Repository navigation
Conversation
SLRU_parse_params() rounds each seg-size segment down on its own, so the segments add up to less than the cache unless the cache size divides evenly. 1a1a11a#343 fixed this for the default layout but kept explicit seg-size layouts as they were. With W-TinyLFU's seg-size=1:4 main cache this is one object short unless the main size is a multiple of 5. Once every segment is full, a hit in probation evicts inside find(), and W-TinyLFU then admits its next window victim without the frequency check. Call SLRU_resize() after parsing, which gives the remainder to the last segment. The seg-size=1:2:3:4 print in test_cli.sh changes from 9:19:29:39 to 9:19:29:40.
marcft
force-pushed
the
fix/slru-seg-size-remainder
branch
from
November 13, 2026 20:01
7a95ce2 to
2a04d23
Compare
SLRU_cool() moved obj_size between segments while promote, insert and evict moved obj_size + obj_md_size, so with --consider-obj-metadata each promote-then-demote left the metadata on the upper segment's count. When no segment had room, SLRU_insert() evicted until the whole cache fit, which could push the lowest segment past its share when objects differ in size; it now evicts until that segment fits too. The cache name and -e print now show the shares asked for (seg_ratio) instead of the byte limits, so seg-size=1:1 is S2LRU(50:50) at every cache size and seg-size=1:2:3:4 prints 10:20:30:40. Count mode (--ignore-obj-size=1) is unchanged.
In byte mode the main cache evicts whole objects, so it can sit a little below its size. A window victim that fit that space was admitted without the frequency check, even long after the main cache had filled. Remember that the main cache has filled, and compare from then on; the hill climber clears this when it grows the main cache. A winning window victim larger than the main victim now evicts until it fits. Two tests push a cold object out of the window into a full main cache with free space: from SLRU segments that did not add up (count mode; fails on develop 4e3521a) and from evicting whole objects (byte mode; fails without this fix). Count mode (--ignore-obj-size=1) is unchanged.
-e print exits from SLRU_parse_params() without freeing the cache. LeakSanitizer stayed quiet only while the cache pointer was still live in the print call; since the label change no longer passes it, the Ubuntu job reports the whole cache as leaked. Free it before exiting. The cache name loops now stop once the name fills the buffer, as the -e print loop already does.
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.
Hi, while working on 1a1a11a#385 I kept seeing weird spikes in the fixed-window W-TinyLFU curves, and the reason I gave for them in that PR was wrong.
The reason was SLRU rounds both segment down, so W-TinyLFU's main ends up one slot short (unless its size is a multiple of 5). W-TinyLFU sees the free slot and puts the next object without checking the sketch. For example in some few traces, more than half the objects just skipped the sketch check at all. The spikes were the few sizes where the bug doesn't happen.
And this is the plot twist, the bug often actually helps. Fixing it makes default W-TinyLFU worse in 50 of the 76 cells from 1a1a11a#385. On cluster26 at the smallest size the miss ratio goes from about 0.26 to 0.47.
I give you here the AI summary ⬇️
What does this PR do?
SLRU_parse_params()rounds eachseg-sizesegment down on its own, so the segments can add up to less than the cache.seg-size=1:4, so a main of 1,001 objects gets 200 + 800 = 1,000 slots. Once both segments are full, every promotion out of probation evicts insidefind(). W-TinyLFU's next miss sees the free slot and admits the window victim without the frequency check. On a typical trace from feat(WTinyLFU): adapt the window size with a hill climber 1a1a11a/libCacheSim#385 (median of 26, smallest size), 22% of admissions into main skip the check.SLRU_resize(cache, cache->cache_size)after parsing. It already gives the remainder to the last segment, so parsing and resizing now share one rule. Add Merlin eviction algorithm and fix capacity remainders in SR-LRU and SLRU 1a1a11a/libCacheSim#343 fixed the same rounding for the default layout; this covers explicitseg-size.SLRU_resize(), so it never leaked, while most fixed-window baselines did.seg-sizethat doesn't divide the cache (seg-size=1:2:3:4on 1 GB:9:19:29:39becomes9:19:29:40).Type of change
How was it tested?
New unit test
test_SLRU_seg_size_fills_cache: fails on develop (5 == 6), passes with the fix.test/test_cli.sh: 428 passed, 0 failed.ctest --test-dir _build --output-on-failurepasses (16/16)Build is warning-free (CI uses
-Wall -Wextra -Werror)Results
All runs:
--ignore-obj-size=1 --num-thread=1, Release.The leak is gone.
At 1223 this PR matches develop with the segments forced to add up exactly, and sizes that were already exact are untouched (13/13 in 1a1a11a#385). Over 208 cells on cluster26 and alibabaBlock_117, the spikes are exactly the cells with main % 5 == 0.
Effect on the 76 cells of 1a1a11a#385 (miss ratio, pp; "same" = within 0.05 pp; negative = first one better):
Not tested: byte mode with variable object sizes, where SLRU may still overfill probation.
Checklist
clang-format(or the pre-commit hook fromscripts/setup_hooks.sh)