[PATCH 2/2] ceph: check the caps of a closed file the MDS thinks we read sooner

From: Xiubo Li via B4 Relay

Date: Thu Nov 26 2026 - 23:35:08 EST


From: Xiubo Li <xiubo.li@xxxxxxxxx>

A file closed after reading is checked again at caps_wanted_delay_max
only: the earlier check at caps_wanted_delay_min is for files that
hold write caps. Until then the MDS still has Fr in our 'wanted'
mask, so if another client is writing the file, the filelock stays
in MIX and that writer has no Fb for up to 60 s after a single "tail"
of the file here.

Queue a closed regular file for the check at caps_wanted_delay_min
also when the MDS has Fr or a write cap in the 'wanted' mask of one of
its caps. The check then sends the one cap message that tells the MDS
we no longer want them; it would send the same message at
caps_wanted_delay_max anyway. A file opened without asking the MDS
(caps already issued) is not affected.

Same test as in the previous patch:

+--------------+---------------+----------------------------------+
| | before "tail" | after "tail" |
| kernel | ops/s | ops/s |
+--------------+---------------+----------------------------------+
| before | ~120,000 | ~85, as long as the test ran |
| patch 1 | ~120,000 | ~110,000, from 60 s after "tail" |
| patch 1 + 2 | ~115,000 | ~120,000, from 10 s after "tail" |
+--------------+---------------+----------------------------------+

Reported-by: PATRICK BÉGOU <patrick.begou@xxxxxxxxxxxxxxxxxxxxxx>
Link: https://tracker.ceph.com/issues/83627
Signed-off-by: Xiubo Li <xiubo.li@xxxxxxxxx>
---
fs/ceph/caps.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index add63a8f6212..2a6c21d8b7af 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -5261,9 +5261,15 @@ void ceph_put_fmode(struct ceph_inode_info *ci, int fmode, int count)
* the exclusive caps from us first when another client
* looks at the file, e.g. stats a file we just created.
* Check again after caps_wanted_delay_min instead.
+ *
+ * The same goes for a file the MDS still thinks we want to
+ * read: it keeps the filelock in MIX, and a writer on
+ * another client has no Fb, until we tell it we don't.
*/
if (S_ISREG(ci->netfs.inode.i_mode) &&
- (__ceph_caps_issued(ci, NULL) & CEPH_CAP_ANY_WR))
+ ((__ceph_caps_issued(ci, NULL) & CEPH_CAP_ANY_WR) ||
+ (__ceph_caps_mds_wanted(ci, false) &
+ (CEPH_CAP_ANY_WR | CEPH_CAP_FILE_RD))))
__cap_delay_requeue_idle(mdsc, ci);
}
spin_unlock(&ci->i_ceph_lock);

--
2.53.0