Skip to content

mds/osdc: avoid Objecter balanced-budget deadlocks under metadata load - #71959

Open
edwinzrodriguez wants to merge 5 commits into
ceph:mainfrom
edwinzrodriguez:ceph-umbrella-journaler-fix
Open

edwinzrodriguez wants to merge 5 commits into
ceph:mainfrom
edwinzrodriguez:ceph-umbrella-journaler-fix

Conversation

@edwinzrodriguez

@edwinzrodriguez edwinzrodriguez commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • After Objecter::set_balanced_budget() (tracker mds: enable osdc op throttles #66578), _throttle_op can block the caller until OSD replies free budget. Those replies are delivered on ms_dispatch, which must take mds_lock first. Holding mds_lock (or another mutex that ms_dispatch/trim depends on) across a throttled Objecter submit wedges the MDS under SpecStorage2020-class metadata load.
  • Drop Journaler::lock around Objecter submits that can throttle; make get_layout_period() lock-free after set_layout.
  • Drop mds_lock around Objecter submits on the log-trim table/sessionmap/OFT path and on dir/inode fetch/store/backtrace; defer overlapping table/sessionmap saves.
  • Keep balanced-budget throttling, but move hot Objecter submits off ms_dispatch / mds-rank-fin onto a dedicated objecter_finisher (mds-obj-fin) via queue_objecter(). Also defer MDLog::flush/write_head so they never block under mds_lock.
  • Fix PurgeQueue: its SafeTimer shares PurgeQueue::lock with safe_callbacks=true, so delayed journaler.flush() held that lock across the Objecter throttle while cache trim held mds_lock in push() — permanent deadlock. Use safe_callbacks=false and drop the lock around Journaler append/flush/write_head.

Commits

  1. osdc/Journaler: do not hold lock across Objecter throttle (Fixes: https://tracker.ceph.com/issues/80667)
  2. mds: do not hold mds_lock across Objecter throttle on trim path
  3. mds: do not hold mds_lock across Objecter throttle on dir/inode I/O
  4. mds: submit Objecter ops on dedicated finisher under balanced budget
  5. mds: do not hold PurgeQueue lock across Objecter throttle

Test plan

  • unittest_journaler_lock — get_layout_period() does not take Journaler::lock
  • unittest_mds_table_save_unlock — unlock window + defer overlapping MDSTable::save
  • Build/run bin/ceph-mds with the series applied
  • SpecStorage2020 SWBUILD (or equivalent metadata hammer) against a single active MDS with mds_cache_memory_limit stressed; confirm no ms_dispatch / asok / beacon wedge from Objecter throttle × lock cycles
  • On stall, capture gdb backtraces: no thread should hold mds_lock or PurgeQueue::lock while blocked in Objecter::_throttle_op / Throttle::_wait
  • Smoke: create/unlink/lookup load still progresses; purge queue and log trim continue under load

Signed-off-by: Edwin Rodriguez [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@edwinzrodriguez
edwinzrodriguez requested review from a team, batrick and vshankar September 21, 2026 19:15
edwinzrodriguez and others added 4 commits September 21, 2026 15:15
Under metadata load the MDS submit thread can block in
Objecter::_throttle_op while holding Journaler::lock (filer.zero /
filer.write / write_head from append/flush/prezero). Objecter correctly
drops its own lock before waiting on the throttle, but Journaler did
not. The SafeTimer thread then runs scatter_tick under mds_lock,
calls MDLog::submit_entry -> get_layout_period (or flush), and blocks
forever on Journaler::lock. Every client path that needs mds_lock
stalls; the rank goes laggy and admin socket stops responding.

Fix this the same way write_buf_throttle already does: drop
Journaler::lock around Objecter submits that can throttle, after
updating journal pointers under the lock. Also cache layout.period()
in an atomic so get_layout_period() is lock-free after set_layout —
that is the exact wait site seen in the stall backtrace.

Add unittest_journaler_lock to regress the get_layout_period path:
one thread holds Journaler::lock while another calls get_layout_period;
the call must complete (Journaler::lock is non-recursive, so taking it
again would hang).

Fixes: https://tracker.ceph.com/issues/80667
Co-authored-by: Cursor <[email protected]>
Signed-off-by: Edwin Rodriguez <[email protected]>
After the Journaler unlock-across-throttle fix, the MDS can still go
laggy under metadata load: MDLog::log_trim_upkeep holds mds_lock through
trim -> try_to_expire -> MDSTable::save / SessionMap::save (and open-file
table commit). Those paths call Objecter::write_full/mutate, which may
block in _throttle_op. While throttled with mds_lock held, dispatch, asok,
and beacon heartbeat cannot run; the rank reports slow requests and
"MDS internal heartbeat is not healthy".

Drop mds_lock around the Objecter submits in MDSTable::save,
SessionMap::save / save_if_dirty, and OpenFileTable::commit. Defer a new
table/sessionmap write while one is already in flight, and kick a
follow-up save when the in-flight write completes if the version advanced
while the lock was dropped.

Add unittest_mds_table_save_unlock to regress the unlock window (another
thread must be able to take mds_lock while save is in submit) and the
defer-overlapping-save behavior.

Fixes: https://tracker.ceph.com/issues/80667
Signed-off-by: Edwin Rodriguez <[email protected]>
After unlocking the Journaler and log-trim table/sessionmap paths across
Objecter::_throttle_op, the active MDS can still go laggy under metadata
load. Client request dispatch holds mds_lock through Server ->
MDCache::path_traverse -> CDir::fetch -> CDir::_omap_fetch, which calls
Objecter::read. When the Objecter op budget is exhausted, _throttle_op
blocks while mds_lock is still held, so heartbeat cannot be reset,
beacons are skipped, and the rank is failed over. The same pattern
appears on successor actives (openc/getattr dir fetch) and on locked
CInode store/fetch/backtrace submits.

GDB on stalled nodes showed ms_dispatch waiting in
Throttle::_wait under CDir::_omap_fetch, with mds-log-trim and other
threads blocked on fair_mutex for mds_lock.

Drop mds_lock around the Objecter submit in CDir::_omap_fetch and
_omap_fetch_more (dirfrag remains auth-pinned for the unlock window),
and likewise in CInode::store, CInode::fetch, and CInode::_commit_ops
when the caller holds mds_lock. _commit_ops still runs unlocked on the
finisher BatchCommitBacktrace path.

Fixes: https://tracker.ceph.com/issues/80667
Signed-off-by: Edwin Rodriguez <[email protected]>
After set_balanced_budget() (tracker ceph#71136), Objecter::_throttle_op can
block the calling thread until inflight OSD ops complete and free budget.
OSD replies that release that budget are handled on ms_dispatch. When
ms_dispatch (or the MDS completion finisher) itself blocks in the
throttle — e.g. CDir::_omap_fetch during path_traverse, or
_omap_commit_ops on mds-rank-fin — replies never run, the throttle never
puts, and the MDS wedges (client creates stuck at journal_and_reply).

Dropping mds_lock across Objecter submit is not enough: the dispatch
thread must not wait on the same throttle that only it can advance.

Keep balanced-budget throttling, but move Objecter submits that may block
onto a dedicated objecter_finisher (mds-obj-fin) via queue_objecter().
ms_dispatch and the completion finisher stay free to process replies.
Route dir/inode fetch and commit, backtrace batch commits, OpenFileTable,
SessionMap, and MDSTable Objecter I/O through that path.

Fixes: https://tracker.ceph.com/issues/80667
Signed-off-by: Edwin Rodriguez <[email protected]>
@edwinzrodriguez
edwinzrodriguez force-pushed the ceph-umbrella-journaler-fix branch from ff2af3b to b5bc8dd Compare September 21, 2026 19:17
@vshankar

Copy link
Copy Markdown
Contributor

Summary

  • After Objecter::set_balanced_budget() (tracker mds: enable osdc op throttles #66578), _throttle_op can block the caller until OSD replies free budget. Those replies are delivered on ms_dispatch, which must take mds_lock first. Holding mds_lock (or another mutex that ms_dispatch/trim depends on) across a throttled Objecter submit wedges the MDS under SpecStorage2020-class metadata load.

#66578 isn't backported to any point release branches.

@vshankar

Copy link
Copy Markdown
Contributor

jenkins test make check

@xiubli

xiubli commented Sep 24, 2026

Copy link
Copy Markdown
Member

@edwinzrodriguez

The root cause is not fully addressed; I reproduced a permanent hang with this PR applied. OSD op replies are fast-dispatched and do not need mds_lock, but OSD maps go through the normal ms_dispatch queue. Setup: vstart, objecter_inflight_ops=4, 16-thread libcephfs metadata load, raising pg_num of the fs pools every 6s. Result:

  • mds-rank-fin holds mds_lock in Throttle::get <- Filer::purge_range <- MDCache::purge_inodes <- Server::_session_logged. This path is not touched by the PR; mds-obj-fin was idle.
  • ms_dispatch is blocked on mds_lock in MDSDaemon::ms_dispatch2.
  • The throttle is full (4/4) and no ops are in flight on any OSD. All 4 MDS ops were dropped by the OSDs: changed after 50, dropping osd_op(mds.0.7:30138 ...).
  • The MDS Objecter is still at e50 while the cluster is at e82. Walking DispatchQueue::mqueue in gdb shows the MOSDMaps for e51/e52 sitting in the queue.
  • The MDS was still wedged 6 minutes later (Objecter e50, cluster e138).

So the resend never happens because the new osdmap is stuck behind mds_lock, and any mds_lock holder that blocks in the throttle can close this cycle. Should osdmap delivery to the Objecter be made independent of mds_lock, or should set_balanced_budget() be reconsidered for the MDS, rather than moving call sites one by one?

After set_balanced_budget(), Objecter::_throttle_op can block until OSD
replies free budget. Those replies are delivered on ms_dispatch, which
must take mds_lock first.

PurgeQueue's SafeTimer shares PurgeQueue::lock with safe_callbacks=true,
so the delayed journaler.flush() callback held that lock while blocked
in the Objecter throttle. MDCache trim holds mds_lock across
PurgeQueue::push(), so it stalled acquiring PurgeQueue::lock; ms_dispatch
then stalled on mds_lock and replies never ran — permanent deadlock.
The same pattern existed for append_entry in push() and write_head under
the lock.

Construct the PurgeQueue timer with safe_callbacks=false, drop
PurgeQueue::lock around Journaler append/flush/write_head, and only clear
delayed_flush when the firing context is still current.

Fixes: https://tracker.ceph.com/issues/80667
Signed-off-by: Edwin Rodriguez <[email protected]>
@edwinzrodriguez
edwinzrodriguez force-pushed the ceph-umbrella-journaler-fix branch from b5bc8dd to 37c177c Compare September 24, 2026 16:42
@edwinzrodriguez

Copy link
Copy Markdown
Contributor Author

I've been wondering myself if set_balanced_budget() is worth the cost. I'm not even sure it will help, more likely hurt without a protocol change to add some kind of flow control to mds traffic from the client. What will probably happen is we'll get a massive backlog in the mds that will stall it until it eventually starts dropping heartbeats and fails over. Where the process begins again.

@edwinzrodriguez

Copy link
Copy Markdown
Contributor Author

set_balanced_budget() was added for #71136 to bound unbounded Objecter queueing / MDS OOMs.Need to decide if we want keep some bound, but a blocking wait on the MDS dispatch/finisher threads is the wrong solution given how maps and replies interact. Other options:

  • Non-blocking / deferred budget acquire on the Objecter (queue the op until put frees budget, never sleep the caller) - keeps a bound without creating lock cycles; similar to a a problem related to osdc blocking strands.
  • Don’t enable blocking balanced-budget on the MDS
  • Can make Objecter OSD map updates independent of mds_lock - agree that is a good idea regardless

@vshankar

Copy link
Copy Markdown
Contributor

jenkins make check arm64

@vshankar vshankar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that there are still cases where things can lockup and/or misbehave due to the lock being dropped before calling into objecter/filer.

nit: use Assisted-by: <LLM> in place of Co-authored-by: in the commit message. That's the norm ceph is being follwowing.

Comment thread src/osdc/Journaler.cc
uint32_t iohint = write_iohint;

// Objecter may block in _throttle_op; do not hold Journaler::lock across that.
l.unlock();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably already handled correctly, but, _write_head() drops Journaler::lock before write_full(). A second header write can start while the first is blocked in Objecter::_throttle_op (via flush()). _finish_write_head() aborts if the older header completes after last_committed has moved forward. Has this overlap been checked?

Comment thread src/osdc/Journaler.cc
ceph_assert(write_pos > requested_pos);
if (pending_safe.empty()) {
_flush(NULL);
_flush(l, NULL);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be an issue here: _issue_read() queues C_RetryRead only after _flush() returns. _flush() submits filer.write() and then drops Journaler::lock again before that queue. If _finish_flush() runs in any of those unlocked sections, it advances safe_pos while waitfor_safe does not yet contain C_RetryRead. The waiter is then inserted at next_safe_pos, which is already safe, and nothing completes it unless a later flush moves safe_pos. Has this been checked?

Comment thread src/osdc/Journaler.cc
l.lock();
}

void Journaler::_finish_write_head(int r, Header &wrote,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also calls _trim() which would call filer.purge_range(...) with lock held.

@vshankar

Copy link
Copy Markdown
Contributor

I've been wondering myself if set_balanced_budget() is worth the cost.

I kind of agree. Fixes like these should bake in the branch before making it to a release. Maybe revert #66578 for now?

I'm not even sure it will help, more likely hurt without a protocol change to add some kind of flow control to mds traffic from the client. What will probably happen is we'll get a massive backlog in the mds that will stall it until it eventually starts dropping heartbeats and fails over. Where the process begins again.

Just FYI - Such a feature is desirable and also prevents us from bloating the MDS journal when log trimming is slow/stuck. See discussion: #71802 (comment)

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions Bot added the stale label Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants