[seekdb][alloc] Optimize chunk cache idle eviction#925
Open
hnwyllmm wants to merge 1 commit into
Open
Conversation
Member
Author
|
The mapping Dima issue is about optimizing the chunk reserved cache size. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task Description
This change aims to address the trade-off between memory usage and performance when using
memory_chunk_cache_size. Setting it to0Mkeeps the AChunkMgr cache unlimited, which maintains good sysbench performance but can lead to high idle memory after a workload. Setting it to a small value (e.g.,2M) bounds the cache but causes a sharp performance drop. The goal is to retain useful chunk cache during active workloads while opportunistically releasing idle cached chunks after they have not been reused for a period, without introducing new timer threads or configuration items.Solution Description
This MR implements an opportunistic idle eviction mechanism within AChunkMgr:
AChunk::cache_ts_to record the timestamp when a chunk enters the AChunkMgr cache.AChunkList::pop_expiredto remove one expired cached chunk from a slot.AChunkMgr::free_chunk, after caching the returned chunk as usual, the method attempts to evict one expired chunk from a normal slot.CACHE_EXPIRE_US) and a rotating cursor over normal slots for eviction attempts.evicting_to prevent concurrent eviction scans.expired_unmaps_to the chunk manager's diagnostic dump output.This branch also includes a change in
context.hthat forcesuse_pm=falsewhen creating anObAllocator. Test data indicates this change slightly improves QPS in one run but significantly increases RSS. This specific change requires careful review.Passed Regressions
./build_release/deps/oblib/unittest/lib/test_chunk_mgr- All 10 tests passed.cmake --build build_release --target seekdb -j 8- Passed.242683f,memory_chunk_cache_size=0M): QPS/TPS: 77,062.28/s, avg latency: 0.21 ms, p95 latency: 0.55 ms, errors: 0.87fd9fb,memory_chunk_cache_size=0M): QPS/TPS: 105,154.90/s, errors: 0.context.h use_pm=false: QPS/TPS: 138,616.99/s, avg latency: 0.11 ms, p95 latency: 0.17 ms, errors: 0.use_pm=false(only idle eviction): QPS/TPS: 133,008.36/s, avg latency: 0.12 ms, p95 latency: 0.18 ms, errors: 0.Upgrade Compatibility
context.h use_pm=falsechange can broadly affect memory behavior and requires careful review.Other Information
MR Commit: Contains a single commit:
87fd9fbfde0 Optimize chunk cache idle evictionChanged Files:
deps/oblib/src/lib/alloc/alloc_struct.hdeps/oblib/src/lib/rc/context.hdeps/oblib/src/lib/resource/achunk_mgr.cppdeps/oblib/src/lib/resource/achunk_mgr.hdeps/oblib/unittest/lib/alloc/test_chunk_mgr.cppConclusion from Tests: The optimization's effect is currently limited. Observations show very few fully-free chunks in the AChunkMgr freelists. Even if all cached fully-free chunks were released, the recoverable upper bound was only about 20-30 MB in the observed idle state. Most RSS is likely held by non-empty chunks, live objects, fragmentation inside ObjectSet/BlockSet, or other contexts/modules, which AChunkMgr-only eviction cannot reclaim.
Release Note
Optimizes AChunkMgr to opportunistically evict idle cached memory chunks after a fixed period (30 seconds) without requiring new configuration or timer threads. This aims to reduce persistent idle memory after workloads while maintaining performance. Includes a diagnostic addition (
expired_unmaps_to chunk mgr dump). Note: A related change incontext.hforcesuse_pm=falseforObAllocator, which may impact memory usage and requires review.