Repository navigation
Conversation
KernelDevice already keeps both an O_DIRECT and a buffered descriptor and already honours a buffered flag in read() and read_random() via choose_fd(). aio_read() had no such flag and always used fd_directs[WRITE_LIFE_NOT_SET], so the async path - the one that serves BlueStore object reads - could not use the page cache at all. Add the flag, defaulted to false so existing callers are unaffected. libaio cannot submit buffered I/O without blocking: io_submit() on a descriptor that was not opened O_DIRECT degrades to a synchronous submit and would stall every read batched with it. So a buffered read is always done synchronously, with read() on the buffered descriptor. Callers wait for their aios anyway, so this only gives up the parallelism across the extents of one read, and a page cache hit returns at once. io_uring is deliberately not used for this: BlueStore shares one ring between threads under a submission lock, and it is not used in the field. SPDK bypasses the kernel, so NVMEDevice takes the flag and ignores it. Assisted-by: Claude-Code-v2.1.303:claude-opus-5-5 Signed-off-by: Dan van der Ster <[email protected]>
BlueStore opens the block device O_DIRECT, so object data is cached only by BlueStore itself, inside osd_memory_target. To keep an OSD small, that target has to be small, and the data cache shrinks with it: on a rotational OSD every read it misses is another seek, where FileStore on XFS would have been served from the page cache. Add an option to issue object data reads through the buffered descriptor, so the page cache can act as the data cache instead, sized by whatever memory the host is not otherwise using and given back under pressure. This is the mechanism bluefs_buffered_io has applied to RocksDB reads by default for years, extended to object data. It relies on an O_DIRECT write invalidating the page cache over the range it writes. The existing per-read buffered flag is reused, so reads a client hints NOCACHE or DONTNEED do not fill the page cache either. Blobs without a checksum are always read O_DIRECT. If a page cache read fails checksum validation, as one left stale by a racing O_DIRECT write would, the pages it came from are dropped and the read is retried O_DIRECT: the existing retry would otherwise read the same stale pages again. Two perf counters, page_cache_read_bytes and page_cache_csum_retries, show how much is read this way and whether that ever happens. Defaults to off. The costs are documented on the option: data is held twice unless BlueStore's own data cache is shrunk to match, page cache pressure can provoke the swapping stalls known from bluefs_buffered_io, and buffered reads are synchronous. Assisted-by: Claude-Code-v2.1.303:claude-opus-5-5 Signed-off-by: Dan van der Ster <[email protected]>
Add unit coverage for reads issued through the non-O_DIRECT descriptor, which is what bluestore_page_cache_read turns on. At the device layer (unittest_bdev): - a buffered aio_read returns what a direct write put there, and returns the same bytes a direct read does - a buffered read is not handed to libaio: it completes inline and leaves nothing queued on the IOContext, where a direct read is queued for async submission. This is the observable difference between the two paths, so assert on it rather than only on the data, otherwise the tests would pass even if the flag were ignored - a buffered and a direct read may share one IOContext, with the buffered one completing inline while the direct one is still queued - page cache coherence: a range pulled into the page cache by a buffered read must not be readable in its stale form after an O_DIRECT write supersedes it. The whole feature rests on this, as bluefs_buffered_io already does by default, so test it rather than assume it At the store layer (store_test): - with bluestore_page_cache_read enabled, write, remount to empty BlueStore's own caches so the read has to reach the device, and read back; then overwrite, remount, and confirm the previous contents do not reappear. Also read a subrange of a range already cached - a page cache read that fails its checksum is retried O_DIRECT: with every checksum failing, page_cache_csum_retries counts exactly one (only the first attempt used the page cache) and the read ends in EIO; with injection off, it reads back correctly Assisted-by: Claude-Code-v2.1.303:claude-opus-5-5 Signed-off-by: Dan van der Ster <[email protected]>
Config Diff Tool Output+ added: bluestore_page_cache_read (global.yaml.in)
The above configuration changes are found in the PR. Please update the relevant release documentation if necessary. |
|
Thanks for this. The motivation is a really good one: an OSD that has to run That said, I have doubts that the page cache is the right place to get that
The data cache sits at its 128 MiB floor on a 1 GiB OSD because the rest of |
|
My concern (mostly speculative) is that CRC32 is pretty weak and it has good enough chances to miss the error in this scenario. Prior to this change we used it for data-at-rest error detection which are not that frequent per se. Now it goes as a mean to avoid races between read and write.Which could be dangerous. |
AI suggest that you might want to use RWF_DONTCACHE flag (needs fresh kernels and likely no libaio) or switch to XXH3-64 checksum alg |
|
Thanks both, this is a really useful review. @ming1 I checked your points and you're right on all of them. In I also agree with your reading of the numbers: the real win in the capped tests came from trimming what the tuner doesn't manage (PG log, RocksDB memtables/WAL, in-flight client messages), not from the page cache. So I'll move this to draft and work on that instead:
@ifed01 agreed. |
|
The first part of the plan from my last comment is up as #72964: the uncached limits now scale with |
|
@dvanders Great effort. Currently we have:
Proposal:
The proposal make it impossible to cache on reads, but do not cache on writes. I am not sure whether it was a goal of the PR. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
BlueStore opens the block device O_DIRECT, so object data is cached only by
BlueStore itself, inside
osd_memory_target. Running small OSDs means a smalltarget, and the data cache shrinks with it.
This adds
bluestore_page_cache_read(default off). Object data reads then gothrough the buffered descriptor, so the kernel page cache can act as the data
cache. It is sized by memory the host isn't otherwise using and given back under
pressure. This is what
bluefs_buffered_ioalready does for RocksDB reads,extended to object data.
How it works
blk:aio_read()gains abufferedflag (default false). A buffered readis a synchronous
pread()on the buffered fd: libaio would block at submit ona non-O_DIRECT fd. io_uring is not used.
os/bluestore: only blobs with a checksum are read through the pagecache. A stale page, for example after a racing O_DIRECT write, then fails
verification instead of being returned. When a page-cache read fails its
checksum, the cached pages are dropped and the read is retried O_DIRECT;
retries never use the page cache. Reads hinted NOCACHE/DONTNEED stay O_DIRECT.
page_cache_read_bytes,page_cache_csum_retries.this, e.g.
bluestore_cache_meta_ratio=0.5,bluestore_cache_kv_ratio=0.45,bluestore_cache_kv_onode_ratio=0.04.Measurements
vstart with 6 OSDs, 256 PGs/OSD, an rbd pool at size 3 with a 24 GiB image
(72 GiB of replicas),
bluestore_debug_enforce_settings=hdd, local NVMe. AllOSDs ran in one cgroup with a hard
memory.maxthat also counts the pagecache. Phases: sequential fill, 3 GiB of 4K random writes, two passes of 4K
random reads, osd.0 out/in recovery, deep scrub.
(*) With a shorter PG log and smaller RocksDB memtables; at defaults, a 1 GiB
target OOMs on this workload whether or not this option is enabled.
at the limit with no OOM kills.
all runs.
Resolved: memory left after recovery
In 2 of 3 runs with this option and the low data-cache ratios together, the OSD that was marked out and back in ended recovery with ~80 MiB in the
bluestore_writingmempool. This was not caused by this change. The OSD op history kept the last 20 recovery pushes and their data, becauseMOSDPGPushdid not drop its buffers once an op was done. It reproduces with this option off, on a 3-OSD cluster with default settings. Fixed separately in #72885 (tracker 81945).Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.