Repository navigation
mds: account for where a rank's mds_lock time goes - #71371
Conversation
Config Diff Tool Output+ added: mds_enable_phase_tracker (mds.yaml.in)
The above configuration changes are found in the PR. Please update the relevant release documentation if necessary. |
|
/config check ok |
fa46fd5 to
7d736a5
Compare
|
@dvanders IMO we should introduce a yaml configuration to trigger the test of this, something likes: https://github.com/ceph/ceph/tree/main/qa/cephfs/overrides/prefetch_entire_dirfrags |
I've added it to fs/thrash. Would you rather it go into fs/verify instead? or perhaps always on ? |
|
Thanks for the patch, @dvanders - I will plan to review this in the upcoming days. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
The thrash placement looks right to me, for two reasons: the I'd skip On "always on": I'd rather not. It makes every suite pay the clock-read One gap neither placement covers: the yaml only sets |
Almost everything an MDS rank does is serialized by mds_lock, which makes the lock -- rather than any one thread -- the resource that saturates first. There is currently no way to ask how much of the wall clock a rank spends holding it, so an operator cannot tell a CPU/serialization-bound rank (scale out) from one that is merely waiting on the metadata pool (scale neither). Add opt-in wait/hold accounting to fair_mutex so that a holder of the lock can publish that utilization. Tracking is off by default: when off, lock() does not read the clock at all and the only added cost is a relaxed load of a bool. When on, it costs three clock reads and three relaxed atomic increments per acquisition, all of them inside the critical section the mutex already has, so no contention is added. Signed-off-by: Dan van der Ster <[email protected]> Assisted-by: Claude Opus 5 <[email protected]>
There is no "tick loop" in the MDS whose phases could be timed: work is spread over the messenger dispatch threads, the finisher, the periodic MDSRankDispatcher::tick(), MDCache's cache-trim thread and MDLog's log-trim thread. What they have in common is mds_lock, which makes the lock -- not any one thread -- the resource that saturates first. MDSPhaseTracker charges exclusive wall time to a phase (client requests, cap handling, subtree import/export, cache trim, client recall, log trim, ...) via an RAII Timer. Timers nest, and time spent in a nested timer is subtracted from its parent, so cache_trim is the time actually spent trimming and not the time spent trimming plus everything the trim dispatched into. Totals land in the new "mds_phase" perf counters section (and therefore in mgr/prometheus), where "sum" is the time charged to a phase and "avgcount" the number of times it was entered; over wall time they give the share of a rank spent on each kind of work. The perf counter is the only bookkeeping -- a time average already accumulates both the sum and the entry count, and get_tavg_ns() reads them back for the asok dump -- so the per-message path costs nothing the counter does not already cost. mds_lock's own wait/hold totals are published alongside the phases, so that "utilization" -- the number an operator needs to tell a rank that must be split up from one that is only waiting on the metadata pool -- is directly observable. Tracking is off by default (mds_enable_phase_tracker, runtime adjustable): two clock reads per instrumented scope and three per mds_lock acquisition work out to a few hundred nanoseconds of serialized work per client request, which a rank should not pay for when nobody is reading the counters. Enabling resets them, so a dump describes only the period since. Instrumentation of the individual phases follows. Fixes: https://tracker.ceph.com/issues/79953 Signed-off-by: Dan van der Ster <[email protected]> Assisted-by: Claude Opus 5 <[email protected]>
Instrument the choke points every kind of upkeep already passes through,
so no new plumbing is needed:
MDSRank::handle_message() one timer, phase picked from the message
type, giving a per-message-class breakdown
for free (and covering both the normal and
the deferred-while-laggy dispatch paths)
MDSIOContextBase::complete() journal and object IO completions, which
take mds_lock on the finisher thread and
are otherwise the largest consumer of it
that dispatch never sees
MDSRank::_advance_queues() waiters unblocked by those completions
MDSRankDispatcher::tick() the periodic tick, with the locker and
balancer upkeep it drives broken out
MDCache::upkeep_main() memory sampling, client leases, cache
trim, client recall and heap release
MDLog::log_trim_upkeep() journal segment trimming
With mds_enable_phase_tracker off, which is the default, each of these
sites costs a relaxed load of a bool and nothing else.
mds_lock's wait/hold totals are folded into the perf counters from tick()
rather than on every acquisition, since the mutex accumulates them itself.
Also add a `dump phase times` asok command for the one-shot human view:
the phases sorted by time spent, each with its share of the wall clock,
plus mds_lock utilization. It deliberately does not take mds_lock --
taking it would both perturb the measurement and block on whatever phase
we are trying to observe.
Signed-off-by: Dan van der Ster <[email protected]>
Assisted-by: Claude Opus 5 <[email protected]>
Explain why mds_lock utilization is the number that decides between scaling a rank up, scaling out, and doing neither, what each phase covers, and how to read the `dump phase times` output and the mds_phase perf counters. Includes the decision table the counters were added to make possible, what the accounting costs -- including the TSC clocksource assumption behind that figure -- and hence why it is off by default. Point at it from the multi-MDS guide too, since "is metadata performance bottlenecked on this rank?" is the question that page already asks. Signed-off-by: Dan van der Ster <[email protected]> Assisted-by: Claude Opus 5 <[email protected]>
The phase tracker is off by default, so nothing in the suites exercises it. Add a yes/no facet setting mds_enable_phase_tracker, and use it in fs:thrash, alongside the prefetch facets, so both settings of a knob that changes how mds_lock is acquired see MDS failover and thrashing. Signed-off-by: Dan van der Ster <[email protected]> Assisted-by: Claude Opus 5 <[email protected]>
set_enabled() runs from handle_conf_change() without mds_lock, so the reset it performs races every thread that charges time: a message being dispatched, an IO completion, the tick, a cache or log trim. Two consequences, both wrong: A Timer whose scope straddles a disable/enable cycle accounted unconditionally in its destructor, charging its whole pre-reset span into counters that are documented to cover only the period since tracking was turned on. Give each reset a generation, have every Timer remember the generation it started in, and drop the sample if they differ. The parent's exclusive time is still adjusted, so a surviving parent is not charged for a dropped child. last_lock_stats, and the mds_lock baselines dump() subtracts, were plain members written by reset() and read-modify-written by update_lock_stats() on the tick thread. Besides being a data race, a reset landing between a reader's mds_lock snapshot and its subtraction left a newer baseline being subtracted from an older total, and the wrapped difference -- some 2^64 ns -- being tinc()'d into lock_wait/lock_held or reported by dump(). Take the snapshot and subtract it under a mutex the writer holds too, and zero the phase counters under it as well, so that a dump is consistent with the window it claims to describe. While here, fix the comment in set_enabled(), which described the store order backwards: the mutex accounting is enabled before the phases and disabled after them, so the lock stats cover at least the phases' period rather than the other way around. Signed-off-by: Dan van der Ster <[email protected]> Assisted-by: Claude Opus 5 <[email protected]>
quiesce_message could never accumulate. MSG_MDS_QUIESCE_DB_LISTING and MSG_MDS_QUIESCE_DB_ACK are consumed by quiesce_dispatch() at the top of _dispatch(), which returns true for both, so they never reach handle_message() where the message phases are charged -- including on the _process_laggy_deferred() replay path, since a message only lands in waiting_for_nolaggy after passing that early return. The real work, submit_peer_listing() and submit_peer_ack(), was therefore invisible in every phase, and a dump reporting "quiesce_message: 0.000s" could not be told apart from a rank seeing no quiesce traffic at all. Move the timer into quiesce_dispatch(), which is where the work happens, and drop the two now-pointless cases from phase_for_message(). Signed-off-by: Dan van der Ster <[email protected]> Assisted-by: Claude Opus 5 <[email protected]>
The mds_phase_tracker facet only sets mds_enable_phase_tracker at cluster start, so the runtime toggle -- set_enabled() resetting the counters from a config thread while timers are in flight on every other thread -- runs nowhere in QA, and that is the path with the least margin for error. Add a functional test that flips the setting under a metadata workload and checks what comes back out of `dump phase times` and the mds_phase perf counters: that the totals advance while enabled, that re-enabling opens a fresh window rather than continuing the old one, and that nothing reports an absurd value -- a sample accounted across a reset, or an unsigned delta taken against a newer baseline, shows up as one. Signed-off-by: Dan van der Ster <[email protected]> Assisted-by: Claude Opus 5 <[email protected]>
5117bf2 to
c7a91b4
Compare
|
This PR has been added to main integration testing by vshankar started 2026-09-21-09:47. |
|
This PR has been added to main integration testing by vshankar started 2026-10-13-15:58. |
|
This is an automated message by src/script/redmine-upkeep.py. I have resolved the following tracker ticket due to the merge of this PR: No backports are pending for the ticket. If this is incorrect, please update the tracker |
Nearly everything an MDS rank does is serialized by mds_lock, which makes
the lock -- rather than any one thread -- the resource a busy rank
exhausts first. There is currently no way to ask how much of the wall
clock a rank spends holding it, or on what, so an operator cannot tell a
rank that is serialization-bound on client work (scale out) from one
thrashing its cache (scale up) from one merely waiting on the metadata
pool (neither helps).
This adds MDSPhaseTracker, which charges exclusive wall time to a phase --
client requests, cap handling, IO completions, subtree import/export,
cache trim, client recall, log trim, ... -- via an RAII timer at the choke
points each kind of work already passes through. Timers nest and nested
time is subtracted from the parent, so cache_trim is the time actually
spent trimming rather than trimming plus whatever it dispatched into.
fair_mutex gains opt-in wait/hold accounting so mds_lock utilization is
reported directly alongside the phases.
Totals land in a new "mds_phase" perf counters section, and therefore in
mgr/prometheus.
ceph tell mds.X dump phase timesgives the one-shothuman view: phases sorted by time spent, each with its share of the wall
clock, plus mds_lock utilization.
Off by default (mds_enable_phase_tracker, runtime adjustable). Enabled it
costs two clock reads per instrumented scope and three per mds_lock
acquisition, a few hundred nanoseconds of serialized work per client
request; disabled, a relaxed load of a bool per lock acquisition.
Fixes: https://tracker.ceph.com/issues/79953
Checklist