Slab Reassignment vs. Manual Growth Factor Tuning for Eviction Control
0 reputation · 05 Jun 2021, 13:22 UTC
0 reputation · 05 Jun 2021, 13:22 UTC
Memcached manages memory through a Slab Allocator to prevent fragmentation, grouping items of similar sizes into specific slabs. When a slab reaches capacity, the system triggers LRU eviction for that specific slab, regardless of whether memory is available in other slabs.
To mitigate premature evictions and improve hit rates, two primary strategies exist: enabling slab_reassign to dynamically shift memory from underutilized slabs, or manually tuning the growth factor to adjust how slab sizes scale.
The trade-off involves balancing the overhead of dynamic memory migration against the risk of internal fragmentation caused by static, oversized slabs.
Which approach is more effective for workloads with highly volatile object sizes to minimize eviction noise? Under what specific memory pressure conditions does slab_reassign become less efficient than a tuned growth factor?
30775 reputation · 05 Jun 2021, 22:48 UTC
For workloads with highly volatile object sizes, slab_reassign (together with slab_automove) is generally the more effective strategy. Growth factor tuning only pays off when you can predict the item-size distribution — and volatility is precisely the condition where that prediction fails. A static layout tuned for yesterday's traffic becomes the wrong layout when the distribution shifts, and Memcached cannot retune the growth factor on a live daemon; -f applies only at startup to an empty cache.
Memcached's slab allocator gives each slab class its own LRU. When one class fills, it evicts its own items even while other classes sit on free pages — the classic "premature eviction" pattern where overall memory usage is low but one class churns. Slab reassignment attacks exactly this: the daemon moves whole 1MB pages from classes with reclaimable capacity to classes under eviction pressure. When object sizes swing unpredictably, this dynamic redistribution is the only mechanism that can follow the workload, because no fixed class geometry fits a moving target.
Reassignment is not free, and there are two specific pressure conditions where it underperforms a statically tuned layout:
Reassignment also cannot fix fragmentation within a page, and it moves pages in 1MB units, so it is a coarse instrument.
First verify you actually have slab imbalance rather than simple memory exhaustion. The signature is high evictions in one or two classes while others show free chunks:
stats slabs
stats items
stats settingsCompare evicted per class against used_chunks and free pages. If evictions track total memory pressure evenly, neither tuning strategy helps — you need more RAM or smaller items. Also confirm via stats settings which slab_reassign, slab_automove, and factor values the running daemon actually has; these behaviors are version-sensitive, and older automove algorithms had known misbehavior, so check your Memcached version's release notes before enabling it in production.
slab_reassign/slab_automove on a staging instance, replay representative traffic, and compare evictions and hit ratio against your baseline.-f to match it, restart with a warm-up plan, and you avoid migration overhead entirely.One caveat worth noting: modern Memcached (1.5+) includes the segmented LRU and lru_maintainer, which reduce eviction noise independently of slab layout. If you are on an older build, upgrading may shrink the problem before you touch either knob. The one diagnostic detail that would change this recommendation is your per-class eviction breakdown from stats slabs — if pressure is uniform, skip reassignment entirely.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.