Skip to content

mds: add mds_dir_prefetch_backend — non-blocking dirfrag prefetch with configurable lazy trigger - #69832

Merged
vshankar merged 3 commits into
ceph:mainfrom
xiubli:prefetch_backend
Aug 31, 2026
Merged

vshankar merged 3 commits into
ceph:mainfrom
xiubli:prefetch_backend

Conversation

@xiubli

@xiubli xiubli commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

This PR introduces a fast, non-blocking dirfrag fetch path that serves individual dentry lookups via targeted omap_get_vals_by_keys OSD reads (~4ms) while lazily warming the cache with a background full dirfrag prefetch.

Problem: The default mds_dir_prefetch=true performs a blocking full-omap read on every cache miss, loading all dentries in a dirfrag before returning to the client. For large directories (10k+ files) with random access patterns, this causes ~95ms latency per lookup.

Design:

prefetch=true (existing): blocking full _omap_fetch ~95 ms/stat
prefetch=false (existing): keyed fetch_keys() only ~3.7 ms (no cache warmth)
backend=true (new): keyed fetch + lazy bg full fetch ~3.7–8 ms (adaptive)

When mds_dir_prefetch=false and mds_dir_prefetch_backend=true:

  1. fetch_keys() sends a targeted omap_get_vals_by_keys — the request completes when that single dentry arrives.
  2. backend_hit_count is incremented. If it reaches the configurable threshold, a background _omap_fetch (with its own STATE_FETCHING + STATE_BACKEND_FETCH) loads the full dirfrag concurrently — keyed fetches are never blocked.
  3. Once the background fetch completes, the dirfrag is marked STATE_COMPLETE and subsequent lookups hit the cache.

Benchmark results (5000 iters, 10³ dirs × 10k files, 3 OSDs, max=1), latency(ms):

┌─────────────────┬───────────────┬────────────────┬───────┬───────┬───────┬───────┬───────┬───────┬────────┐
│    Scenario     │ prefetch_true │ prefetch_false │ thr=2 │ thr=3 │ thr=4 │ thr=5 │ thr=6 │ thr=8 │ thr=16 │
├─────────────────┼───────────────┼────────────────┼───────┼───────┼───────┼───────┼───────┼───────┼────────┤
│ random_norepeat │      112      │      3.7       │  3.7  │  3.6  │  4.5  │  3.8  │  3.9  │  4.5  │  4.5   │
├─────────────────┼───────────────┼────────────────┼───────┼───────┼───────┼───────┼───────┼───────┼────────┤
│ seq_scan_full   │      2.4      │      3.1       │  2.3  │  2.4  │  2.3  │  2.4  │  2.4  │  2.4  │  2.4   │
├─────────────────┼───────────────┼────────────────┼───────┼───────┼───────┼───────┼───────┼───────┼────────┤
│ seq_scan_multi  │      2.4      │      3.1       │  2.5  │  2.5  │  2.5  │  2.4  │  2.5  │  2.4  │  2.5   │
├─────────────────┼───────────────┼────────────────┼───────┼───────┼───────┼───────┼───────┼───────┼────────┤
│ hot_dir_mixed   │     10.5      │      3.3       │  3.3  │  2.8  │  2.6  │  2.8  │  3.0  │  2.8  │  2.8   │
├─────────────────┼───────────────┼────────────────┼───────┼───────┼───────┼───────┼───────┼───────┼────────┤
│ random_stat     │     94.1      │      3.7       │  8.0  │  7.0  │  6.1  │  5.6  │  5.4  │  4.3  │  3.6   │
└─────────────────┴───────────────┴────────────────┴───────┴───────┴───────┴───────┴───────┴───────┴────────┘

Key observations:

  • random_norepeat (0 bg fetches): backend_true ≡ prefetch_false across all thresholds — zero overhead.
  • random_stat: Higher threshold → fewer bg fetches → asymptotically approaches prefetch_false. At thr=16, 0 dirs reach the threshold (5000 hits ÷ 1000 dirs ≈ 5 avg, Poisson tail falls below 16) — performance converges to pure keyed fetch.
  • seq_scan_*: Threshold irrelevant — the second file in the same dir always triggers the bg fetch.
  • hot_dir_mixed: 5 hot dirs always reach any threshold (~900 hits each), cold dirs never do (~1 hit each). Result stable at ~2.8ms.

New config options:

  • mds_dir_prefetch_backend (bool, default: false)
  • mds_dir_prefetch_backend_max (uint, default: 4)
  • mds_dir_prefetch_backend_hit_threshold (uint, default: 2) — 1=immediate, 2=lazy, 8–16=very deferred

Recommended defaults: max=1, hit_threshold=2. For highly random workloads with few repeat hits, increase threshold to 8–16 to eliminate bg fetch overhead entirely.

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

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 June 30, 2026 10:32
@xiubli
xiubli requested a review from a team as a code owner June 30, 2026 10:32
@github-actions

github-actions Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Config Diff Tool Output

+ added: mds_dir_prefetch_backend_max (mds.yaml.in)
+ added: mds_dir_prefetch_backend_hit_threshold (mds.yaml.in)
+ added: mds_dir_prefetch_backend (mds.yaml.in)

The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
Ignore this comment if docs are already updated. To make the "Check ceph config changes" CI check pass, please comment /config check ok and re-run the test.

@xiubli xiubli changed the title Prefetch backend mds: add mds_dir_prefetch_backend — non-blocking dirfrag prefetch with configurable lazy trigger Jun 30, 2026
@xiubli

xiubli commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

/config check ok

@anthonyeleven

Copy link
Copy Markdown
Contributor

Thanks for contributing. You'll need to tick a box in each of the 4 sections of the checklist in the PR description for the second test to pass.

Comment thread src/common/options/mds.yaml.in Resolved
Comment thread src/common/options/mds.yaml.in Resolved
Comment thread src/common/options/mds.yaml.in Resolved
@xiubli
xiubli force-pushed the prefetch_backend branch from 1dd0aa8 to 1092290 Compare July 1, 2026 02:39
@xiubli

xiubli commented Jul 1, 2026

Copy link
Copy Markdown
Member Author

Thanks for contributing. You'll need to tick a box in each of the 4 sections of the checklist in the PR description for the second test to pass.

@anthonyeleven Sure, got it. Thanks very much for your valuable info. I didn't notice this :-)

@vshankar

Copy link
Copy Markdown
Contributor

Design:

prefetch=true (existing): blocking full _omap_fetch ~95 ms/stat prefetch=false (existing): keyed fetch_keys() only ~3.7 ms (no cache warmth) backend=true (new): keyed fetch + lazy bg full fetch ~3.7–8 ms (adaptive)

When mds_dir_prefetch=false and mds_dir_prefetch_backend=true:

  1. fetch_keys() sends a targeted omap_get_vals_by_keys — the request completes when that single dentry arrives.
  2. backend_hit_count is incremented. If it reaches the configurable threshold, a background _omap_fetch (with its own STATE_FETCHING + STATE_BACKEND_FETCH) loads the full dirfrag concurrently — keyed fetches are never blocked.
  3. Once the background fetch completes, the dirfrag is marked STATE_COMPLETE and subsequent lookups hit the cache.

The performance gains look nice to me 👍

@vshankar vshankar self-assigned this Jul 14, 2026
@xiubli

xiubli commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

jenkins test make check arm64

Comment thread src/mds/CDir.cc Resolved
Comment thread src/mds/CDir.cc Resolved
Comment thread src/common/options/mds.yaml.in Resolved
@xiubli
xiubli force-pushed the prefetch_backend branch 2 times, most recently from 4e7082a to 2a33e86 Compare July 18, 2026 01:49
@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

@xiubli
xiubli force-pushed the prefetch_backend branch from 2a33e86 to e257e39 Compare July 21, 2026 06:45
@xiubli
xiubli force-pushed the prefetch_backend branch from e257e39 to 92024d3 Compare July 23, 2026 06:26
@xiubli
xiubli requested a review from a team as a code owner July 23, 2026 06:26
@xiubli
xiubli force-pushed the prefetch_backend branch from 92024d3 to 35964aa Compare July 23, 2026 06:47
Comment thread src/mds/CDir.cc Resolved

@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.

Left a minor nit. Otherwise LGTM.

@vshankar

vshankar commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by vshankar started 2026-08-05-16:27.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath7-testing-20260824.015917-main.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been removed from wip-bharath7-testing-20260824.015917-main.

@dparmar18 dparmar18 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 was a nice read @xiubli. Thanks for the patch. Just one nit -- maybe coalesce the commits into given they touch the same CDir::fetch? i think it would also make the patch more readable that way. Apart from this. LGTM.

@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

xiubli and others added 3 commits August 26, 2026 14:14
mds_dir_prefetch_backend bridges the performance gap between
mds_dir_prefetch=true (blocking full-omap fetch, ~95 ms for random)
and mds_dir_prefetch=false (keyed-only fetch, ~3.7 ms no cache warmth).

When mds_dir_prefetch=false and mds_dir_prefetch_backend=true, every
dentry lookup completes via a fast targeted keyed OSD fetch while
a background full dirfrag prefetch warms the cache for subsequent
accesses.  mds_dir_prefetch_backend_max (default 1) limits concurrent
background fetches to avoid OSD I/O contention.

Fixes: https://tracker.ceph.com/issues/77810
Signed-off-by: Xiubo Li <[email protected]>
Defer background dirfrag prefetch until a directory has been hit
mds_dir_prefetch_backend_hit_threshold (default 16) times.  A per-dir
uint8_t hit counter tracks keyed-fetch accesses; only when the
counter reaches the threshold is the background full _omap_fetch
launched.  This avoids wasted full-omap reads for directories that
are accessed only a few times in random workloads, while still
warming the cache for genuinely hot directories.

Threshold 16 effectively eliminates bg fetches on scattered-access
patterns (behaving like prefetch_false), while lower thresholds
provide more aggressive cache warming for mixed workloads.

Also fix a race: clear STATE_FETCHING and STATE_BACKEND_FETCH only on
the background fetch completion (complete=true), not on keyed fetch
completions that happen to run concurrently.

Fixes: https://tracker.ceph.com/issues/77810
Signed-off-by: Xiubo Li <[email protected]>
@vshankar

Copy link
Copy Markdown
Contributor

@xiubli - the introduced config (prefetch_dirfrag_backend yamls) were not getting picked up in tests. It has to be (sym)linked from the suite directory. I have added a commit to use it in fs:thrash. Tests running here: https://pulpito.ceph.com/vshankar-2026-08-26_08:29:09-fs:thrash-wip-vshankar-testing-20260824.070857-distro-default-trial/

@xiubli

xiubli commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

@xiubli - the introduced config (prefetch_dirfrag_backend yamls) were not getting picked up in tests. It has to be (sym)linked from the suite directory. I have added a commit to use it in fs:thrash. Tests running here: https://pulpito.ceph.com/vshankar-2026-08-26_08:29:09-fs:thrash-wip-vshankar-testing-20260824.070857-distro-default-trial/

LGTM, thanks @vshankar

@vshankar

Copy link
Copy Markdown
Contributor

jenkins test windows

@vshankar

Copy link
Copy Markdown
Contributor

This is good to merge once run wiki is prepared (slight delay due to another PR in the batch having failing tests).

@xiubli

xiubli commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

It was a nice read @xiubli. Thanks for the patch. Just one nit -- maybe coalesce the commits into given they touch the same CDir::fetch? i think it would also make the patch more readable that way. Apart from this. LGTM.

@dparmar18 Thanks for your feedback. I will leave this to @vshankar since this has already under the tests. Thanks.

@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.

@vshankar
vshankar merged commit ea5b6d6 into ceph:main Aug 31, 2026
7 checks passed
@github-actions

Copy link
Copy Markdown

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
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/33361829563

@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.

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.

6 participants