Repository navigation
Conversation
_resize_shards() gives every buffer cache shard the same limit, data_alloc / shards. Collections map to shards by pg seed modulo the shard count, so an OSD's PGs spread unevenly over them: the loaded shards trim on every insert while the light ones never fill, and the data cache stops below its committed size (574 of 816 MiB on one OSD of a 4-OSD vstart, 85 % buffer hit rate on a hot set that fits). With the new option bluestore_cache_data_shard_weighted (default true), give each shard 1/8 of its even share as a floor and split the rest in proportion to the bytes it holds, from one snapshot of the counters so the limits sum to at most the committed size. A shard at exactly its even share is a fixed point, so an evenly loaded OSD keeps today's split; false restores it. A cache that can fill its commit must not ask the autotuner for all it holds: the tuner commits held + 64 MiB, so the request would grow at every balance and take the other caches' oldest bins. By age, ask only for the fraction of the held bytes that an even split would have held; ask for the rest at LAST, which is served after every cache's binned content and only from memory nobody claimed by age. The commit grows into unclaimed memory, never into another cache's recent content. This needs "common/PriorityCache: credit grants made at the last priority" (PR ceph#73570). The split and the fraction are pure functions in BlueStore_cache_shards.h, covered by unit tests. On the tracker's hot-set test the data cache now holds the whole hot set instead of about two thirds of its commit, and disk reads during the pass all but disappear. With the pool taken by the onode and RocksDB caches of millions of small objects, switching the option on at runtime leaves those caches where they are and grows the data commit only into memory nobody claimed by age. Writes are unchanged. Numbers are in the pull request. Fixes: https://tracker.ceph.com/issues/82021 Signed-off-by: Ming Lei <[email protected]>
_resize_shards() gives every buffer cache shard the same limit, data_alloc / shards. Collections map to shards by pg seed modulo the shard count, so an OSD's PGs spread unevenly over them: the loaded shards trim on every insert while the light ones never fill, and the data cache stops below its committed size (574 of 816 MiB on one OSD of a 4-OSD vstart, 85 % buffer hit rate on a hot set that fits). With the new option bluestore_cache_data_shard_weighted (default true), give each shard 1/8 of its even share as a floor and split the rest in proportion to the bytes it holds, from one snapshot of the counters so the limits sum to at most the committed size. A shard at exactly its even share is a fixed point, so an evenly loaded OSD keeps today's split; false restores it. A cache that can fill its commit must not ask the autotuner for all it holds: the tuner commits held + 64 MiB, so the request would grow at every balance and take the other caches' oldest bins. By age, ask only for the fraction of the held bytes that an even split would have held; ask for the rest at LAST, which is served after every cache's binned content and only from memory nobody claimed by age. The commit grows into unclaimed memory, never into another cache's recent content. This needs "common/PriorityCache: credit grants made at the last priority" (PR ceph#73570). The split and the fraction are pure functions in BlueStore_cache_shards.h, covered by unit tests. On the tracker's hot-set test the data cache now holds the whole hot set instead of about two thirds of its commit, and disk reads during the pass all but disappear. With the pool taken by the onode and RocksDB caches of millions of small objects, switching the option on at runtime leaves those caches where they are and grows the data commit only into memory nobody claimed by age. Writes are unchanged. Numbers are in the pull request. Fixes: https://tracker.ceph.com/issues/82021 Signed-off-by: Ming Lei <[email protected]>
dvanders
left a comment
There was a problem hiding this comment.
The fix is right. The loop's grant at LAST is subtracted from mem_avail and then overwritten by set_cache_bytes(), and with the pool already at max_mem the tuner has no way to give it back. I checked the other PriCache users: the mon's OSDMap caches only ask at PRI1, and rbd-mirror asks at PRI10 with a ratio of 0, so the fair_share > 0 guard covers its assert.
I built the gtest from the tracker on this branch: 4/4 pass; with the parent's PriorityCache.cc the two LAST cases fail; with the fix but without the fair_share > 0 guard the zero-ratio case fails. So both halves of the change are covered.
Requests:
- Please add that gtest as a second commit. There is no PriorityCache unit test in the tree today. It needs
$<TARGET_OBJECTS:common_prioritycache_obj>in the executable andglobal heap_profilerto link. - Please set the Backport field on the tracker (umbrella, tentacle, squid).
- Consider a PendingReleaseNotes line: OSDs holding cache content older than the last age bin will now use that memory, so their RSS moves closer to
osd_memory_targetafter the upgrade.
Nit: the commit message says the OSD mapped 1744 MiB and the PR text says 1745.
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 1745 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]>
Drive PriorityCache::Manager with fake caches and check that the pool is handed out in full, that a request served at the last priority stays with the cache once the ratio split has run, that two caches asking for more than is left at the last priority share it by ratio, and that a cache with a ratio of 0 is not handed a zero-byte share it would assert on (as rbd-mirror's does). The second and third fail without the previous commit. Signed-off-by: Ming Lei <[email protected]>
7b0e827 to
fca2224
Compare
|
Thanks for the review, and for checking the other
|
|
Thanks Igor and Dan's review! |
|
This PR has been added to wip-bharath29-testing-20261121.045602-main. |
There was a problem hiding this comment.
(1) I believe that this block should be executed only when pri != LAST.
There was a problem hiding this comment.
(1) I believe that this block should be executed only when
pri != LAST.
(2) That would make the change fromset_cache_bytestoadd_cache_bytesfully redundant.
That also stops the loss, but it drops the requests at LAST, and I think keeping them fits the current code better:
- The loop already runs at
LASTtoday, and since Cache Age Binning (56351838337) the BlueStore caches and the RocksDB block cache each have aLASTcase inrequest_cache_bytes(), asking for content older than the last age bin. With the loop skipped, those cases are never called.
Example. 600 MiB left at LAST, ratios 0.30 / 0.40 / 0.30:
| MiB | onode | data | RocksDB |
|---|---|---|---|
| asks for | 400 | 50 | 50 |
loop skipped at LAST |
180 | 240 | 180 |
| this PR | 400 + 30 | 50 + 40 | 50 + 30 |
With the loop skipped, the onode cache has to evict 220 MiB while the data cache gets 190 MiB it did not ask for. The two differ only in this case, where one cache wants more than its ratio share and another wants less; under contention the loop hands out by ratio as well.
Measurement. 4-OSD vstart, osd_memory_target 2 GiB, 700k 4 KiB objects, random reads, one run each:
| per OSD | main | loop skipped at LAST |
this PR |
|---|---|---|---|
| lost from the pool | 193–241 MiB | 0 | 0 |
| onode cache committed | 312–336 MiB | 376–400 MiB | 592–696 MiB |
| onode hit rate | 86.9–91.4 % | 88.8–92.8 % | 95.1–96.8 % |
| onode misses, 6 min, all OSDs | 92,203 | 78,405 | 34,580 |
| data cache committed / used | 408–464 / 108–238 MiB | 496–576 / 129–297 MiB | 328–408 / 98–213 MiB |
Small objects favour the onode cache, so this is the good case for the PR.
So I would keep granting the requests at LAST as at the other priorities, and split by ratio only what nobody asked for.
There was a problem hiding this comment.
I think this part of the discussion should wait for acceptance on design/documentation of PriorityCache.
In this specific case I have in mind my claim (as a documentation creator of code I did not design nor wrote) that:
"The LAST means that the cache is using the memory, but it does not affect its performance."
From:
https://github.com/ceph/ceph/pull/74359/changes#diff-4280052187eed37ef193fd7e299e7ca3956f3e45385698e31c4f19a07ffecf44R54
There was a problem hiding this comment.
But this PR follows the current code base's implementation. If you think the current implementation is wrong
wrt. LAST, please send a fix.
PR # 74359 is not a design of PriorityCache at all, which is retrieved from current code. Design doc is supposed for guiding implementation.
So I don't buy your point, sorry.
| it->second->set_cache_bytes(Priority::LAST, fair_share); | ||
| total_assigned += fair_share; | ||
| if (fair_share > 0) { | ||
| it->second->add_cache_bytes(Priority::LAST, fair_share); |
There was a problem hiding this comment.
(2) That would make the change from set_cache_bytes to add_cache_bytes fully redundant.
|
jenkins test windows |
|
Please note the following: |
Can you share anything this PR violates the above? |
balance_priority()grants each cache's request atPriority::LASTwithadd_cache_bytes(), then splits the remainder by ratio withset_cache_bytes(LAST, share), which overwrites the grant. The bytes left the pool, but no cache is committed them. BlueStore's caches ask atLASTfor content older than their last age bin (720 s), so the grant is lost on every balance and the OSD runs belowosd_memory_target: 170 to 270 MiB of a 1484 MiB pool with 2 M small objects, about 1 % on a small hot set.The fix adds the share on top of the grant, and skips a zero share because rbd-mirror's
PriCache::add_cache_bytes()asserts at a priority it did not ask at. With nothing asked atLASTthe result is byte-identical to today; the ratios still split only the memory nobody asked for.4-OSD vstart, 2 GiB target, same load (osd.1): onode cache commit 368 -> 792 MiB, 371k -> 510k onodes, 93 -> 99 % hit rate, OSD mapped 1546 -> 1745 MiB of 2048. The RocksDB block cache goes 288 -> 184 MiB because it loses its 24 MiB share of the unspent memory and asks for less; its request was granted in full in both runs.
Harmful since Cache Age Binning (
56351838337, v17.1.0) made the caches ask atLAST. The second commit adds a gtest driving the realManager::balance()with fake caches: four cases, two fail without the fix and the zero-ratio case fails without thefair_share > 0guard.PendingReleaseNotes: OSDs holding cache content older than the last age bin now use that memory, so their RSS moves closer to
osd_memory_targetafter the upgrade.Fixes: https://tracker.ceph.com/issues/82836
Checklist