Skip to content

mds: fix backend dirfrag prefetch throttle leak, refetch loop and a lookup hang - #72036

Open
xiubli wants to merge 4 commits into
ceph:mainfrom
xiubli:wip-prefetch-backend-fixes
Open

xiubli wants to merge 4 commits into
ceph:mainfrom
xiubli:wip-prefetch-backend-fixes

Conversation

@xiubli

@xiubli xiubli commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #69832 (mds_dir_prefetch_backend).

Fixes: https://tracker.ceph.com/issues/80828

Problems

  1. Throttle slot leak on fetch failure. A background full fetch sets
    STATE_BACKEND_FETCH and takes a mds_dir_prefetch_backend_max slot, but
    only the success path in _omap_fetched() released them. A failed fetch
    (missing dirfrag object, corrupt fnode header) went through go_bad(),
    which leaked the slot. With the default max of 1, a single failure
    disabled backend prefetch for the whole rank until restart.

  2. Refetch loop under cache pressure. backend_hit_count stopped counting
    at the threshold and was never reset. Once trimming dropped a dirfrag back
    to incomplete, the next keyed miss relaunched a full background fetch, so
    the threshold no longer had any effect. Under cache pressure this became a
    loop: the fetch fills the cache, trimming evicts some of it, and the next
    miss reads the whole dirfrag again.

  3. Prefetch ignores cache pressure. The background fetch ran even when
    cache_toofull(), where everything it loads is trimmed straight back out.

  4. Lookup hang on a failed keyed fetch. With mds_dir_prefetch=false, a
    keyed fetch parks the request on waiting_on_dentry, but go_bad() only
    finished WAIT_COMPLETE. If the dirfrag object is missing, the lookup
    hangs forever as a slow request. This is independent of the backend
    prefetch and also affects main with mds_dir_prefetch=false alone.

Changes

  • go_bad(): release STATE_BACKEND_FETCH and the throttle slot. Do this,
    and clear STATE_FETCHING, only when the failed fetch was a full one. A
    keyed fetch can fail while a background full fetch is still in flight.
  • mark_complete(): reset backend_hit_count.
  • CDir::fetch(): skip the background fetch while cache_toofull().
  • go_bad(): also wake dentry waiters. The retried request stops at the
    damaged dirfrag in path_traverse() and gets -EIO.
  • New functional test qa/tasks/cephfs/test_dir_prefetch.py, added to
    fs:functional. A second client holds a file open in each directory under
    test, so the dirfrag stays cached while cache drop trims its other
    dentries.
    • test_hit_count_reset_after_trim
    • test_no_prefetch_when_cache_too_full
    • test_fetch_failure

Testing

Run with vstart_runner.py against a local vstart cluster:

without the MDS fixes with the MDS fixes
test_fetch_failure FAIL: lookup in the damaged dirfrag hung ok
test_hit_count_reset_after_trim FAIL: background fetch launched before 4 hits ok
test_no_prefetch_when_cache_too_full FAIL: background fetch launched while the cache is too full ok

Only mds_dir_prefetch=false with mds_dir_prefetch_backend=true is
affected, apart from (4). The default (mds_dir_prefetch=true) is unaffected.

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.

@xiubli
xiubli requested a review from a team September 24, 2026 07:01
@github-actions github-actions Bot added cephfs Ceph File System tests labels Sep 24, 2026
@vshankar vshankar self-assigned this Sep 27, 2026
@vshankar
vshankar self-requested a review September 27, 2026 16:42
@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

The backend dirfrag prefetch (mds_dir_prefetch_backend) sets
STATE_BACKEND_FETCH and increments mdcache->num_backend_fetching when
launching a background full fetch. The state and counter are only
cleared on the success path in _omap_fetched(). If the fetch fails
(missing dirfrag object, corrupt fnode header, trailing garbage),
_omap_fetched() calls go_bad(), which clears only STATE_FETCHING and
never clears STATE_BACKEND_FETCH nor decrements num_backend_fetching.

The leaked counter saturates the mds_dir_prefetch_backend_max throttle
over time, silently disabling all future backend prefetches, and the
CDir's STATE_BACKEND_FETCH bit stays stuck set.

Mirror the success-path cleanup in go_bad(), and do it only when the
failed fetch was a full one. With the backend prefetch a keyed fetch
can run while a background full fetch is still in flight; if the keyed
fetch fails, clearing STATE_FETCHING and the throttle slot then would
let a second full fetch start on the same dirfrag and release the slot
before the first one finishes.

Fixes: https://tracker.ceph.com/issues/80828
Signed-off-by: Xiubo Li <[email protected]>
The lazy backend prefetch counts keyed-fetch hits on a dirfrag in
backend_hit_count and launches a background full fetch once the count
reaches mds_dir_prefetch_backend_hit_threshold. The counter saturates at
the threshold and is never reset.

Once a dirfrag has been fetched complete, trimming any one of its
dentries clears STATE_COMPLETE again. With the counter still at the
threshold, the very next keyed miss relaunches a full background fetch
of the whole dirfrag. Under cache pressure this turns into a loop: the
fetch fills the cache, trimming drops the dirfrag back to incomplete,
and the next miss reads the whole dirfrag again.

Reset the counter in mark_complete(), so a dirfrag that has lost its
complete state has to earn a background fetch again.

Fixes: https://tracker.ceph.com/issues/80828
Signed-off-by: Xiubo Li <[email protected]>
The background full fetch launched by mds_dir_prefetch_backend loads
every dentry and inode of the dirfrag into the cache. When the cache is
already over its reservation (cache_toofull()), the loaded entries are
trimmed straight back out, so the prefetch only costs a full omap read
and adds to the pressure on the cache.

Skip the background fetch while the cache is too full. The requesting
operation is still served by the keyed fetch, which is issued first.

Fixes: https://tracker.ceph.com/issues/80828
Signed-off-by: Xiubo Li <[email protected]>
Nothing in the suite runs with mds_dir_prefetch_backend enabled beyond
the fs:thrash override, and nothing checks when a background fetch is
launched or what happens when a fetch fails. Add a functional test:

* test_hit_count_reset_after_trim: a dirfrag trimmed back to incomplete
  takes mds_dir_prefetch_backend_hit_threshold new keyed-fetch hits
  before another background fetch, rather than refetching on the next
  miss.

* test_no_prefetch_when_cache_too_full: no background fetch is launched
  while the cache is over its reservation, and one is once it has room.

* test_fetch_failure: with the dirfrag object removed, a lookup gets
  EIO instead of hanging, and the background fetch slot is released so
  that another dirfrag can still be prefetched with
  mds_dir_prefetch_backend_max=1.

A second client holds a file open in each directory under test, which
keeps the dirfrag in the cache while "cache drop" trims its other
dentries, so the tests can observe a dirfrag going from complete to
incomplete and back.

Fixes: https://tracker.ceph.com/issues/80828
Signed-off-by: Xiubo Li <[email protected]>
@xiubli
xiubli force-pushed the wip-prefetch-backend-fixes branch from 6fbdb1a to 90becbb Compare October 21, 2026 00:59
@anthonyeleven

Copy link
Copy Markdown
Contributor

@xiubli @vshankar If these are backported, #69832, #72036 and #72524 need to land in the same point release on each branch. #69832 alone would ship the problems tracked in https://tracker.ceph.com/issues/80828 to anyone running mds_dir_prefetch=false with mds_dir_prefetch_backend=true, and #72524 is the qa change that covers the backend mode. Backports are requested on trackers 77810, 80828 and 81584.

@anthonyeleven

Copy link
Copy Markdown
Contributor

@vshankar gentle ping for a review when you have a chance. The tentacle and umbrella backports of #69832 (https://tracker.ceph.com/issues/82048, https://tracker.ceph.com/issues/82049) are waiting on this one, since the three PRs need to land together. We are hoping the set can make 20.2.6. Thanks!

@vshankar

Copy link
Copy Markdown
Contributor

@vshankar gentle ping for a review when you have a chance. The tentacle and umbrella backports of #69832 (https://tracker.ceph.com/issues/82048, https://tracker.ceph.com/issues/82049) are waiting on this one, since the three PRs need to land together. We are hoping the set can make 20.2.6. Thanks!

Ummm.. I see you requested back porting of the original enhancement. Normally, we let an enhancement bake it main branch and have it as part of the next release. Apart from having features and enhancements generally not being a backport candidate, it is also a risk mitigation strategy for sizeable changes (enhancements and features) that get merged late in a releases development cycle.

So, my question is: do we really need to backport the original enhancement? @anthonyeleven @xiubli ?

@xiubli

xiubli commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

@vshankar gentle ping for a review when you have a chance. The tentacle and umbrella backports of #69832 (https://tracker.ceph.com/issues/82048, https://tracker.ceph.com/issues/82049) are waiting on this one, since the three PRs need to land together. We are hoping the set can make 20.2.6. Thanks!

Ummm.. I see you requested back porting of the original enhancement. Normally, we let an enhancement bake it main branch and have it as part of the next release. Apart from having features and enhancements generally not being a backport candidate, it is also a risk mitigation strategy for sizeable changes (enhancements and features) that get merged late in a releases development cycle.

So, my question is: do we really need to backport the original enhancement? @anthonyeleven @xiubli ?

Since this is a new feature and from my understanding we'd better not backport it, which is a bit risky ?

@vshankar

vshankar commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

@vshankar gentle ping for a review when you have a chance. The tentacle and umbrella backports of #69832 (https://tracker.ceph.com/issues/82048, https://tracker.ceph.com/issues/82049) are waiting on this one, since the three PRs need to land together. We are hoping the set can make 20.2.6. Thanks!

Ummm.. I see you requested back porting of the original enhancement. Normally, we let an enhancement bake it main branch and have it as part of the next release. Apart from having features and enhancements generally not being a backport candidate, it is also a risk mitigation strategy for sizeable changes (enhancements and features) that get merged late in a releases development cycle.
So, my question is: do we really need to backport the original enhancement? @anthonyeleven @xiubli ?

Since this is a new feature and from my understanding we'd better not backport it, which is a bit risky ?

Unless the enhancement fixes a nagging issue that is bothering our users, it is generally expected to be part of next release. @anthonyeleven - unless the backport is required to fix a perf related thing that you have come across with our users or at $company, I would generally not want to port it. I am happy to help out with any perf issue that prompted the port requirement.

@anthonyeleven

Copy link
Copy Markdown
Contributor

@vshankar @xiubli You're right, we don't need it. We asked for the #69832 backport after surveying MDS changes that might help cold-cache failovers, not because of a problem we measured, so I've withdrawn the umbrella and tentacle requests on 77810, 80828 and 81584.

One part of this PR does affect released branches: the lookup hang in item 4. On reef, tentacle and umbrella, CDir::go_bad() only finishes WAIT_COMPLETE, so with mds_dir_prefetch=false alone, a failed keyed fetch leaves the lookup hanging. We run two large filesystems that way. Would you be open to that fix going in as its own commit with its own tracker, so it can be backported without the enhancement?

@vshankar

Copy link
Copy Markdown
Contributor

One part of this PR does affect released branches: the lookup hang in item 4. On reef, tentacle and umbrella, CDir::go_bad() only finishes WAIT_COMPLETE, so with mds_dir_prefetch=false alone, a failed keyed fetch leaves the lookup hanging. We run two large filesystems that way. Would you be open to that fix going in as its own commit with its own tracker, so it can be backported without the enhancement?

Am I correct in understanding that this is a bug that is present in release branches? If yes, then we should fix it separately. Have a tracker?

@anthonyeleven

Copy link
Copy Markdown
Contributor

@vshankar Yes, it's in the release branches, and it already has a tracker: https://tracker.ceph.com/issues/79454. CDir::go_bad() finishes only WAIT_COMPLETE, so the contexts fetch_keys() parks in waiting_on_dentry are never completed when the dirfrag object is missing. A takeover MDS hits that during rejoin, which is the case in 79454. A client lookup hits it with mds_dir_prefetch=false, which is item 4 here. Both come from the same missing wakeup.

Xiubo's #71022 fixed it on main on Oct 19 by finishing WAIT_COMPLETE | WAIT_DENTRY with -EIO, which is why this PR's go_bad() hunk no longer touches the waiters. umbrella, tentacle, squid and reef still finish WAIT_COMPLETE only. The tentacle and umbrella backports are #73027 and #73028, which you approved on Oct 27. The squid backport (https://tracker.ceph.com/issues/81886) has no PR yet.

So item 4 doesn't need a separate fix or tracker. It reaches the release branches with the #71022 backports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cephfs Ceph File System tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants