内存回收 - 基础
按顺序来:
- 物理内存分配,了解几种内存回收方式的触发条件和路径
- 学习几种内存回收方式的区别,node_reclaim、direct_reclaim、kswapd reclaim
- 学习内存回收机制,先看关键流程,再深入函数细节。
- scan_control
- workingset
- active/inactive 之间的平衡、file/anon 之间的平衡
- shrink_lruvec()
- shrink_active_list
- shrink_inactive_list
- shrink_slab
- reclaim throttling
- MGLRU
- 深入更底层
- writeback
- swap_cache, swap in/out
- zswap
- swap tableF
做一些总结:folio 在各个 active/inactive lru 链表之间的流转 lru,folio 的生命周期。
- 从 buddy 到 inactive
- 从 inactive promoted 到 active
- 从 active demoted 到 inactive
- 从 inactive evicted
- 从 inactive rotate 到 inactive head
挖掘演进历史 总结每个函数的作用。vmscan.c swap.c workingset.c
内存回收的触发条件、回收方式
- 内存回收的触发路径。
- get_page_from_freelist() 时的 node_reclaim(),见 page_alloc 快速路径。
- kswapd 线程的间接回收。
- 慢速路径的直接回收。
关注于 struct scan_control
LRU 演进历程
- 2014-02-04 [patch 00/10] mm: thrash detection-based file cache sizing v9
- 2020-05-20 [PATCH 00/14] mm: balance LRU lists based on relative thrashing v2 - Johannes Weiner
- 2020-06-16 [PATCH for v5.8 0/3] fix for “mm: balance LRU lists based on relative thrashing” patchset - js1304
- 2020-07-23 [PATCH v7 0/6] workingset protection/detection on the anonymous LRU list - js1304 对匿名页的 workingset 保护
- 2020-03-10 Working-set protection for anonymous pages [LWN.net]
- 原先,匿名页在 refault 时,会无条件地进入 active list head,
- 2022-09-18 [PATCH mm-unstable v15 00/14] Multi-Gen LRU Framework - Yu Zhao 引入 MGLRU
- 2023-05-18 Page aging with hardware counters [LWN.net]
其他比较小的改动
- 2009-06-08 [PATCH 0/3] make mapped executable pages the first class citizen (with test cases) - Wu Fengguang
- 2009-05-19 Being nicer to executable pages [LWN.net]
- 可执行文件页更不容易 deactivate
- 2019-11-07 [PATCH 0/3] mm: fix page aging across multiple cgroups
- 2021-01-17 Linus Torvalds feb889fb40fa mm: don't put pinned pages into the swap cache
- 不把 pinned pages 放进 swap cache