Multigenerational LRU¶
Quick start¶
Build configurations¶
- Required
Set
CONFIG_LRU_GEN=y
.- Optional
Set
CONFIG_LRU_GEN_ENABLED=y
to enable this feature by default.
Runtime configurations¶
- Required
Write
1
to/sys/kernel/mm/lru_gen/enable
if the feature wasn’t enabled by default.
Recipes¶
Personal computers¶
- Thrashing prevention
Write
N
to/sys/kernel/mm/lru_gen/min_ttl_ms
to prevent the working set ofN
milliseconds from getting evicted. The OOM killer is invoked if this working set can’t be kept in memory. Based on the average human detectable lag (~100ms),N=1000
usually eliminates intolerable lags due to thrashing. Larger values likeN=3000
make lags less noticeable at the cost of more OOM kills.
Data centers¶
- Optional
Change
CONFIG_NR_LRU_GENS
to a larger value to support more generations forWorking set estimation
andProactive reclaim
.- Optional
Change
CONFIG_TIERS_PER_GEN
to a larger value to support more tiers, which generally provide better protection for page cache when under heavy buffered I/O workloads.- Optional
Set
CONFIG_LRU_GEN_STATS=y
to enable full stats for debugging. SeeDebugfs interface
.- Debugfs interface
/sys/kernel/debug/lru_gen
has the following format:memcg memcg_id memcg_path node node_id min_gen birth_time anon_size file_size ... max_gen birth_time anon_size file_size
min_gen
is the oldest generation number andmax_gen
is the youngest generation number.birth_time
is in milliseconds.anon_size
andfile_size
are in pages.This file also accepts commands in the following subsections. Multiple command lines are supported, so does concatenation with delimiters
,
and;
./sys/kernel/debug/lru_gen_full
contains additional stats for debugging.- Working set estimation
Write
+ memcg_id node_id max_gen [can_swap [full_scan]]
to/sys/kernel/debug/lru_gen
to trigger the aging. It scans PTEs for accessed pages and promotes them to the youngest generationmax_gen
. Then it creates a new generationmax_gen+1
. Setcan_swap
to 1 to scan for accessed anon pages when swap is off. Setfull_scan
to 0 to reduce the overhead as well as the coverage when scanning PTEs.- Proactive reclaim
Write
- memcg_id node_id min_gen [swappiness [nr_to_reclaim]]
to/sys/kernel/debug/lru_gen
to trigger the eviction. It evicts generations less than or equal tomin_gen
.min_gen
should be less thanmax_gen-1
asmax_gen
andmax_gen-1
aren’t fully aged and therefore can’t be evicted. Usenr_to_reclaim
to limit the number of pages to evict.