[PATCH v2 0/2] ceph: don't let a mapped write overwrite other clients' writes
From: Xiubo Li via B4 Relay
Date: Sat Dec 05 2026 - 05:57:17 EST
Alex pointed out in his review of "ceph: only check the caps of a clean
file early after its last close" 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. This happens without that patch as well; this series fixes
it.
Patch 1 adds the CMPEXT OSD op to libceph. Patch 2 keeps a copy of a
folio dirtied that way, and writes back only the bytes this client
changed: as WRITE ops of just the changed ranges when they are few, or
else as whole runs of folios behind a CMPEXT of the copy, which falls
back to the changed ranges when another client wrote there meanwhile.
Testing, on a vstart cluster with three kernel mounts of one fs (A, B
and C), KASAN and lockdep enabled, 3 rounds, no splats:
- B stores through a shared mapping while C pwrite()s disjoint bytes of
the same pages: before, C's bytes were lost; now none are.
- B and C store through shared mappings and A pwrite()s, each into its
own 64-byte stripes, for 30s: every byte is its owner's last write.
- After B's own writeback, B's mapping shows what C wrote afterwards,
and B's next store does not undo it.
- fsx with a second client holding the file open for writing.
Performance, release config, B storing 8 bytes into K random pages of
a 1 MiB file and calling msync(), 30s per run, median of 3-5
alternating runs, ops/s:
case before after
MIX, K=1 9403 9422 +0.2%
MIX, K=16 2072 2089 +0.8%
MIX + C pwrite()ing, K=1 6677 6765 +1.3%
MIX + C pwrite()ing, K=16 1513 1502 -0.7%
B alone (Fb), K=1 11577 12254 (noise, +-10%)
B alone (Fb), K=16 5289 5275 -0.3%
p50-p95 msync() latency in MIX is up to 40us higher, p99-p99.99 lower.
Link to the patch Alex reviewed: https://patch.msgid.link/20261201-ceph-cap-idle-release-clean-only-v1-1-f4bb68a744db@xxxxxxxxx
Signed-off-by: Xiubo Li <xiubo.li@xxxxxxxxx>
---
Changes in v2:
- Patch 2: move the diff run arrays of ceph_write_kept() off the stack,
into a scratch buffer embedded in the heap-allocated merge batch (or
allocated for a lone folio), fixing a -Wframe-larger-than warning on
32-bit arm (1456 -> 568 bytes with KASAN), reported by the kernel test
robot: https://lore.kernel.org/oe-kbuild-all/20261204215859.a5U1Zloy-lkp@xxxxxxxxx/
- Link to v1: https://patch.msgid.link/20261204-ceph-mmap-no-overwrite-v1-0-323689b39a29@xxxxxxxxx
---
Xiubo Li (2):
libceph: add the CMPEXT OSD op
ceph: don't let a mapped write overwrite other clients' writes
fs/ceph/addr.c | 773 ++++++++++++++++++++++++++++++++++++++++++---
fs/ceph/inode.c | 1 +
fs/ceph/super.h | 1 +
include/linux/ceph/rados.h | 1 +
net/ceph/osd_client.c | 10 +-
5 files changed, 738 insertions(+), 48 deletions(-)
---
base-commit: 3f90412e989cb381d4bf96260468f5c7b2d08655
change-id: 20261204-ceph-mmap-no-overwrite-b4bbfd1e2dcc
Best regards,
--
Xiubo Li <xiubo.li@xxxxxxxxx>