Repository navigation
Description
Measured on Linux (Azure D16s_v5, glibc) against 1.2.0-rc3 (c0f49b0) and 1.1.3, following Parikalp Bhardwaj's review in #221 (findings 2 and 5). Not a regression after churn: rc3's RSS after delete/refill churn is the same as or lower than 1.1.3's in every shape measured (100 B values 23-40% lower, 1 KB 0-28% lower, mixed 100 B-16 KB within ±3%). Three things to improve after 1.2.0:
1. Waste in full slabs after light churn (efficiency). At 10-20% churn, RSS settles 13-16% above load (100 B: 158 -> 183 MB, of which 24 MB is free blocks in slabs that are 75-100% live; 1 KB: about 150 MB of 1.2 GB). It doesn't grow past cycle 2. Without maxmemory, a slab is reused only when a quarter of it is free (#208 lowered that only near the limit), and active defrag can't help: plan_evacuation only takes slabs from the partial lists, never a FULL one, and the waste stays under the default trigger (64 MB / 20%). Proposed: let defrag evacuate the sparsest FULL slabs (FULL -> EVACUATING under the class lock), and trigger on slab waste itself (e.g. > 10% of slab bytes and > 16 MB). The hot path and the 1/4 rule stay as they are (they exist to avoid lock ping-pong on small overwrites).
2. Active defrag (on by default) briefly raises RSS during churn. With 1 KB values, a delete phase pushes waste over 20%, defrag starts, the slabs it evacuates leave the lists, and the refill takes fresh slabs: peak RSS up to +26% over load (rc3 defaults 1308-1339 MB vs 1191-1207 with defrag off at 10-20% churn), settling within a cycle or two. Peaks stay below 1.1.3's except one sample (+3%). Smaller evacuation sets and not starting while a large delete is being refilled would cut it.
3. Values near 4 KiB (small regression vs 1.1.3).
- Memory: values of about 3830-4020 B use up to +202 B per key (+5.2%) more RSS than 1.1.3: their class fits only 16 blocks in a 64 KiB slab and leaves an unused tail (e.g. a 3832 B value goes in the 3904 class, 3072 B left per slab).
used_memorydoesn't show it. Smaller tails exist in other classes above 2 KB. - Throughput: above 4088 B (8 B header + value no longer fits the largest slab block, MAX_BLOCK) values go to the system allocator: SET at pipeline 16 drops about 17% across the boundary and is about 8% below 1.1.3 above it (p99 0.93 -> 1.2 ms). Below it rc3 is 5-10% faster than 1.1.3. GET unchanged.
- Directions: class sizes of 65536/k above 2 KB, or larger slabs for the big classes; raising MAX_BLOCK past 4 KiB would also help mixed-size workloads (values above 4 KiB live in glibc today, where Redis/jemalloc keeps fragmentation at 2-4%).
Evidence and scripts are kept with the measurement (churn.py, run_churn.sh, spike.sh, run_f5.sh).
Activity
Parikalp-Bhardwaj commentedon Nov 1, 2026
Hi @murtazayusuf, I have been looking into #240, particularly the slab reuse issue under delete/refill workloads.
I would like to investigate whether we can improve memory reuse through a bounded defragmentation path, without adding contention to the allocation fast path.
I will start by reviewing the existing slab and compaction logic and comparing a few approaches against the Linux benchmark results.
Are you already working on an implementation for this, or would this be a useful area for me to take on?
murtazayusuf commentedon Nov 1, 2026
Thanks @Parikalp-Bhardwaj, nobody is on it: it's yours. It lands after 1.2.0 (we're in the release-candidate phase), so there's time to measure properly.
What we'd look for:
listableexists because relisting slabs eagerly cost a lot of lock traffic for small overwrites on many threads (7.4M -> 1.8M ops/s when we tried a lower threshold). The direction in the issue is to let active defrag evacuate the sparsest FULL slabs (FULL -> EVACUATING under the class lock;free,settleandfinish_evacuationalready handle EVACUATING), and to trigger on slab waste itself rather than the 64 MB / 20% default. If you find a better design, great: measure it against that one.scripts/perf/run.shinstruction counts for GET/SET within 1%; the eviction-quality andmaxmemorybehaviour from maxmemory bounds what the process uses; a command's keys are found through a table #208/Eviction: every key as likely to be sampled, and the runners-up looked at again #212 unchanged.The churn driver we used: 8 processes sending pipelined raw RESP, 16 B keys, each cycle deleting a random X% of live keys then inserting X% new ones, VmRSS and INFO sampled ~2 s after each cycle. Happy to review a design note before you write much code.
Parikalp-Bhardwaj commentedon Nov 1, 2026
Thanks @murtazayusuf, I'll take this on.
Thanks for the detailed guidance!
Parikalp-Bhardwaj commentedon Nov 1, 2026
Hi @murtazayusuf,
I have completed the initial design investigation and drafted a design note. No implementation changes yet.
The proposed approach follows your FULL → EVACUATING direction:
alloc,free,take,let_go, and the existing 1/4-free rule unchanged.One concern came up during the analysis, moving live entries requires destination capacity before source slabs can be released, so reducing steady-state RSS without increasing peak RSS may be difficult under sustained churn.
Before implementing, I would appreciate clarification on three points:
I will refine the design based on your feedback and share it for review before making code changes.
Parikalp-Bhardwaj commentedon Nov 1, 2026
Hi @murtazayusuf, I have made some progress on #240 and completed another round of Linux experiments.
A few findings:
These results are from Linux/aarch64 in Docker Desktop, so I haven't treated them as final performance numbers.
I'm planning to separate the work into a small compaction-pacing change first, followed by the resident-hole allocator and its concurrency tests.
Would you prefer the pacing improvement as a separate PR, or as part of the eventual #240 change? I can share the design note before implementing the allocator changes.
murtazayusuf commentedon Nov 1, 2026
Thanks @Parikalp-Bhardwaj, and sorry for the slow reply to your 06:10 questions. The pacing find is a good one.
Your three questions:
Pacing: please make it a separate small PR first. It's easy to review and measure on its own, and it helps whatever comes next. One condition: merging the sleeps must keep the same CPU share (the 10% cap). Fewer, longer sleeps shouldn't turn into bursts that show up as latency. For that PR, please show p99/p99.9 of a memtier SET/GET load running during a defrag pass, before and after, besides the wall time.
Resident holes: this sounds promising, and it avoids fresh destination slabs, which is the peak-RSS problem you named. It does sit closer to the allocation path, though, so a design note first, please. The note should cover:
scripts/perf/run.shinstruction counts for GET/SET look like.Numbers: Docker Desktop on aarch64 is fine for direction. For the gate numbers we'll run your branch on a native Linux VM on our side when it's ready, so you don't need the hardware.
All of this lands after 1.2.0.
Parikalp-Bhardwaj commentedon Nov 1, 2026
Okay @murtazayusuf, I will start with the compaction pacing fix as a separate small PR.
Parikalp-Bhardwaj commentedon Nov 2, 2026
Hi @murtazayusuf, I've opened a draft PR for the M1 compaction pacing change.
It reduces the number of sleeps during background defrag while keeping the existing CPU-share calculation. I've also added tests, and the local checks are passing.
The compaction-speed results look promising, but I'm leaving it as a draft because my local A/B tests showed a possible GET/SET tail-latency regression. The Docker environment was too noisy to confirm the cause.
I've prepared a reproducible native-Linux benchmark setup to validate the change before merging.
This is limited to pacing; the allocator changes remain separate.
murtazayusuf commentedon Nov 2, 2026
Thanks, @Parikalp-Bhardwaj. Keeping #291 to the pacing alone, and as a draft until the tail latency is understood, is the right call.
I've left review notes on #291. In short: the latency you saw is most likely the defrag thread taking a shard's lock again right after letting it go, now that it runs batches back to back for up to a millisecond;
unlock_fairat the end of a batch should hand it to a waiting client. The CI failure there wasn't from your change: it was a race inhset_beside_the_field_expiry_sweep_keeps_the_new_field, now fixed on the release branch, with credit to you for spotting it.For the native-Linux A/B, measure
GET/SETp99 and p99.9 during a pass, with and without the change. If you don't have quiet hardware for it, say so and we'll run it on an Azure VM.Parikalp-Bhardwaj commentedon Nov 2, 2026
Thanks @murtazayusuf , that makes sense. I'll look into the targeted
unlock_fairchange at the end of compaction batches and update #291.I don't have a quiet native-Linux machine available, so the Azure VM would be helpful for the final A/B latency comparison. I will keep the PR in draft until we have those results.
murtazayusuf commentedon Nov 2, 2026
Sounds good, @Parikalp-Bhardwaj. Push the
unlock_fairchange to #291 when it's ready, and we'll run the A/B on an Azure VM:GET/SETp50/p99/p99.9 during a defrag pass, master against your branch, alternating runs on the same machines. We'll post the numbers and the harness on the PR. It will be once 1.2.0 is out, since the release is taking the machines today.23 remaining items
murtazayusuf commentedon Nov 21, 2026
#990 is merged: points 1 and 2 of this issue.
Left open for point 3, values near 4 KiB: a 3,832 B value costs 4,120 B of RSS per key (3,885 B at 3,800 B), and SET goes from 800k/s at 4,088 B to 681k/s at 4,100 B. A prototype with 128 KiB slabs brought the 3,832 to 3,900 B values to 3,998 B per key and left the boundary where it is, so the next step is larger slabs for the classes above 2 KiB together with a higher block limit.
Active defrag empties sparse full slabs, from a class-protected list …
Settings and INFO fields for the slab-waste trigger, stress and model…
Slab regions carved out of growing reservations of address space, no …
Tests of the in-place SET under compaction, evacuation, holds, a repl…
Suite 46 recorded again at 7fe6535, with one RSS a group held to its …
Slab callers go through alloc and free, whatever the class: 10 % fast…
Suite 46 recorded again and suite 43 run at eca5923, both ok (#240 re…
Merge pull request #1000 from kividbio/perf/slab-large-classes-240
Values of 2 KiB to 26 KB in 1 MiB slabs, classes at most 2.5 % apart;…
Large slabs: used again once a sixteenth is free, and a thread takes …
A SET over a string of its own writes its block in place while nothin…
Large classes: 4,096 bytes among them (kividbio#240)
Suite 46 recorded on a D8s_v5 (kividbio#240); CHANGELOG and configura…