From: Xiubo Li via B4 Relay <devnull+xiubo.li.clyso.com@kernel.org>
To: Ilya Dryomov <idryomov@gmail.com>,
Alex Markuze <amarkuze@redhat.com>,
Viacheslav Dubeyko <slava@dubeyko.com>
Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
Xiubo Li <xiubo.li@clyso.com>
Subject: [PATCH v9 1/5] ceph: use READ_ONCE/WRITE_ONCE for oldest_tid
Date: Wed, 02 Dec 2026 09:24:42 +0100 [thread overview]
Message-ID: <20261202-ceph-mdsc-mutex-optimization-v9-1-f7719b7c4f57@clyso.com> (raw)
In-Reply-To: <20261202-ceph-mdsc-mutex-optimization-v9-0-f7719b7c4f57@clyso.com>
From: Xiubo Li <xiubo.li@clyso.com>
The oldest_client_tid sent in the MDS request header only tells the
MDS which completed-request records it may drop. A stale, older
value is harmless: the MDS just keeps a few records longer than
needed. The field only moves forward while requests are tracked and
does not need lock serialization to stay correct.
Switch all accesses to READ_ONCE() and WRITE_ONCE() to prevent
the compiler from tearing or inventing loads, documenting that
these lockless accesses are intentional. This removes the last
reason the MDS request-send path had to be serialized under
mdsc->mutex.
A value of 0 is the one exception: the MDS takes it as "trim every
completed request", which drops the records it needs to recognize a
retried request. __unregister_request() used to store 0 and then
look for the next tracked request, so a lockless reader could pick
up that 0 while other requests were still in flight. Find the
replacement first and publish it with a single store, so 0 is only
ever published when no tracked request remains.
Signed-off-by: Xiubo Li <xiubo.li@clyso.com>
---
fs/ceph/mds_client.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 3d3bd5e06a92..a6820b7567fe 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -1320,8 +1320,8 @@ static void __register_request(struct ceph_mds_client *mdsc,
if (!req->r_mnt_idmap)
req->r_mnt_idmap = &nop_mnt_idmap;
- if (mdsc->oldest_tid == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK)
- mdsc->oldest_tid = req->r_tid;
+ if (READ_ONCE(mdsc->oldest_tid) == 0 && req->r_op != CEPH_MDS_OP_SETFILELOCK)
+ WRITE_ONCE(mdsc->oldest_tid, req->r_tid);
if (dir) {
struct ceph_inode_info *ci = ceph_inode(dir);
@@ -1342,18 +1342,26 @@ static void __unregister_request(struct ceph_mds_client *mdsc,
/* Never leave an unregistered request on an unsafe list! */
list_del_init(&req->r_unsafe_item);
- if (req->r_tid == mdsc->oldest_tid) {
+ if (req->r_tid == READ_ONCE(mdsc->oldest_tid)) {
struct rb_node *p = rb_next(&req->r_node);
- mdsc->oldest_tid = 0;
+ u64 next_tid = 0;
+
+ /*
+ * Find the replacement first and publish it with a single
+ * store. The MDS takes an oldest_client_tid of 0 as "trim
+ * every completed request", so a lockless reader must never
+ * see a transient 0 while another tracked request remains.
+ */
while (p) {
struct ceph_mds_request *next_req =
rb_entry(p, struct ceph_mds_request, r_node);
if (next_req->r_op != CEPH_MDS_OP_SETFILELOCK) {
- mdsc->oldest_tid = next_req->r_tid;
+ next_tid = next_req->r_tid;
break;
}
p = rb_next(p);
}
+ WRITE_ONCE(mdsc->oldest_tid, next_tid);
}
erase_request(&mdsc->request_tree, req);
@@ -1778,7 +1786,7 @@ create_session_full_msg(struct ceph_mds_client *mdsc, int op, u64 seq)
ceph_encode_32(&p, 0);
/* version == 7, oldest_client_tid */
- ceph_encode_64(&p, mdsc->oldest_tid);
+ ceph_encode_64(&p, READ_ONCE(mdsc->oldest_tid));
msg->front.iov_len = p - msg->front.iov_base;
msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
@@ -2882,7 +2890,7 @@ static struct ceph_mds_request *__get_oldest_req(struct ceph_mds_client *mdsc)
static inline u64 __get_oldest_tid(struct ceph_mds_client *mdsc)
{
- return mdsc->oldest_tid;
+ return READ_ONCE(mdsc->oldest_tid);
}
#if IS_ENABLED(CONFIG_FS_ENCRYPTION)
@@ -3561,9 +3569,6 @@ static void complete_request(struct ceph_mds_client *mdsc,
complete_all(&req->r_completion);
}
-/*
- * called under mdsc->mutex
- */
static int __prepare_send_request(struct ceph_mds_session *session,
struct ceph_mds_request *req,
bool drop_cap_releases)
@@ -3678,9 +3683,6 @@ static int __prepare_send_request(struct ceph_mds_session *session,
return 0;
}
-/*
- * called under mdsc->mutex
- */
static int __send_request(struct ceph_mds_session *session,
struct ceph_mds_request *req,
bool drop_cap_releases)
--
2.53.0
next prev parent reply other threads:[~2026-12-02 8:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 8:24 [PATCH v9 0/5] ceph: reduce mdsc->mutex contention in the cephfs kclient Xiubo Li via B4 Relay
2026-12-02 8:24 ` Xiubo Li via B4 Relay [this message]
2026-12-02 8:24 ` [PATCH v9 2/5] ceph: replace the request_tree rbtree with an xarray keyed by r_tid Xiubo Li via B4 Relay
2026-12-02 8:24 ` [PATCH v9 3/5] ceph: add wait_list_lock for wait-list serialization Xiubo Li via B4 Relay
2026-12-02 8:24 ` [PATCH v9 4/5] ceph: move mdsc->mutex into __do_request() Xiubo Li via B4 Relay
2026-12-02 8:24 ` [PATCH v9 5/5] ceph: narrow mdsc->mutex scope in replay_unsafe_requests Xiubo Li via B4 Relay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202-ceph-mdsc-mutex-optimization-v9-1-f7719b7c4f57@clyso.com \
--to=devnull+xiubo.li.clyso.com@kernel.org \
--cc=amarkuze@redhat.com \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=slava@dubeyko.com \
--cc=xiubo.li@clyso.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®