[PATCH] ceph: do not round random read misses out to the stripe unit
From: Xiubo Li via B4 Relay
Date: Mon Nov 30 2026 - 20:50:08 EST
From: Xiubo Li <xiubo.li@xxxxxxxxx>
ceph_netfs_expand_readahead() rounds every readahead request out to
the stripe unit, so that a read misses whole objects at a time. For a
small random read the VM asks for just the pages it needs, but the
request still grows to a whole object, 4 MiB by default: each 4 KiB
random read then reads 4 MiB from the OSDs, and a random read workload
over a large file is limited by OSD bandwidth after a few thousand
reads per second. fio does not show it by default, as it sets
POSIX_FADV_RANDOM, which turns readahead off.
The VM sets the file's readahead window before it reads ahead: after
a sequential miss, at the start of a file, for an oversized read or
for a fault. A random miss is read as is and leaves the window alone.
Only round out a readahead request that starts inside the window, and
leave one outside it as the VM asked for it.
Buffered fio reads without an fadvise hint (fadvise_hint=0), 16 jobs
over 16 x 4 GiB files, 60 s, page and OSD caches dropped first, on a
3-OSD cluster (BlueStore on NVMe); IOPS with p99 latency:
+------------------------+-------------------+-------------------+
| | before | after |
+------------------------+-------------------+-------------------+
| 4K random read | 1191 (31.9 ms) | 63351 (0.45 ms) |
| 64K random read | 1170 (31.6 ms) | 25965 (1.35 ms) |
| 4K random read, mmap | 59490 (0.51 ms) | 59708 (0.51 ms) |
| 4K sequential read | 1142611 (4 us) | 1233376 (4 us) |
| 64K sequential read | 78380 (3.29 ms) | 79121 (3.23 ms) |
| 1M sequential read | 4819 (46.9 ms) | 4814 (46.4 ms) |
+------------------------+-------------------+-------------------+
The OSD read size of a random 4K miss drops from 4 MiB to 4 KiB, and
sequential reads still go to the OSDs in whole objects. A random 4K
read run that checks a checksum in every block found no errors. ior
random 4 KiB reads from 16 processes over 4 mounts went from 0.0071
to 0.218 GiB/s.
Signed-off-by: Xiubo Li <xiubo.li@xxxxxxxxx>
---
Each small random read miss on a CephFS file read a whole object from
the OSDs. This keeps random misses at the size the VM asks for and
leaves sequential readahead as it is.
---
fs/ceph/addr.c | 23 +++++++++++++++++++++++
fs/ceph/super.h | 3 +++
2 files changed, 26 insertions(+)
diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index de3431f28ba9..d42bf5a6c575 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -370,6 +370,14 @@ static void ceph_netfs_expand_readahead(struct netfs_io_request *rreq)
*/
if (priv->file_ra_strided)
return;
+
+ /*
+ * A random read miss: the VM reads just the pages asked for,
+ * and rounding that out to the stripe unit would read up to
+ * a whole object (4 MiB by default) for each small read.
+ */
+ if (priv->file_ra_random)
+ return;
}
/* Readahead is disabled */
@@ -753,6 +761,21 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file)
priv->file_ra_disabled = file->f_mode & FMODE_RANDOM;
priv->file_ra_strided = READ_ONCE(fi->ra_strided);
+ /*
+ * The VM sets the readahead window before it reads ahead,
+ * after a sequential miss, at the start of a file or for a
+ * fault, but reads a random miss without touching it. A
+ * readahead request outside the window is a random miss.
+ */
+ if (rreq->origin == NETFS_READAHEAD) {
+ pgoff_t index = rreq->start >> PAGE_SHIFT;
+ pgoff_t ra_start = READ_ONCE(file->f_ra.start);
+ unsigned int ra_size = READ_ONCE(file->f_ra.size);
+
+ priv->file_ra_random = index < ra_start ||
+ index - ra_start >= ra_size;
+ }
+
/*
* ceph_read_iter() and ceph_filemap_fault() hold caps and
* register an rw context before entering the page cache.
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 978dd7be1778..f0102b1cb475 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -565,6 +565,9 @@ struct ceph_netfs_request_data {
/* Set it if the file is read in records at a fixed stride */
bool file_ra_strided;
+
+ /* Set it if the request is a random read miss, not readahead */
+ bool file_ra_random;
};
static inline struct ceph_inode_info *
---
base-commit: 3f90412e989cb381d4bf96260468f5c7b2d08655
change-id: 20261130-b4-ceph-random-read-noexpand-bb9dc5c985db
Best regards,
--
Xiubo Li <xiubo.li@xxxxxxxxx>