Repository navigation
Conversation
dvanders
left a comment
There was a problem hiding this comment.
Thanks @ming1, nice find. I reproduced it.
Benchmark: vstart, 6 OSDs, local NVMe, a 3 GiB rbd image as the hot set, fio with the rbd engine, caches dropped first. Base vs this PR, interleaved, two runs each; values are means. 4K random read, second (warm) 60 s pass, and 4 MiB sequential read:
osd_memory_target |
base | this PR | |
|---|---|---|---|
| 2 GiB | 4K random read | 49,375 IOPS, p99 1.21 ms | 62,021 IOPS, p99 1.00 ms (+26%) |
| data cache hit rate | 39% | 97% | |
| data cache per OSD (used / committed) | 315 MiB (79% of 385) | 525 MiB (89% of 565) | |
| 4M sequential read | 3.9 GiB/s | 5.1 GiB/s (+31%) | |
| 4 GiB | 4K random read | 54,100 IOPS | 62,789 IOPS (+16%) |
| data cache hit rate | 63% | 100% | |
| 4M sequential read | 4.8 GiB/s | 5.1 GiB/s |
The data cache stalls at 69–79% of its committed size without the patch, as you describe. With it, the hot set fits, and PriorityCache even commits more to the data cache because it's being used. My gain is smaller than yours (+16–26% vs 19×) since my baseline wasn't disk-bound, but the direction and the hit rates match.
I went through the maths: limits sum to at most data_alloc, every shard keeps its ⅛ floor, a uniformly full OSD converges back to the even split, and a shard below its even share grows back by about ⅛ of a share per resize, so nothing starves. The lock-free _get_bytes() read matches DataCache::_get_used_bytes().
A few suggestions, none blocking:
- Could
shard_limitbecome a small static function with a unit test (sum ≤ alloc, even split when nothing is held, the floor, an evenly loaded OSD unchanged, no overflow past 4 GiB)? The tracker reproducer is good evidence but isn't a regression test. - Onode shards are split evenly by the same PG mapping (
max_shard_onodes), so they may have the same imbalance. Worth a follow-up. - A
dout(20)of the per-shard limits would make this observable in the field.
|
This PR has been added to wip-bharath9-testing-20261027.065249-main. |
|
This PR addresses the problem of unused cache, which by itself is an 100% admirable goal. I believe in many conditions it can degrade performance. It should get the config parameter (on/off) and a documentation what the change is. I am not objecting to the feature. Hand-waving explanation of how this change can degrade performance. Current state New variant Insensitivity to change (Please bear in mind that I am recalling all algorithms from memory, I welcome corrections.) |
aclamk
left a comment
There was a problem hiding this comment.
Please add configuration parameter controlling the feature.
35e5088 to
ab36bcc
Compare
|
@aclamk thanks for the review.
Added
You are right, I measured it. 4-OSD vstart, rbd 4K random reads plus
With memory to spare, the data cache takes what it used to leave unused and meta loses about a quarter of its onodes; under contention both are the same.
The split does not freeze: a shard below its even share always gets a limit above what it holds (limit >= even/8 + 7/8 * held), so it grows every resize. Modelling your example, it is back to 25/25/25/25 within about 30 resizes (1.5 s). What it cannot do is go above its even share while the other shards stay full, same as today. |
Config Diff Tool Output+ added: bluestore_cache_data_shard_weighted (global.yaml.in)
The above configuration changes are found in the PR. Please update the relevant release documentation if necessary. |
ab36bcc to
7bc2cda
Compare
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
7bc2cda to
7b18587
Compare
|
/config check ok The new option |
7b18587 to
9f9b723
Compare
|
New push for @aclamk's two comments, no behaviour change:
Unit tests and the tracker's hot-set test re-run on the new code. |
9f9b723 to
bc91096
Compare
|
jenkins test make check |
|
jenkins test windows |
bc91096 to
809d4b2
Compare
|
Hi @aclamk Thanks for your review! All your comments have been addressed, can you unblock this PR so we can move on? Or if you have any other concerns, please let us know. thanks, |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
balance_priority() serves each cache's request in a loop that adds the grant to the cache's bytes for that priority. At LAST it then splits the remaining memory by ratio with set_cache_bytes(), which overwrites what the loop just granted: the memory left the pool, but no cache is committed it. BlueStore's caches ask at LAST for content older than their last age bin, so the grant is lost on every balance and the OSD runs that far below its target: 170 to 270 MiB of a 1484 MiB pool on a 4-OSD vstart with 2 M small objects, about 1 % on a small hot set. Add the ratio share on top of the loop's grants. Skip a zero share: rbd-mirror's cache asserts on add_cache_bytes() at a priority it did not ask at, and its ratio is 0. Same load with the fix: the onode cache's commit went from 368 to 792 MiB (510k instead of 371k onodes, 99 % instead of 93 % hits) and the OSD mapped 1744 instead of 1546 MiB of its 2048 MiB target. The RocksDB block cache went from 288 to 184 MiB because it lost its 24 MiB share of the unspent memory and asked for less (130 to 49 MiB, fewer lookups); its request was granted in full in both runs. Fixes: https://tracker.ceph.com/issues/82836 Signed-off-by: Ming Lei <[email protected]>
_resize_shards() gives every buffer cache shard the same limit, but collections map to shards by pg seed % shards, so the loaded shards trim on every insert while the light ones never fill: the data cache stops below its commit (574 of 816 MiB on one OSD, 85 % hit rate on a hot set that fits). With bluestore_cache_data_shard_weighted (default true) each shard keeps 1/8 of its even share and the rest is split by the bytes each shard holds. An evenly loaded OSD keeps today's split. A cache that fills its commit must not ask the autotuner for all it holds, or the commit grows at every balance out of the other caches' age bins. By age the data cache asks only for what an even split would have held, and for the rest at LAST, which is served from memory no cache claimed by age. This needs "common/PriorityCache: credit grants made at the last priority". Numbers are in the pull request. Fixes: https://tracker.ceph.com/issues/82021 Signed-off-by: Ming Lei <[email protected]>
809d4b2 to
7032f30
Compare
weighted_limits(): the even split with nothing held, the 1/8 floor, the sum within the budget, and full shards converging to the even split. even_split_fraction(): shards over their even share are capped. The commit loop: the even-split request keeps the commit at 128 MiB where asking for everything grows it to 576 MiB in ten rounds. Through PriorityCache::Manager with fake caches: a LAST request is credited, is served from unclaimed memory, and gets nothing when the other caches claim the pool by age. Signed-off-by: Ming Lei <[email protected]>
7032f30 to
7d76951
Compare
|
jenkins test make check |
|
jenkins test make check arm64 |
1 similar comment
|
jenkins test make check arm64 |
|
Could you cover this PR in your test so that finally it can be marked as TESTED? Thanks, |
Ceph PR triage — related open PRsQueried #73018 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. |
There was a problem hiding this comment.
LGTM.
Tested the shard split on a bare-metal 3-OSD cluster, where it fixes a case we hit in practice: reads served by the primary only.
Setup: 3 OSDs on NVMe, 3 replicas, 64-PG data pool, osd_memory_target 32G, CephFS kernel client, 16 jobs of 4K random reads, page cache and OSD caches dropped before each run, one run per arm. Note this is the earlier single-commit version of the shard split ("give each shard 1/8 of its even share as a floor and split the rest by the bytes it holds").
To see the shards I added a debug line after _resize_shards() that prints every buffer cache shard's held/max bytes.
Without the PR, with primary-only reads an OSD only serves the PGs it is primary for, about a third of them, so many of the 32 shards get no data at all. At the end of a 120 s O_DIRECT run:
┌───────┬──────────────┬─────────────────┬─────────────────┐
│ │ empty shards │ held / limit │ per-shard limit │
├───────┼──────────────┼─────────────────┼─────────────────┤
│ osd.0 │ 10 of 32 │ 2.99 / 4.44 GiB │ 142 MiB │
├───────┼──────────────┼─────────────────┼─────────────────┤
│ osd.1 │ 15 of 32 │ 1.73 / 3.25 GiB │ 104 MiB │
├───────┼──────────────┼─────────────────┼─────────────────┤
│ osd.2 │ 17 of 32 │ 1.35 / 2.88 GiB │ 92 MiB │
└───────┴──────────────┴─────────────────┴─────────────────┘
Every non-empty shard sits at its limit and trims on each insert, so no buffer ages into the older priority bins and the autotuner never grows the data cache: it stays at 3-4 GiB while kv and meta keep 10+ GiB each. With read_from_replica=balance every OSD serves every PG, no shard is empty and the data cache grows to 7.9 GiB in the same run; this is why balanced reads looked better than primary reads in our IO500 runs.
With the PR the empty shards drop to the floor (16-66 MiB) and the loaded ones get 300-840 MiB. Primary-only reads:
┌───────────────────────────────────────────────────────┬──────────────────────────────────┬──────────────────────────────────┐
│ │ before │ after │
├───────────────────────────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ buffered, 16 x 4 GiB, 300 s: data cache held, osd.0 │ 3.13 GiB │ 15.90 GiB │
├───────────────────────────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ IOPS │ 1034 │ 1256 (+21%) │
├───────────────────────────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ latency p50 / p90 / p99 / p99.9 / max (ms) │ 13.7 / 29.2 / 39.6 / 47.4 / 62.0 │ 11.3 / 24.8 / 35.9 / 44.8 / 77.0 │
├───────────────────────────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ O_DIRECT, 16 x 640 MiB, 120 s: data cache held, osd.0 │ 2.99 GiB │ 4.41 GiB │
├───────────────────────────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ IOPS │ 69291 │ 77685 (+12%) │
├───────────────────────────────────────────────────────┼──────────────────────────────────┼──────────────────────────────────┤
│ latency p50 / p90 / p99 / p99.9 / max (us) │ 222 / 338 / 461 / 618 / 11246 │ 194 / 326 / 444 / 569 / 10929 │
└───────────────────────────────────────────────────────┴──────────────────────────────────┴──────────────────────────────────┘
Balanced reads, where every shard is loaded, do not change, as the description says: 71362 vs 71014 IOPS, p99 416 vs 416 us, held 6.61 vs 6.60 GiB, every shard limit within 200-296 MiB.
_resize_shards()gives every buffer cache shard the same limit, but PGs map to shards bypg seed % shards, so the loaded shards trim on every insert while the light ones never fill: the data cache stops well below its commit (574 of 816 MiB on one OSD, 85 % hit rate on a hot set that fits).This PR splits the data cache budget in proportion to what each shard holds (floor 1/8 of the even share, option
bluestore_cache_data_shard_weighted, default true), and changes what the data cache asks the autotuner for: by age only the fraction an even split would have held, the rest atLAST, so the commit grows only into memory no cache claimed by age and never drains the onode or RocksDB caches.Carries the one commit of #73570 (
common/PriorityCache: credit grants made at the last priority) as its first commit, so it can merge before or after that PR; the tuner fix is needed here because without it a request served atLASTis taken from the pool but credited to no cache, the data cache would come out below the even split.Measurements
Hot-set test of the tracker: 4-OSD vstart,
osd_memory_target2 GiB,osd_memory_base256 MiB, meta/kv ratios 0.30, 128 PGs, 3 GiB hot region of an RBD image, 4K random reads, 120 s pass, two reps.2026-11-06, two reps each, same binary tree, stock vs this branch. IOPS and p99 are rep 1 / rep 2; the cache columns are from the end of rep 1 (rep 2 differs by at most 1 MiB in held and by 8 MiB in osd.0's commit, 816):
The four held values of the PR sum to 3072 MiB, the whole hot region split by primaries. The commit above held is the data cache's ratio share of memory no cache asked for, plus the 64 MiB chunk headroom; the accounting identity pool − reserve = Σ grants holds to the byte on every OSD.
The drain concern from Adam's 2026-11-03 review
Point 2 of the review: a cache whose shards fill their commit asks for more at every balance, gets it back by ratio, fills that too, and "asymptotically ... drain[s] other caches from space". This version closes the loop by construction: by age the data cache asks for what an even split would have held, the same as today, so it cannot get back more than it chipped in; only the surplus is asked at
LAST, served after every cache's binned content and only from memory nobody claimed by age.Measured where a drain would show, a pool with nothing spare (2026-11-06, this branch): 4 OSDs,
osd_memory_target1 GiB (pool 614 MiB, fully claimed by age bins in every phase), 606k 4 KiB objects under a stat storm plus 4K random reads of a sparse 4 GiB image; option on at runtime, then off; 6-minute phases, means over the last 120 s (MiB, 4 OSDs):LASTgrants (data 0–33 → 15–72, onode cache 33–58 → 13–41, content older than 12 minutes), never from an age bin.Caveat: no other cache was capacity-bound here, so there was little to lose. When one really holds more than its commit, the
LASTsplit is by ratio (0.36 against the onode cache's 0.30) and costs it part of its cold content; whether the data cache should take only unclaimed memory atLASTis open for discussion.4K random and 4M sequential writes unchanged within noise.
Tests
unittest_bluestore_types --gtest_filter='bluestore_cache_shards.*': 11 tests on the pure functions (weighted_limits,even_split_fraction) and on the request path through the realPriorityCache::Managerwith fake caches.Fixes: https://tracker.ceph.com/issues/82021
Checklist
unittest_bluestore_types,bluestore_cache_shards.*)