Blame doc/new_lru.txt

Packit 4e8bc4
In versions new enough to have the `-o lru_maintainer` option, a new LRU
Packit 4e8bc4
mechanic is available.
Packit 4e8bc4
Packit 4e8bc4
Previously: Each slab class has an independent doubly-linked list comprising
Packit 4e8bc4
its LRU. Items are pulled from the bottom and either reclaimed or evicted as
Packit 4e8bc4
needed.
Packit 4e8bc4
Packit 4e8bc4
Now, enabling `-o lru_maintainer` changes all of the behavior below:
Packit 4e8bc4
Packit 4e8bc4
 * LRU's are now split between HOT, WARM, and COLD LRU's. New items enter the
Packit 4e8bc4
   HOT LRU.
Packit 4e8bc4
 * Items hit at least twice are considered active.
Packit 4e8bc4
 * LRU updates only happen as items reach the bottom of an LRU. If active in
Packit 4e8bc4
   HOT, move to WARM, if active in WARM, stay in WARM. If active in COLD, move
Packit 4e8bc4
   to WARM.
Packit 4e8bc4
   The exception is that items active in COLD are immediately moved to WARM.
Packit 4e8bc4
 * HOT/WARM each capped at N% of memory available for that slab class. COLD
Packit 4e8bc4
   is uncapped (by default, as of this writing).
Packit 4e8bc4
 * HOT/WARM are also age capped by ratios of COLD's age. IE: HOT is capped at
Packit 4e8bc4
   N% of memory, or 10% of the age of COLD, whichever comes first.
Packit 4e8bc4
 * Items flow from HOT/WARM into COLD.
Packit 4e8bc4
 * A background thread exists which shuffles items between/within the LRU's as
Packit 4e8bc4
   limits are reached. This includes moves from COLD to WARM.
Packit 4e8bc4
 * The background thread can also control the lru_crawler, if enabled.
Packit 4e8bc4
Packit 4e8bc4
The primary goal is to better protect active items from "scanning". Items
Packit 4e8bc4
which are never hit again will flow from HOT, through COLD, and out the
Packit 4e8bc4
bottom. Items occasionally active (reaching COLD, but being hit before
Packit 4e8bc4
eviction), move to WARM. There they can stay relatively protected.
Packit 4e8bc4
Packit 4e8bc4
A secondary goal is to improve latency. The LRU locks are no longer used on
Packit 4e8bc4
most item reads, largely during sets and from the background thread. Also the
Packit 4e8bc4
background thread is likely to find expired items and release them back to the
Packit 4e8bc4
slab class asynchronously, which speeds up new allocations.
Packit 4e8bc4
Packit 4e8bc4
It is recommended to use this feature with the lru crawler as well:
Packit 4e8bc4
`memcached -o lru_maintainer,lru_crawler` - Then it will automatically scan
Packit 4e8bc4
slab classes for items with expired TTL's. If your items are always set to
Packit 4e8bc4
never expire, you can omit this option safely.
Packit 4e8bc4
Packit 4e8bc4
An extra option: `-o temporary_ttl=N` (when used with lru_maintainer) will make
Packit 4e8bc4
items with a TTL less than or equal to this value use a fourth TEMP LRU. Items
Packit 4e8bc4
stored in TEMP are never bumped within its LRU or moved to other LRU's. They
Packit 4e8bc4
also cannot be evicted. This can help reduce holes and load on the LRU crawler.
Packit 4e8bc4
Packit 4e8bc4
Do not set temporary_ttl too high or memory could become exhausted.