Skip to content

osd, os/bluestore, kv: keep read-once data out of the OSD's caches - #73273

Open
ming1 wants to merge 12 commits into
ceph:mainfrom
ming1:wip-osd-cache-admission
Open

ming1 wants to merge 12 commits into
ceph:mainfrom
ming1:wip-osd-cache-admission

Conversation

@ming1

@ming1 ming1 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On dense RGW hosts memory per OSD is a direct cost, and an OSD runs up to
its osd_memory_target under RGW small-object writes, deep scrub and
backfill although almost nothing it caches is used again: every onode
touched and every RocksDB block read goes to the front of its cache, and
the tuner, which looks only at recency, hands them the budget. Keeping
read-once data out of the caches halves the peak under RGW writes at the
same throughput, which makes a lower osd_memory_target for RGW workloads
possible without hurting performance.

What changes (v3, 12 commits)

  1. osd: recovery push reads use FADVISE_DONTNEED
    (RecoveryHandle::cache_dont_need was never set).
  2. osd: EC recovery reads use it too, in both EC backends, honouring the
    handle's client-waiting flag; the shards read for a reconstruction are
    sent once, and the sources kept them cached.
  3. os/bluestore: two preps without behaviour change (_add() loses its
    unused level; _touch() is factored out of maybe_unpin()).
  4. os/bluestore: an onode enters a bounded probation FIFO and is admitted
    to the LRU on its second later use. Probation is bounded by the arrivals
    of the last four age bins (the shard keeps its own ring of arrivals per
    bin) and at least 1024 onodes per shard, so backfill scans are not
    evicted early; over budget the promoted onodes come first, with half of
    probation's share reserved for newcomers so a shifted working set can
    still prove itself. bluestore_onode_cache_probation_ratio (0.1;
    0 = old behaviour), changeable at run time. Perf counter
    onodes_probation. Unit tests.
  5. kv/rocksdb_cache: EvictEntry()/LRU_InsertAfter() factored out
    (also fixes EraseUnRefEntries() not decrementing the element count),
    then the same probation for binned_lru blocks; probation is not
    binned, so the tuner sees it at its lowest priority.
    rocksdb_cache_probation_ratio (0.1; 0 = off), run time. Counter
    probation. Unit tests in a new unittest_binned_lru_cache that drives
    one shard directly.
  6. os/bluestore: ghost list. The shard remembers the keys its LRU
    evicted last, as many as its budget, and a miss on one of them goes
    straight back to the LRU, so a hot set squeezed by the tuner grows back
    as it would under a plain LRU; scan residue leaves from probation and is
    not remembered. Unit tests.
  7. doc: configuration reference section and release note.

Both probations need the age bins to rotate, and only BlueStore's mempool
thread rotates them, so the shards start with probation off and BlueStore
turns it on from that thread; tools that open the store without it, and
the mon's block cache, admit at once as before.

Applies on main, no dependency on open PRs; the maybe_unpin() fix
(tracker 82605) and its test are #73664 now. unittest_bluestore_types
172/172, unittest_binned_lru_cache 16/16.

Test results

A/B on a 2-OSD vstart cluster on two NVMe drives, osd_memory_target
4 GiB, base = main plus #73018, every workload on a cluster created from
scratch for each build (drives discarded first), 120 s per steady phase.
Peak RSS GiB, osd.0 / osd.1:

Workload Before After Change Time or throughput, before -> after
Deep scrub, all PGs 4.36 / 4.43 1.34 / 1.32 -69% / -70% 319 s -> 319 s
Recovery, source / target OSD 4.04 / 1.99 2.27 / 1.59 -44% / -20% clean after 312 s -> 297 s
RGW PUT 4 MiB 1.55 / 1.54 1.54 / 1.54 -1% / 0% 1174 -> 1117 MiB/s
RGW PUT 4 KiB 4.51 / 4.48 2.01 / 2.00 -55% / -55% 8395 -> 8437 obj/s
RGW GET 4 MiB 4.33 / 4.32 3.77 / 3.44 -13% / -20% 2718 -> 2366 MiB/s
RGW GET 4 KiB 3.68 / 4.03 3.73 / 3.43 +1% / -15% 3092 -> 3092 obj/s
RBD write 4 MiB 1.63 / 1.65 1.61 / 1.62 -1% / -2% 1164 -> 1275 MiB/s
RBD write 4 KiB 2.10 / 2.08 2.10 / 2.09 0% / 0% 33.2k -> 33.5k IOPS
RBD read 4 KiB 3.38 / 3.37 3.37 / 3.38 0% / 0% 180k -> 179k IOPS
RBD read 4 MiB 4.19 / 4.31 4.27 / 4.28 +2% / -1% 4214 -> 4710 MiB/s

The same host as an EC cluster: six OSDs on the two drives, RGW data pool
erasure coded k=4 m=2, rbd and index pools replicated. The EC shard
rebuild takes osd.1 down during 4 MiB PUTs to the EC pool, then its shards
are rebuilt from the other five. Peak RSS GiB, range over the OSDs:

Workload, EC 4+2 data pool Before After Change Time or throughput, before -> after
Deep scrub 4.35 - 4.47 1.13 - 1.21 -72% .. -75% 261 s -> 267 s
EC shard rebuild, 5 source OSDs 2.89 - 3.04 1.09 - 1.17 -60% .. -63% clean after 154 s -> 161 s
EC shard rebuild, target osd.1 1.13 1.07 -6%
RGW PUT 4 MiB 0.70 - 0.79 0.71 - 0.79 within 5% 1002 -> 1028 MiB/s
RGW PUT 4 KiB 4.39 - 4.68 1.46 - 1.65 -64% .. -69% 6350 -> 6140 obj/s
RGW GET 4 MiB 4.29 - 4.44 2.68 - 2.95 -32% .. -38% 2178 -> 2127 MiB/s
RGW GET 4 KiB 3.82 - 4.05 2.63 - 2.95 -25% .. -32% 3072 -> 3076 obj/s

The rebuild row is patch 3's: patch 2 is read by the replicated backend
only, and without patch 3 each of the five sources caches the shard data
it read once.

Throughput and scrub / recovery times are within run-to-run spread in
every phase (RGW GET 4 MiB varies between 2.4 and 3.0 GB/s on this host
regardless of build). On the replicated cluster RGW GET runs at the target
on both builds, since the tuner hands the caches whatever the rest of the
heap leaves; what changes is the content: the patched OSD spends 0.4 GiB
less in allocator free lists and untracked heap, the tuner turns that into
buffer cache (1.4 -> 2.0 GiB on osd.0) and 26% of the run's read bytes hit
instead of 17%. The GET set, ~35k 4 MiB objects read ~2.3 times each in
random order, is beyond any cache. On the EC cluster each OSD touches a
1 MiB shard per object, the base's 1.15 GiB of allocator overhead left by
read-once churn drops to 0.25 GiB and osd.0 serves 83% of its read bytes
from cache instead of 53%.

Hot set beside a scan (review point 1): fio 4 KiB random reads at qd64 on
four RBD images, alone, then through a deep scrub of all PGs (~1.5M small
RGW objects, ~770 s), then alone again; osd.0:

Build During the scrub: IOPS / p99 / onode misses After: IOPS / onode misses
main 140k / 15.1 ms / 1.81M 143k / 16.5k
v1 as reviewed 128k / 17.7 ms / 2.56M 134k / 195k
v2 135k / 16.1 ms / 2.04M 142k / 211

v1 lost IOPS to the scan; v2 is within this host's 10% spread of main
during the scrub and keeps the whole hot set resident after it (the ghost
list is what makes the last column: with the tuner's budget below the hot
set, a missed hot onode re-entered through probation and was evicted
before its second use).

Probation ratios swept over 0.05-0.5: 0.05 doubles the hot set's block
cache misses, 0.25 and 0.5 add 0.6 and 1.8 GiB to the scrub peak for no
gain in time; 0.1 is kept.

Left for later: memtables under RGW 4 KiB PUTs (0.7 GiB, outside the
tuner), the data cache under a read-once scan (it fills to the budget in
both builds; a separate change).

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
    • Includes unit test(s)
    • Includes integration test(s)
    • Includes bug reproducer
    • No tests

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Config Diff Tool Output

+ added: rocksdb_cache_probation_ratio (global.yaml.in)
+ added: bluestore_onode_cache_probation_ratio (global.yaml.in)

The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
Ignore this comment if docs are already updated. To make the "Check ceph config changes" CI check pass, please comment /config check ok and re-run the test.

@dvanders dvanders left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ming1, these numbers are great, and they fit with the scaling in #72964: the deep scrub and RGW 4 KiB PUT peaks falling by more than half at the same speed is exactly what makes a lower osd_memory_target realistic. Patches 1 and 2 look good to me as they are. A few things on 3 and 4:

1. Mixed workloads: can the hot set still be evicted by a scan? In LruOnodeCacheShard::_trim_to(), probation is only trimmed first while it is above _probation_max(); below that, eviction takes the lru tail. _probation_max() includes recent, the onodes stamped in the last four age bins, and the bins count lru touches as well as probation arrivals. So with a hot set being read while a scrub or backfill runs, pmax is roughly hot set plus four seconds of scan, probation stays under it, and when the shard is over budget the onodes evicted are the hot set's, not the scan's. The tests run each workload alone, so they would not show this. Could you add a run with RBD 4 KiB random reads on a hot set during a deep scrub (or a backfill), and compare onode hits and read IOPS with and without the series? If it does show up, counting only probation arrivals in recent might be enough.

2. The maybe_unpin() change is a bug fix of its own. On main, after the loop that follows the onode to its current shard, the code links it into this->lru and this->age_bins while holding the other shard's lock, so a split_cache() racing with an unpin can corrupt the list. Your if (ocs != this) delegation fixes that. Could it be its own commit with a tracker, so it can be backported without the rest?

3. Unit tests for the list handling. Neither the lru_probation_/lru_low_pri_ bookkeeping in BinnedLRUCacheShard nor probation and promotion in the onode cache has a unit test, and both are easy to get subtly wrong. test_bluestore_types.cc already creates lru onode cache shards, and BinnedLRUCache has no unit test at all yet. Some cases that seem worth covering:

  • promotion only after uses in two later bins;
  • EvictFromLRU() taking the oldest main entry while probation is under half its share;
  • the two list pointers after removing the newest probation entry and the newest low-pri entry.

Smaller things:

  • The comment on probation says it is "evicted before lru", but _trim_to() evicts from lru while probation is within _probation_max().
  • rocksdb_cache_probation_ratio is only read at startup; flags: [startup] would make ceph config set say so.
  • _add() no longer uses level and leaves an onode with !exists unlinked but counted in num. If that really can't happen, an assert would say so.
  • The config-change check needs a /config check ok.

@ming1

ming1 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/config check ok

@ming1

ming1 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All of it is in the pushed v2 (14 commits); answers under each point.

1. Mixed workloads: can the hot set still be evicted by a scan? [...] If it does show up,
counting only probation arrivals in recent might be enough.

Confirmed, and that is the core of the fix: the shard keeps its own ring of probation arrivals per
bin and bounds probation by it; the age bins and the tuner's view are unchanged. Two more rules
came out of the run: over budget the promoted onodes come first (probation gets what the budget
leaves after the LRU, half of it reserved for newcomers), and only linked onodes count against the
budget when trimming (the arriving onode is pinned during its own add's trim).

The run, on the host of the description (2 NVMe OSDs, 4 GiB target, 8 shards): fio 4 KiB random
reads at qd64 on four RBD images, alone, then through a deep scrub of all PGs (~1.5M small RGW
objects, ~770 s), then alone again; osd.0:

build during the scrub: IOPS / p99 / onode misses after: IOPS / onode misses
main 140k / 15.1 ms / 1.81M 143k / 16.5k
PR as reviewed 128k / 17.7 ms / 2.56M 134k / 195k
PR v2 135k / 16.1 ms / 2.04M 142k / 211

The reviewed build shows the regression you predicted; v2 is within this box's spread of main
(about 10% in IOPS) during the scrub and keeps the whole hot set after it.

The last column needed the ghost list from "Left for later", now its own commit: with the tuner's
budget below the hot set, a missed hot onode re-entered through probation and died before its
second use, so the promoted set never grew back (misses after the scan stayed at 161k). The shard
now remembers the keys its LRU evicted last, as many as its budget, and a miss on one of them goes
straight back to the LRU; scan residue leaves from probation and is not remembered. The RBD 4 KiB
read phase of the description's table now misses 174k / 179k against main's 198k / 213k with the
same ~29.7k onodes resident (625k / 565k with 21k before the ghost list).

2. The maybe_unpin() change is a bug fix of its own. [...] its own commit with a tracker

Done: first commit, on main's code, test as the second commit (unpin through the shard an onode was
moved out of, both shards' age bins checked). Introduced by a3057f4 ("os/bluestore: fix onode
ref counting", 2022); tracker https://tracker.ceph.com/issues/82605.

3. Unit tests for the list handling. [...]

All three are in. unittest_bluestore_types has 18 OnodeCache tests (promotion after two later
bins, probation off at start, ratio 0 at start and at run time, the scan-beside-hot-set case, the
budget rules, the floor, popped-while-pinned onodes, the maybe_unpin delegation, five for the ghost
list). The new unittest_binned_lru_cache drives one BinnedLRUCacheShard directly, independent
of the RocksDB Cache API: 16 tests, including promotion after two later bins, trim to the share
under capacity, eviction sparing probation below half its share and taking it at or above, and both
list pointers after erasing the newest probation and the newest low-pri entry.

  • The comment on probation says it is "evicted before lru" [...]

Fixed in the admission commit.

  • rocksdb_cache_probation_ratio is only read at startup [...]

Both ratios are runtime options now. Probation needs the age bins to rotate, and only BlueStore's
mempool thread rotates them, so the shards start with probation off and BlueStore applies both
ratios from that thread (at start, on config change, before the DB closes), the block caches
through PriCache::set_probation_ratio(). Tools that open the store without the thread, and the
mon's block cache, admit at once as before.

  • _add() no longer uses level and leaves an onode with !exists unlinked but counted [...]

It cannot happen: every caller holds a reference besides the map's, so the onode is pinned on add
and linked, or dropped, when that reference goes. A prep commit drops level and asserts
pin_nref > 1; the branch is dead on main too.

  • The config-change check needs a /config check ok.

Posting it with the push.

v2 order: unpin fix + test; recovery push reads and EC recovery reads with FADVISE_DONTNEED
(as reviewed, the EC one now honouring the handle's client-waiting flag); two no-behaviour-change
preps (_add() loses level, _touch() factored out of maybe_unpin()); onode admission +
tests; EvictEntry()/LRU_InsertAfter() prep for the block cache (also fixes
EraseUnRefEntries() not decrementing the count); block-cache probation + tests; ghost list +
tests; docs.

Re-run on the same host against current main plus #73018, each workload on a new cluster on
discarded NVMe, 120 s per phase, peak RSS GiB osd.0 / osd.1:

workload main + #73018 v2 change time / throughput
deep scrub 4.36 / 4.43 1.34 / 1.32 -69% / -70% 319 s -> 319 s
recovery, source / target 4.04 / 1.99 2.27 / 1.59 -44% / -20% clean 312 s -> 297 s
RBD write 4 MiB 1.63 / 1.65 1.61 / 1.62 -1% / -2% 1164 -> 1275 MiB/s
RBD write 4 KiB 2.10 / 2.08 2.10 / 2.09 0% / 0% 33.2k -> 33.5k IOPS
RBD read 4 KiB 3.38 / 3.37 3.37 / 3.38 0% / 0% 180k -> 179k IOPS
RBD read 4 MiB 4.19 / 4.31 4.27 / 4.28 +2% / -1% 4214 -> 4710 MiB/s
RGW PUT 4 MiB 1.55 / 1.54 1.54 / 1.54 -1% / 0% 1174 -> 1117 MiB/s
RGW PUT 4 KiB 4.51 / 4.48 2.01 / 2.00 -55% / -55% 8395 -> 8437 obj/s
RGW GET 4 MiB 4.33 / 4.32 3.77 / 3.44 -13% / -20% 2718 -> 2366 MiB/s
RGW GET 4 KiB 3.68 / 4.03 3.73 / 3.43 +1% / -15% 3092 -> 3092 obj/s

RBD onode misses over the run: 79.0k / 87.1k base, 80.6k / 88.6k v2. RGW GET sits at the target
on both builds (the tuner gives the caches what the rest of the heap leaves); v2 spends 0.4 GiB
less in allocator free lists and untracked heap, the tuner turns it into buffer cache (1.4 -> 2.0
GiB) and 26% of the run's read bytes hit instead of 17%. The GET set (~35k 4 MiB objects, read
~2.3x at random) is beyond any cache; GET 4 MiB throughput varies 2.4 to 3.0 GB/s run to run here.

Same host as an EC cluster (6 OSDs, RGW data pool EC 4+2, EC recovery = osd.1 down during 4 MiB
PUTs to the EC pool, shards rebuilt from the other five), peak RSS GiB, range over the OSDs:

workload (EC 4+2, 6 OSDs) main + #73018 v2 change time / throughput
deep scrub 4.35 - 4.47 1.13 - 1.21 -72% .. -75% 261 s -> 267 s
EC shard recovery, 5 sources 2.89 - 3.04 1.09 - 1.17 -60% .. -63% clean 154 s -> 161 s
EC shard recovery, target osd.1 1.13 1.07 -6%
RGW PUT 4 MiB 0.70 - 0.79 0.71 - 0.79 within 5% 1002 -> 1028 MiB/s
RGW PUT 4 KiB 4.39 - 4.68 1.46 - 1.65 -64% .. -69% 6350 -> 6140 obj/s
RGW GET 4 MiB 4.29 - 4.44 2.68 - 2.95 -32% .. -38% 2178 -> 2127 MiB/s
RGW GET 4 KiB 3.82 - 4.05 2.63 - 2.95 -25% .. -32% 3072 -> 3076 obj/s

The sources are where the EC recovery-read commit shows: the shards read once for the rebuild no
longer fill their caches. RGW GET stays under the target here with v2 (each OSD touches a 1 MiB
shard per object); the base's 1.15 GiB of allocator overhead left by read-once churn drops to
0.25 GiB, and osd.0 served 83% of its read bytes from cache instead of 53%.

Two things I looked at and did not take, both in the commit messages: evicting LRU onodes to keep
num <= max when pinned onodes push it over (that is the hot-set churn the series removes), and
leaving onode probation out of the age bins like the block cache's (under a pure scan the budget
is probation itself, so the four-bin guarantee would have no funding).

@ifed01

ifed01 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

I'd make a separate PR for b037a40 and 7e64833 as they are rather bug fixing.
Additionally you might keep these commits here as well.

@ming1

ming1 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

I'd make a separate PR for b037a40 and 7e64833 as they are rather bug fixing. Additionally you might keep these commits here as well.

Looks nice suggestion, will take it by creating new tracker & PR for the two fixes.

Thanks,

ming1 added 5 commits November 9, 2026 02:26
RecoveryHandle::cache_dont_need was never set, so the first chunk of every
push was read without a fadvise flag and BlueStore kept it in the buffer
cache; later chunks already passed DONTNEED. On a 2-OSD test cluster the
source OSD's data cache grew to 1.16 GiB this way during backfill.

Default the flag to true. maybe_kick_recovery clears it, since a client op
is waiting for that object: that object's first chunk stays cached as
before, while later chunks are read with the flag as they always were. A
push to more than one shard still caches its first read, as before. Only
the replicated backend honours the flag. Pulls are unchanged: a pull
source already read with the flag, and the pull target, which serves the
reads that follow, keeps the recovered copy it writes in its buffer cache.

Data cache of the source OSD during the same backfill: 1.16 -> 0.00 GiB.

Signed-off-by: Ming Lei <[email protected]>
Both erasure-code backends read the shards for a reconstruction with no
fadvise flag: the legacy backend passes 0 and the new backend's recovery
read_request_t never sets its flags. That data is sent once and not read
again on the source, yet BlueStore keeps it in its buffer cache. On a
six-OSD test cluster with a 4+2 pool, each of the five source OSDs of a
shard rebuild grew a 1.9 GiB data cache this way.

Pass FADVISE_DONTNEED on both paths, driven by the same
RecoveryHandle::cache_dont_need as the replicated backend's push reads:
when a client op waits for the object, the primary clears it and the
shards read for that object stay cached on their sources, which serve the
client's reads of an EC object. Crimson's EC recovery, which shares
ECCommon, sets no flag and keeps caching.

Source OSDs of a shard rebuild on the test cluster: peak RSS 3.02 -> 1.16
GiB, data cache 1.9 -> 0 GiB, rebuild 164 -> 156 s.

Signed-off-by: Ming Lei <[email protected]>
_add() links the onode into the LRU, at the end its level argument
chooses, when the onode is not pinned. Every caller holds a reference
besides the onode map's, so that branch is never reached: the onode is
linked when that reference is dropped, in maybe_unpin(). Drop the branch
and the argument, and assert the reference. No change in behaviour.

Signed-off-by: Ming Lei <[email protected]>
maybe_unpin() links an onode into the LRU, or moves it to the front, in
two branches with their own age bin bookkeeping; _rm() and _trim_to()
unlink with theirs. Move the linking into _touch(), with _stamp() for the
age bin, _link_front() and _unlink() for the list, and clear the bin
pointer wherever an onode is unlinked, so that an onode carries a stamp
exactly while it is linked. No change in behaviour.

Signed-off-by: Ming Lei <[email protected]>
Every onode loaded or created went to the front of the shard's LRU, so one
pass over many objects (scrub, backfill, writes never read back) filled
the cache with onodes used once, and the tuner, which counts only the
mempool half of an onode's heap, let it. RGW 4 KiB PUTs drove an OSD with
a 4 GiB target to 4.74 GiB, 3.8 GiB of it such onodes and their untracked
heap.

An onode now enters a probation FIFO on its first use and moves to the
LRU once it is used in two later age bins: one op sequence falls into one
bin, and a scan that lists then reads an object gives one later use.
Probation is trimmed first once it is above its share: the largest of
bluestore_onode_cache_probation_ratio of the shard (0.1; 0 keeps the old
single LRU), what arrived on probation during the last four age bins
(counted in a ring of the shard's own, as the age bins count the hot
set's touches too), and bluestore_onode_cache_probation_floor onodes
(1024, a backfill scan's osd_backfill_scan_max objects of one PG, read
into one shard before they are pushed). Over budget the promoted onodes
come first and probation gets what the budget leaves after them, but
never less than half its share, so a working set that shifts can still
prove itself against a stale LRU. Only linked onodes count against the
budget: the onode being added is pinned while the trim runs. Onodes on
probation are stamped into the age bins like the rest, so the tuner
budgets for them.

Admission needs the age bins to rotate, which only the mempool thread
does, with or without the autotuner. The thread applies the ratio and
floor to the shards when it starts, when either option changes (through
the config change counter it polls) and, as 0, when it stops; a tool
that opens the store without the thread admits every onode at once, and
so does bluestore_cache_age_bin_interval 0. With the ratio set to 0 at
run time, what is on probation stays until it is used, and is admitted
then. The onodes_probation perf counter reports the probation count.

Signed-off-by: Ming Lei <[email protected]>
ming1 added 7 commits November 9, 2026 02:29
Cover the probation rules of LruOnodeCacheShard: an onode is promoted only
after uses in two later age bins, a ratio of 0 admits at once, the floor
keeps the newest arrivals, and a scan beside a hot set evicts the scan's
residue and not the hot set. The maybe_unpin() test uses the new fixture's
object names.

Signed-off-by: Ming Lei <[email protected]>
EvictFromLRU() and EraseUnRefEntries() each carried a copy of the
eviction sequence, and the copy in EraseUnRefEntries() did not decrement
the element count, so the elems stat kept every entry it dropped.
LRU_Insert() linked an entry by hand in both of its branches.

Keep one EvictEntry(), which unlinks, uncharges, counts and chains an
entry for freeing, and one LRU_InsertAfter(). No change in behaviour
beyond the count.

Signed-off-by: Ming Lei <[email protected]>
binned_lru inserted every block at the head of its low-priority pool, so a
pass over many keys (a backfill listing, a scrub's omap reads) filled the
cache with blocks read once, and the tuner grew the cache for them because
they sat in its newest age bins: 0.1 -> 0.9 GiB during backfill while the
OSD was at its target.

A new block sits at the tail of the list, on probation, and moves to the
main pool once it is used in two later age bins: one op's hits do not
count, nor does the single later use of a block that straddles two scan
chunks. A block looked up before its inserter released it is still new.
Probation is bounded to rocksdb_cache_probation_ratio of the capacity
(0.1; 0 disables it), trimmed on every insert, kept at least half full
when the main pool is evicted, and not binned, so the tuner counts it at
its lowest priority. Blocks inserted with high priority (index and filter
blocks) and blocks larger than probation's share go to the main pool at
once. When the cache is full and a new block would overflow probation's
share, the oldest probation block goes rather than a main-pool one, so an
insert never evicts twice; a capacity cut takes the oldest blocks,
probation's first. A smaller share set at run time throws nothing away:
the newest probation blocks join the main pool as its oldest, in the
oldest bin, until probation fits.

A shard starts with probation off. The rule needs the age bins to rotate,
and only BlueStore's mempool thread rotates them, so that thread turns
probation on through PriCache::set_probation_ratio() when it starts and
when the option changes, and off before it stops and the DB is closed;
the mon's block cache is unchanged, and bluestore_cache_age_bin_interval
0 keeps probation off. Cache stat and perf counter: probation (bytes).

Signed-off-by: Ming Lei <[email protected]>
The binned LRU block cache had no unit test. Drive one shard directly, so
the test does not depend on the Cache API of the RocksDB version in use,
and cover: promotion after uses in two later age bins, ratio 0, probation
trimmed to its share while the cache is under capacity, eviction sparing
probation below half its share and taking it at or above, and the two
list pointers after removing the newest probation and low-priority
entries.

Signed-off-by: Ming Lei <[email protected]>
With the tuner's onode budget below the hot set, a hot onode that misses
comes back through probation, and the budget evicts it again before its
second later use, so the LRU never grows back to what the budget would
hold: on a 4 KiB random read of a set the tuner had squeezed, the cache
missed three times as often as a plain LRU.

Remember the keys of the onodes the LRU evicts, as many as the shard's
budget, oldest first, and admit a miss on one of them straight to the
LRU, as 2Q's ghost list does. Only existing onodes evicted from the LRU
are remembered: a scan's residue leaves from probation and gets no
shortcut, and a deleted object's name may be reused. The keys are 64-bit
hashes of the whole object id, kept in the bluestore_cache_other mempool
so the tuner charges them to the meta cache; a collision promotes a
stranger, which the LRU then ages out as any other. The list is dropped
while admission is off.

Signed-off-by: Ming Lei <[email protected]>
A miss on an onode the LRU evicted lately goes back to the LRU while an
unknown onode goes on probation; the keys are remembered up to the
shard's budget, the oldest forgotten first, and from a key's latest
eviction; evictions with admission off are not remembered, and turning
admission off forgets them.

Signed-off-by: Ming Lei <[email protected]>
Add a Cache Admission section to the BlueStore configuration reference
for the probation options and the ghost list, and a release note for the
series.

Signed-off-by: Ming Lei <[email protected]>
@ming1
ming1 force-pushed the wip-osd-cache-admission branch from 9e9198f to fd5095d Compare November 9, 2026 08:36

@dvanders dvanders left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ming1, v2 answers everything I raised, and the scrub run is exactly the test I was hoping for: the hot set surviving the scan (211 misses afterwards vs 16.5k on main) is a better result than plain LRU, not just parity. The recovery FADVISE_DONTNEED patches and the block-cache probation look good to me. A few things before I approve:

1. Merge order with #73664. On its own, maybe_unpin() here still calls _touch(o) on this after finding the shard that holds the onode, so the #73664 bug now reaches the probation list and probation_arrivals too. I merged #73664 into this branch locally: the code merges cleanly and its early hand-off covers _touch(); only test_bluestore_types.cc conflicts, because both append tests at the same place. So #73664 should go first. Could you say so in the description? #73673 (keep at least one age bin) is related too: _cache_probation_ratio() checks bluestore_cache_age_bin_interval but not the bin count, and admission relies on age_bins.front().

2. Ghost list memory. The ghosts are allocated in bluestore_cache_other, which MetaCache::_get_used_bytes() counts, so they raise get_bytes_per_onode() and the tuner keeps fewer onodes for the same bytes. At up to max keys per shard, a list node plus an unordered_map node per key, that's probably small next to an onode, but could you put a number on it at your 4 GiB setup? A perf counter for the ghost count, next to onodes_probation, would also help anyone tuning this later.

3. A low-memory data point. I built fd5095d (RelWithDebInfo) and ran the unit tests: unittest_binned_lru_cache 16/16, OnodeCache* 17/17, and unittest_bluestore_types 173/173. Then I ran a small version of your scrub test on one file-backed OSD with osd_memory_target 1 GiB:

  • a hot pool of 20k 4 KiB objects, read with rados bench rand -t 32;
  • deep-scrubbed beside it: a pool of 400k 4 KiB objects;
  • both probation ratios at 0.1 against 0, with the OSD restarted between runs.
ratio hot IOPS during scrub / after hot-set misses during scrub onodes at peak OSD RSS at peak
0.1 28.0k / 24.7k ~0 52.8k (32.8k on probation) 487 MiB
0 27.0k / 25.9k ~6.7k 85.5k (tuner-capped) 620 MiB

"Hot-set misses" is onode misses during the scrub minus the 400k scan objects. With admission on, the scrub didn't push a single hot onode out. With it off, the tuner had to cap the cache and the hot set took about 6.7k re-misses. IOPS are within noise on this box, since the hot set's data stays in the page cache. At 2 GiB the difference is starker: with admission off, the scrub grew the cache to 355k onodes and the OSD to 1.41 GiB, against 56k and 559 MiB with it on.

With admission on, the shard never got near its budget in these runs, so the ghost list stayed empty and I couldn't measure point 2 here. A run with a hot set larger than the budget would exercise it.

4. Defaults and backports. Both ratios default to 0.1, so every cluster changes cache behaviour on upgrade, and the bins now rotate even with bluestore_cache_autotune=false. I'm fine with that on main given the numbers. Which releases do you intend to backport to? I'd keep it on main until it has run in a release cycle.

Nit: the comment in _rm() says a promoted onode "keeps its place in lru" after a split, but _rm() unlinks it and its next unpin puts it at the front of the new shard's lru. "stays promoted" would be accurate.

@anthonyeleven anthonyeleven left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs lgtm but suggest for the PR / commit titles

out of OSD caches

The ' can confuse scripting.

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@RaminNietzsche

Copy link
Copy Markdown
Member

Ceph PR triage — related open PRs

Queried #73273 against KB snapshot 2026-11-10T06:02:21 in 2.1s.
Signals are candidates for human review, not merge blockers.

Category Confidence Other PR(s) Note
stated-supersede medium #72964 #72964 description says: "Running OSDs at 1.5 GiB (HDD) / 2 GiB (flash) instead of 4 / 6 GiB, together with #73018 and #73273" (both still open)

This comment is updated in place when the workflow re-runs (hidden HTML marker). Data: read-only GitHub + local git analysis; no labels or merges were changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants