Repository navigation
Conversation
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. |
ec9779d to
e2b1008
Compare
dvanders
left a comment
There was a problem hiding this comment.
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
probationsays it is "evicted before lru", but_trim_to()evicts fromlruwhile probation is within_probation_max(). rocksdb_cache_probation_ratiois only read at startup;flags: [startup]would makeceph config setsay so._add()no longer usesleveland leaves an onode with!existsunlinked but counted innum. If that really can't happen, an assert would say so.- The config-change check needs a
/config check ok.
|
/config check ok |
e2b1008 to
9e9198f
Compare
|
Thanks for the review. All of it is in the pushed v2 (14 commits); answers under each point.
Confirmed, and that is the core of the fix: the shard keeps its own ring of probation arrivals per The run, on the host of the description (2 NVMe OSDs, 4 GiB target, 8 shards): fio 4 KiB random
The reviewed build shows the regression you predicted; v2 is within this box's spread of main The last column needed the ghost list from "Left for later", now its own commit: with the tuner's
Done: first commit, on main's code, test as the second commit (unpin through the shard an onode was
All three are in.
Fixed in the admission commit.
Both ratios are runtime options now. Probation needs the age bins to rotate, and only BlueStore's
It cannot happen: every caller holds a reference besides the map's, so the onode is pinned on add
Posting it with the push. v2 order: unpin fix + test; recovery push reads and EC recovery reads with Re-run on the same host against current main plus #73018, each workload on a new cluster on
RBD onode misses over the run: 79.0k / 87.1k base, 80.6k / 88.6k v2. RGW GET sits at the target Same host as an EC cluster (6 OSDs, RGW data pool EC 4+2, EC recovery = osd.1 down during 4 MiB
The sources are where the EC recovery-read commit shows: the shards read once for the rebuild no Two things I looked at and did not take, both in the commit messages: evicting LRU onodes to keep |
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]>
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]>
9e9198f to
fd5095d
Compare
dvanders
left a comment
There was a problem hiding this comment.
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.
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
Ceph PR triage — related open PRsQueried #73273 against KB snapshot
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. |
Motivation
On dense RGW hosts memory per OSD is a direct cost, and an OSD runs up to
its
osd_memory_targetunder RGW small-object writes, deep scrub andbackfill 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_targetfor RGW workloadspossible without hurting performance.
What changes (v3, 12 commits)
osd: recovery push reads useFADVISE_DONTNEED(
RecoveryHandle::cache_dont_needwas never set).osd: EC recovery reads use it too, in both EC backends, honouring thehandle's client-waiting flag; the shards read for a reconstruction are
sent once, and the sources kept them cached.
os/bluestore: two preps without behaviour change (_add()loses itsunused
level;_touch()is factored out ofmaybe_unpin()).os/bluestore: an onode enters a bounded probation FIFO and is admittedto 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.kv/rocksdb_cache:EvictEntry()/LRU_InsertAfter()factored out(also fixes
EraseUnRefEntries()not decrementing the element count),then the same probation for
binned_lrublocks; probation is notbinned, so the tuner sees it at its lowest priority.
rocksdb_cache_probation_ratio(0.1; 0 = off), run time. Counterprobation. Unit tests in a newunittest_binned_lru_cachethat drivesone shard directly.
os/bluestore: ghost list. The shard remembers the keys its LRUevicted 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.
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_types172/172,
unittest_binned_lru_cache16/16.Test results
A/B on a 2-OSD vstart cluster on two NVMe drives,
osd_memory_target4 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:
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:
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:
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