[PATCH v2] ceph: only check the caps of a clean file early after its last close
From: Xiubo Li via B4 Relay
Date: Thu Dec 03 2026 - 02:20:01 EST
From: Xiubo Li <xiubo.li@xxxxxxxxx>
Commit 2377544a8ffe ("ceph: check the caps of a closed file after
caps_wanted_delay_min") queues every regular file that still holds
exclusive or write caps for a cap check caps_wanted_delay_min after its
last close.
Leave out a file whose dirty data is not yet written back when that
check comes due. Its caps get checked anyway when its writeback
completes (ceph_put_wrbuffer_cap_refs()), which flushes and gives them
back in one message, 30-35s after the write with the default
dirty_expire_centisecs. An earlier check has to flush them first, a
second cap message and a second inode update in the MDS journal for
every such file.
That extra cost hits any workload that writes files and closes them
soon after. Measured with mdtest on bare metal: 1 MDS, 2 BlueStore OSDs
on NVMe, 4 kernel mounts, 16 processes. "small files" creates files in
one shared directory and writes 3901 bytes to each, "empty files"
creates empty files, a directory per process. Medians of 2 runs. Caps
messages are the ones the MDS handles, journal events the ones it logs,
both per file:
+-------------+-----------------+--------+-------+
| workload | | before | after |
+-------------+-----------------+--------+-------+
| small files | kops/s | 6.64 | 7.87 |
| | caps msgs/file | 1.98 | 1.09 |
| | journal ev/file | 2.98 | 2.09 |
| empty files | kops/s | 10.15 | 10.31 |
| | caps msgs/file | 1.00 | 0.99 |
| | journal ev/file | 1.99 | 1.98 |
+-------------+-----------------+--------+-------+
The early check made writing small files 13% slower (from 7.66 kops/s);
with this it is back to where it was. Empty files still give their
caps back early.
Checking such files after a fixed delay instead does not help. With
10s or 20s writing small files is as slow as before (6.65, 6.66), with
30s it is half way (7.36), and from 40s on it is the same as with this
change (7.81, 7.88): by then writeback has given the caps back.
Still queue such a file at its last close, and skip it only when the
check comes due. Its writeback may complete before
caps_wanted_delay_min is up, e.g. with an fsync() or sync() around the
close. The check at writeback completion then still finds the caps
wanted and leaves them to caps_wanted_delay_max: left out at close, the
file would give them back about 65s after the close instead of 5-10s.
Fixes: 2377544a8ffe ("ceph: check the caps of a closed file after caps_wanted_delay_min")
Signed-off-by: Xiubo Li <xiubo.li@xxxxxxxxx>
---
A follow-up to "ceph: check the caps of a closed file after
caps_wanted_delay_min", which is already in the testing branch: v1
also checks the caps of files with dirty data early, which costs the
MDS a second cap message and journal event per file and made writing
many small files 13% slower in mdtest. This brings it back, see the
numbers in the commit message.
Alex pointed out in his review of v1 that a MAP_SHARED store on a
client holding Fw but neither Fb nor Fc (the file in MIX) dirties the
whole folio, so its writeback can overwrite a write another client has
completed. That happens without this patch as well, and is left for a
separate discussion.
Link to v1 of that patch: https://patch.msgid.link/20261008-ceph-cap-idle-release-v1-1-86e7a8bf36d0@xxxxxxxxx
---
Changes in v2:
- Queue a file with dirty data at its last close again, and skip it in
check_delayed_caps_list() only if it is still under writeback by
then. v1 left it out at close, so when its writeback completed
within caps_wanted_delay_min of the close (e.g. fsync() or sync()
around the close), the check at writeback completion still found the
caps wanted, and they were given back only after
caps_wanted_delay_max: about 65s instead of 5-10s (Alex Markuze).
- Link to v1: https://patch.msgid.link/20261201-ceph-cap-idle-release-clean-only-v1-1-f4bb68a744db@xxxxxxxxx
---
fs/ceph/caps.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index cc8748f7e0bd..9ea880f20559 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -5047,6 +5047,22 @@ static unsigned long check_delayed_caps_list(struct ceph_mds_client *mdsc,
break;
list_del_init(&ci->i_cap_delay_list);
+ /*
+ * A closed file with dirty data not yet written back gets its
+ * caps checked when the writeback completes
+ * (ceph_put_wrbuffer_cap_refs()), and that check flushes and
+ * gives them back in one message. Checking them now could
+ * only flush the dirty caps, not give back BUFFER while it is
+ * in use: a second cap message and a second inode update in
+ * the MDS journal.
+ */
+ if (list == &mdsc->cap_idle_delay_list &&
+ READ_ONCE(ci->i_wrbuffer_ref)) {
+ doutc(cl, "skip %p %llx.%llx with dirty data\n",
+ &ci->netfs.inode, ceph_vinop(&ci->netfs.inode));
+ continue;
+ }
+
inode = igrab(&ci->netfs.inode);
if (inode) {
/*
---
base-commit: 3f90412e989cb381d4bf96260468f5c7b2d08655
change-id: 20261010-ceph-cap-idle-release-clean-only-30aa18a01a3a
Best regards,
--
Xiubo Li <xiubo.li@xxxxxxxxx>