cachelib: skip reaper traversal for empty caches - #485
Open
SimBuddy wants to merge 1 commit into
Open
Conversation
Assigned allocation slots can remain after all accessible primary items have been removed. Use the existing primary-item count to skip the current reaper slab walk when that count is zero, without adding state or writer work. Periodic wakeups and nonempty traversal are unchanged. A concurrent insertion may be handled on a later pass, consistent with the existing weak traversal semantics; lookup expiration and synchronized ownership checks are unchanged. Add registered tests for empty allocations, reactivation, pinned expired parents with chained items, live retention and concurrent slab traversal.
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.
Summary
The reaper can continue scanning assigned allocation slots after all accessible primary items have been removed. Use the existing primary-item count to skip that periodic slab walk when the cache is empty. Nonempty traversal and periodic wakeups are unchanged.
Why
Assigned slabs can remain after the accessible population reaches zero, but walking those slots cannot find an accessible item to expire. The existing atomic count supplies the signal without another flag, lock, or per-item update.
Concurrency
The count observation can race with insertion/publication. A concurrently inserted item may be handled on a subsequent periodic pass, consistent with the existing weak slab traversal. Foreground expiration checks and synchronized removal/ownership behavior are unchanged.
Performance
In a local default-style idle workload (64 MiB configured cache, approximately 16 MiB assigned slots, 5-second reaper interval, 12-second window):
This saves about 5 ms CPU over the 12-second idle window. It measures idle/background reaper work, not foreground cache throughput; the process CPU measurement includes other process bookkeeping. Absolute savings are modest and depend on assigned slab population, reaper frequency and hardware. A concise confirmation on the final rebased source verified zero empty-cache visits, active nonempty traversal and reactivation.
Testing
python3 build/fbcode_builder/getdeps.py --allow-system-packages --scratch-path /root/wob3/getdeps --num-jobs 4 build cachelib --src-dir /root/wob3/CacheLib --build-type RelWithDebInfopython3 build/fbcode_builder/getdeps.py --allow-system-packages --scratch-path /root/wob3/getdeps --num-jobs 2 test cachelib --src-dir /root/wob3/CacheLib --build-type RelWithDebInfo --no-testpilot --timeout 300 --retry 0(private ext4 /tmp and DAC-bypass capabilities removed for filesystem/permission tests).clang-format-21 --dry-run --Werror cachelib/allocator/CacheAllocator.h cachelib/allocator/tests/ReaperTest.cppgit diff --check upstream/main...HEADScope
No cache or eviction policy changes, new persistent state, or NVM changes. No foreground hit/miss behavior change is intended. Numerical CPU results are workload and hardware dependent.
The opportunities were identified and validated using WOB/WOB3 techniques.
WOB is an experimental method of refocussing workloads in data-heavy code. I am stress testing various codebases, to develop the method further, and cachelib seemed like a worthwhile candidate. This single result was a small win, so I am sharing. Feedback would be greatly appreciated.
WOB is human-designed, human-led, and machine assisted.