From: Xiubo Li via B4 Relay <devnull+xiubo.li.clyso.com@kernel.org>
To: Ilya Dryomov <idryomov@gmail.com>,
Alex Markuze <amarkuze@redhat.com>,
Xiubo Li <xiubo.li@clyso.com>,
Viacheslav Dubeyko <slava@dubeyko.com>
Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/4] ceph: flush the OSD completions before destroying the mds client
Date: Mon, 19 Oct 2026 13:33:29 +0200 [thread overview]
Message-ID: <20261019-ceph-metrics-percpu-v2-3-1fa5229b00b8@clyso.com> (raw)
In-Reply-To: <20261019-ceph-metrics-percpu-v2-0-1fa5229b00b8@clyso.com>
From: Xiubo Li <xiubo.li@clyso.com>
The callbacks of OSD requests that complete with an error, or that are
aborted, are run from osdc->completion_wq instead of the messenger.
Like the ones run from the messenger, the read and write ones update the
client metrics in mdsc->metric and mdsc->subvol_metrics.
ceph_mdsc_destroy() only flushes the messenger before it frees those and
mdsc itself, while completion_wq keeps running until ceph_osdc_stop()
destroys it from ceph_destroy_client(), long after. A callback still
queued there then updates freed memory.
Add ceph_osdc_flush_completions() to libceph and call it right after
ceph_msgr_flush() in ceph_mdsc_destroy().
Signed-off-by: Xiubo Li <xiubo.li@clyso.com>
---
fs/ceph/mds_client.c | 2 ++
include/linux/ceph/osd_client.h | 1 +
net/ceph/osd_client.c | 11 +++++++++++
3 files changed, 14 insertions(+)
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index d4ef8a355a48..b62291f0e351 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -7046,6 +7046,8 @@ void ceph_mdsc_destroy(struct ceph_fs_client *fsc)
/* flush out any connection work with references to us */
ceph_msgr_flush();
+ /* and the OSD request callbacks that update our metrics */
+ ceph_osdc_flush_completions(&fsc->client->osdc);
/*
* Mark reset as failed and wake any blocked waiters before
diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index 52eb76e9d62a..6028754efe6a 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -585,6 +585,7 @@ extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
+extern void ceph_osdc_flush_completions(struct ceph_osd_client *osdc);
void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc);
int ceph_osdc_call(struct ceph_osd_client *osdc,
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 5f2c561ff4e2..ec5e8870ec6f 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -5164,6 +5164,17 @@ void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc)
}
EXPORT_SYMBOL(ceph_osdc_flush_notifies);
+/*
+ * Wait for the request callbacks queued on completion_wq to finish - for
+ * use before freeing what those callbacks touch
+ */
+void ceph_osdc_flush_completions(struct ceph_osd_client *osdc)
+{
+ dout("%s osdc %p\n", __func__, osdc);
+ flush_workqueue(osdc->completion_wq);
+}
+EXPORT_SYMBOL(ceph_osdc_flush_completions);
+
void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc)
{
down_read(&osdc->lock);
--
2.53.0
next prev parent reply other threads:[~2026-10-19 11:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-19 11:33 [PATCH v2 0/4] ceph: fix the buffered read size metric and make the subvolume metrics per CPU Xiubo Li via B4 Relay
2026-10-19 11:33 ` [PATCH v2 1/4] ceph: report the requested length in the netfs read metrics Xiubo Li via B4 Relay
2026-10-19 11:33 ` [PATCH v2 2/4] ceph: drop the unused subvolume metrics debug counters Xiubo Li via B4 Relay
2026-10-19 11:33 ` Xiubo Li via B4 Relay [this message]
2026-10-19 11:33 ` [PATCH v2 4/4] ceph: accumulate subvolume metrics per CPU 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=20261019-ceph-metrics-percpu-v2-3-1fa5229b00b8@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®