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,
Anthony D'Atri <anthony.datri@gmail.com>,
Xiubo Li <xiubo.li@clyso.com>
Subject: [PATCH v3 1/3] ceph: do not read ahead on an mmap fault without Fc
Date: Wed, 02 Dec 2026 14:18:20 +0100 [thread overview]
Message-ID: <20261202-ceph-append-excl-v3-1-68fdbef33f32@clyso.com> (raw)
In-Reply-To: <20261202-ceph-append-excl-v3-0-68fdbef33f32@clyso.com>
From: Xiubo Li <xiubo.li@clyso.com>
ceph_filemap_fault() faults a page in through filemap_fault() also when
it got Fr but not Fc, e.g. while another client writes the file and the
filelock is in MIX. It registers an rw context first, and
ceph_init_request() lets every request with such a context through, so
the read-around of that fault fills the page cache with the folios next
to the faulting one as well, without Fc.
Nothing drops those folios: we do not hold Fc, so no revoke of it
invalidates them when another client writes the file. Once we get Fc
and Fb again, a buffered write into one of them uses it as it is and
writes the whole folio back, with the old data over what the other
client wrote in between. Seen with an mmap writer on one client while
two clients took turns appending to the file: on every turn change a
few records of the other client were overwritten with zeroes; with
MADV_RANDOM on the mapping (no read-around) none were.
Fail the readahead of a request whose rw context holds neither Fc nor
LAZYIO, as when there is no rw context at all: the fault then reads
only the folio it needs.
Tested on a vstart cluster, KASAN and lockdep enabled, two mounts, 4
O_APPEND writers on each taking turns on Fx (patch 3 of this series),
150 records of 64 bytes per writer, and an mmap writer rewriting the
first page of the file on one of the mounts:
+--------------------------------------+------+-------------------+
| case | runs | records zeroed |
+--------------------------------------+------+-------------------+
| without this patch | 12 | 62-88 of 1200 |
| without this patch, MADV_RANDOM | 4 | 0 |
| with this patch | 3 | 0 |
+--------------------------------------+------+-------------------+
Signed-off-by: Xiubo Li <xiubo.li@clyso.com>
---
fs/ceph/addr.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 49b58f85dc17..d14121694051 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -754,6 +754,7 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file)
struct ceph_file_info *fi = file ? file->private_data : NULL;
int got = 0, want = CEPH_CAP_FILE_CACHE;
struct ceph_netfs_request_data *priv;
+ struct ceph_rw_context *rw_ctx;
int ret = 0;
/* [DEPRECATED] Use PG_private_2 to mark folio being written to the cache. */
@@ -775,7 +776,22 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file)
* ceph_read_iter() and ceph_filemap_fault() hold caps and
* register an rw context before entering the page cache.
*/
- if (ceph_find_rw_context(fi)) {
+ rw_ctx = ceph_find_rw_context(fi);
+ if (rw_ctx) {
+ /*
+ * ceph_filemap_fault() may hold Fr only. Then read
+ * just the folio that faulted, not ahead of it: no
+ * revoke of Fc would drop the folios read ahead when
+ * another client writes the file, and once we get
+ * Fc and Fb a buffered write would write them back
+ * stale over that client's data.
+ */
+ if (rreq->origin == NETFS_READAHEAD &&
+ !(rw_ctx->caps & (CEPH_CAP_FILE_CACHE |
+ CEPH_CAP_FILE_LAZYIO))) {
+ ret = -EACCES;
+ goto out;
+ }
rreq->netfs_priv = priv;
return 0;
}
--
2.53.0
next prev parent reply other threads:[~2026-12-02 13:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:18 [PATCH v3 0/3] ceph: serialize O_APPEND writes across clients Xiubo Li via B4 Relay
2026-12-02 13:18 ` Xiubo Li via B4 Relay [this message]
2026-12-02 13:18 ` [PATCH v3 2/3] ceph: send the cap messages of an inode in the order they were prepared Xiubo Li via B4 Relay
2026-12-02 13:18 ` [PATCH v3 3/3] ceph: serialize O_APPEND writes across clients on Fx 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-append-excl-v3-1-68fdbef33f32@clyso.com \
--to=devnull+xiubo.li.clyso.com@kernel.org \
--cc=amarkuze@redhat.com \
--cc=anthony.datri@gmail.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®