Skip to content

mds: flush the journal when a rename waits for an unjournaled update - #73171

Open
dvanders wants to merge 3 commits into
ceph:mainfrom
dvanders:wip-mds-rename-flush-log
Open

dvanders wants to merge 3 commits into
ceph:mainfrom
dvanders:wip-mds-rename-flush-log

Conversation

@dvanders

@dvanders dvanders commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Renaming a file that a client has just written, into a directory on another active rank, waits a full mds_tick_interval (5 s). Workloads that write output and move it into a tree pinned to another rank pay this on every file.

Each of the waits is for an update that has been submitted to the journal but not flushed. Nothing asks for a flush, so it waits for the tick. A rename can hit more than one of them, one tick each:

  • handle_peer_rename_prep() freezes the renamed inode on the rank that owns it. The client's flush of its dirty caps on the file holds an auth pin on the inode in _do_cap_update() until it is journaled, and the freeze waits for that. Now the log is flushed when the freeze has to wait, and _do_cap_update() asks for a flush when the inode is being frozen, in case the cap flush arrives after the freeze started.
  • The destination rank also discovers the just-created source dentry, and handle_discover() blocks on its xlock, which the create holds until it is journaled. The log is nudged there too.
  • A rename whose leader replies early leaves its log unflushed, while a witness keeps the rename's locks until the leader commits. A request on the witness's rank that needs one of those locks, such as the client's lookup of the new name, waits for that commit, and nudge_log() there only flushes the witness's own log. The leader now flushes after an early reply when the request has witnesses. (Found by @xiubli.)

Two active ranks, /src on rank 0 and /dst pinned to rank 1; write 4 KiB or 1 MiB, close, rename into /dst, on a vstart cluster:

before after same-rank rename
main, ceph-fuse 4.9-5.0 s 16-110 ms 19 ms
main, ceph-fuse, mds_tick_interval 10 10 s 80-100 ms
Reef 18.2.8, kernel client 2.8-5.0 s (p90 up to 8.3 s) 140-155 ms 3 ms
Reef 18.2.8, ceph-fuse 3.5-4.6 s 170-210 ms 37 ms

@xiubli's runs on kernel 7.2 and ceph-fuse saw two tick waits per rename, about 10 s, and 130-190 ms median with these changes (see his review).

For the early-reply flush: clients rename their oldest file into another client's directory, with the client directories pinned alternately to the two ranks (libcephfs, memstore, 8 clients set up). Three runs before and two after:

active clients renames/s p50 p99 max
1 before 3.7-7.7 7.0-7.4 ms 5.1 s 5.1 s
after 162-166 6.5-6.7 ms 11 ms 20-26 ms
4 before 284-364 8.4-8.7 ms 18-19 ms 4.5-4.9 s
after 517-520 7.4 ms 15-16 ms 28-32 ms
8 before 1780-1845 4.6-4.8 ms 8.4-9.1 ms 40-45 ms
after 1666-1732 4.8-5.0 ms 10-11 ms 47 ms

Writing a file and renaming it straight into the other rank's directory is unchanged by it (130 renames/s with 1 client, max 21-34 ms).

(The kernel client couldn't mount the main vstart cluster: its AES-256 cephx keys, and with an AES-128 key the 6.8 kernel saw no active MDS. The code the first two items change is the same on Reef and main.)

The new TestExports.test_rename_just_written_file_across_ranks sets mds_tick_interval to 10 and fails if any of ten such renames takes 5 s or more. I ran its steps by hand against both builds (10 s before, 0.1 s after); I couldn't run it under vstart_runner, which needs teuthology.

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

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)

🤖 Generated with Claude Code

@dvanders
dvanders requested a review from a team as a code owner October 27, 2026 21:43
@github-actions github-actions Bot added cephfs Ceph File System tests labels Oct 27, 2026
@dvanders
dvanders requested a review from xiubli October 27, 2026 21:56

@xiubli xiubli left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dvanders Good catch. I ran the test and reproduced it:

Before the fix I saw two tick waits per rename, about 10 s with the default mds_tick_interval of 5, with both the kernel client and ceph-fuse. The MDS log shows them one after the other:

00:17:01.514 mds.0 handle_discover blocking on xlocked [dentry #0x1/src/.../f3 ... (dn xlockdone x=1)
00:17:06.465 mds.0 handle_discover added dentry ...
00:17:06.468 mds.0 freezing srci [inode ... ap=4 ...]
00:17:11.457 mds.0 handle_peer_rename_prep (retry), inode FROZEN

So ceph-fuse hits the handle_discover() wait as well, not only the kernel client, and the 4.9-5.0 s in the description looks like one of the two waits.

The setup was a vstart cluster in a VM (kernel 7.2 and ceph-fuse) with 2 active MDSs, /src on rank 0 and /dst pinned to rank 1. Each run wrote a file, closed it and renamed it into /dst. I ran four rounds on one cluster in the order base, PR, PR, base, restarting both MDSs with the other binary between rounds. Latency is pooled over the two rounds of each variant, in ms:

client     case                 n    p50    p90    p95    p99  p99.9 p99.99    max
---------- ------------------- -- ------ ------ ------ ------ ------ ------ ------
kernel     cross, 4K     base 40   9912  10010  10031  10117  10117  10117  10117
                         PR   40    166    229    261   6459   6459   6459   6459
kernel     cross, 1M     base 40   9887  10018  10519  11594  11594  11594  11594
                         PR   40    127    177    195    256    256    256    256
kernel     cross, 4K,    base 20   9997  10030  10119  10119  10119  10119  10119
           tick 10       PR   20    129    190    211    211    211    211    211
kernel     same rank, 4K base 40    0.6    3.0    3.4    5.0    5.0    5.0    5.0
                         PR   40    2.4    6.6    8.5   10.7   10.7   10.7   10.7
ceph-fuse  cross, 4K     base 40   9898  10004  10008  10016  10016  10016  10016
                         PR   40    133    193    199    295    295    295    295
ceph-fuse  cross, 1M     base 40   9901  10008  10013  10163  10163  10163  10163
                         PR   40    194    358    482    664    664    664    664
ceph-fuse  cross, 4K,    base 20   9996  10011  10127  10127  10127  10127  10127
           tick 10       PR   20    178    460    556    556    556    556    556
ceph-fuse  same rank, 4K base 40    3.4    5.6    6.1    7.0    7.0    7.0    7.0
                         PR   40    8.8   23.5   34.0   57.0   57.0   57.0   57.0

"tick 10" is the new qa test's case, with mds_tick_interval set to 10. All the other rows use the default of 5. Every renamed file read back intact.

@xiubli

xiubli commented Oct 28, 2026

Copy link
Copy Markdown
Member

@dvanders When I was running the mdbench suites and found another similar bug badbcc5, could you include it in this PR ? Or I can create a new one ? Thanks.

@dvanders
dvanders force-pushed the wip-mds-rename-flush-log branch from 7a7270d to 0b4d05e Compare October 28, 2026 17:18
@dvanders

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the numbers, @xiubli. I've picked up your commit here, since it's the same tracker. It goes between the two existing ones, before the qa test.

I measured it on the same vstart setup: each client renames its oldest file into another client's directory, with the directories pinned alternately to the two ranks. With one active client it goes from 4-8 renames/s with p99 5.1 s to 160 renames/s with p99 11 ms. With 4 clients, the max drops from 4.5-4.9 s to about 30 ms. Writing a file and renaming it straight into the other rank's directory is unchanged by it. The numbers are in the description.

You're right that ceph-fuse also waits in handle_discover(). I've taken "with the kernel client" out of the description.

@dvanders

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@dvanders

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@xiubli xiubli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks @dvanders

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

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

dvanders and others added 3 commits November 10, 2026 09:37
A rename into a directory on another rank of a file the client has just
written waits a full mds_tick_interval (5 s). Two waits in that path
are for an update that is already submitted to the journal but not
flushed, and nothing asks for a flush, so the update is only journaled
by the next tick:

- handle_peer_rename_prep() freezes the renamed inode on the rank that
  owns it. When the client flushes its dirty caps on the file, at the
  same time or just before, _do_cap_update() holds an auth pin on the
  inode until the update is journaled, and the freeze waits for it.
  Flush the log when the freeze has to wait, and have _do_cap_update()
  ask for a flush when the inode is being frozen, for a cap flush that
  arrives after the freeze started.
- The other rank discovers the just-created source dentry, and
  handle_discover() blocks on its xlock, which the create holds until it
  is journaled. d0a7454 ("mds: do not replicate an xlocked dentry
  whose linkage is projected", ceph#72790) already nudges the log there.

On a vstart cluster with two active ranks, renaming a just-written 4 KiB
or 1 MiB file from a directory on rank 0 into one on rank 1 took a
median of 2.8-5.0 s with a kernel client and 3.5-4.6 s with ceph-fuse,
and about 1.5 s with mds_tick_interval set to 1. With this change it
takes 140-210 ms with either client, against 3 ms (kernel) and 37 ms
(ceph-fuse) within one rank. Measured on Reef 18.2.8. On main, with
ceph-fuse, the same renames took 4.9-5.0 s before and 16-110 ms after;
with mds_tick_interval at 10 they took 10 s before and 80-100 ms after.

Fixes: https://tracker.ceph.com/issues/82190
Assisted-by: Claude-Code-v2.1.303:claude-opus-5-5
Signed-off-by: Dan van der Ster <[email protected]>
A rename within a directory on one rank of a file whose inode another
rank holds a replica of makes the client's next request wait a full
mds_tick_interval (5 s).

The leader early-replies the rename, so journal_and_reply() leaves the
log unflushed.  The witness keeps the locks it took for the rename
until the leader commits and tells it to finish.  A request on the
witness's rank that needs one of those locks, such as the client's
lookup of the new name right after the rename, waits on the witness,
and nothing on the leader flushes the log for it: nudge_log() only
flushes the local log of a lock's auth.  The update is journaled at
the next tick.

Flush the log after an early reply when the request has witnesses.
This only adds a flush to multi-rank requests, which are already the
slow path.

Measured on a vstart cluster with two active ranks (libcephfs,
memstore), with clients renaming files into a peer's directory pinned
on the other rank (mdbench rename-xrank) or renaming files they have
just written (write-rename-xrank).  Two runs of each, shown as
run1/run2, latency in ms:

  rename-xrank
  clients            ops/s      p50        p99      p99.9        max
  1       before   3.6/3.4  2.7/4.6  5097/5097  5097/5097  5097/5097
          after    487/367  1.5/1.9    5.0/6.7    7.7/8.4  56.3/14.1
  4       before 1097/1191  2.8/2.6    7.4/7.4  16.7/21.7  1072/1653
          after  1154/1006  2.8/3.2    8.0/9.1  30.7/14.7  73.0/69.9
  8       before 1416/1412  4.8/4.8  12.4/14.1  32.1/33.5  61.4/73.0
          after  1391/1216  4.8/5.2  12.9/17.5  22.7/25.8   29.4/103

  write-rename-xrank
  clients            ops/s      p50        p99      p99.9        max
  1       before   317/298  2.3/2.3   9.1/10.0  12.9/14.1  14.7/25.8
          after    339/275  2.2/2.8    8.4/8.0  12.4/11.8  18.3/19.9
  4       before   794/850  4.8/4.6    9.1/8.7  25.8/18.3    584/665
          after    851/776  4.6/5.0   8.7/10.0  19.1/19.9    665/637
  8       before 1029/1085  7.7/7.4  16.7/17.5  32.1/28.2  83.2/69.9
          after   1067/992  7.7/8.0  16.0/19.1  29.4/35.0  61.4/83.2

The second 8-client rename-xrank run after the change is 14% slower
than the runs before it; more runs are needed to tell it from noise.

Fixes: https://tracker.ceph.com/issues/82190
Assisted-by: LLM
Signed-off-by: Xiubo Li <[email protected]>
Rename ten just-written files from a directory on rank 0 into one
pinned to rank 1, with mds_tick_interval at 10 s, and check that none
takes 5 s or more: each used to wait for the tick.

Fixes: https://tracker.ceph.com/issues/82190
Assisted-by: Claude-Code-v2.1.303:claude-opus-5-5
Signed-off-by: Dan van der Ster <[email protected]>
@dvanders
dvanders force-pushed the wip-mds-rename-flush-log branch from 0b4d05e to c1971d7 Compare November 10, 2026 16:38
@dvanders

Copy link
Copy Markdown
Contributor Author

Rebased on main. #72790 (d0a7454) already added the same nudge_log() in handle_discover(), so that hunk is gone and the first commit's message now points to it; the freeze and cap-flush part is unchanged. test_exports.py keeps both the new TestRenameWitnessDiscover from main and the test here.

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.

2 participants