page reclaim 04:参数
未开启CONFIGMEMCG, CONFIGSWAP.
1. scan_control
linux-3.10.86/mm/vmscan.c
struct scan_control {
/* Incremented by the number of inactive pages that were scanned */
unsigned long nr_scanned;
/* How many pages shrink_list() should reclaim
问题:nr_to_reclaim和nr_scanned的关系?
答:nr_to_reclaim是个setting data, nr_reclaimed是runtime date.
通常是先给struct scan_control sc设置好这个目标,
然后启动回收.
在 sum of shrink_list() > nr_to_reclaim后中断回收, see shrink_lruvec() or do_try_to_free_pages().
*/
unsigned long nr_to_reclaim;
/*
这里的may类似may I ..., may的意思是 是否可以, 是否允许
*/
int may_writepage;
/*
[Understanding the Linux Kernel, 3rd Edition]p695
Lower priority implies scanning more pages.
*/
int priority;
};
get_scan_count
{
size = get_lru_size(lruvec, lru);
scan = size >> sc->priority;
//扫描的量 与 list的大小 成比例
}
shrink_lruvec
|--//1. 根据优先级等 给数组nr[]赋值
|--get_scan_count(lruvec, sc, nr);
2. watermark
2.1 low watermark
发现低于low watermark时, 唤醒kswapd:
__alloc_pages_nodemask
|-- int alloc_flags = ALLOC_WMARK_LOW|ALLOC_CPUSET;
|--page = get_page_from_freelist(,alloc_flags,)
|--if (unlikely(!page))
| |--__alloc_pages_slowpath()
| | |--if (!(gfp_mask & __GFP_NO_KSWAPD))
| | | |--wake_all_kswapd(order, ...)
2.2 high watermark
达到high watermark时停止:
zone_balanced(, balance_gap:0,) //简化问题, 忽略CONFIG_COMPACTION
|--free > high_wmark_pages+balance_gap
|-- and ...
pgdat_balanced //简化问题, 只看order为0的情况
{
if (zone_balanced(..,balance_gap:0, ))
return true
}
kswapd -> balance_pgdat
{
...
shrink_zone
shrink_slab
if (pgdat_balanced(...))
break; /* kswapd: all done */
}
2.3 minfreekbytes
linux-3.10.86/Documentation/sysctl/vm.txt
minfreekbytes:
This is used to force the Linux VM to keep a minimum number of kilobytes free. The VM uses this number to compute a watermark[WMARK_MIN] value for each lowmem zone in the system. Each lowmem zone gets a number of reserved free pages based proportionally on its size.
Some minimal amount of memory is needed to satisfy PF_MEMALLOC allocations; if you set this to lower than 1024KB, your system will become subtly broken, and prone to deadlock under high loads.
Setting this too high will OOM your machine instantly.
linux-3.10.86/mm/vmscan.c
pfmemalloc_watermark_ok
{
pfmemalloc_reserve += min_wmark_pages(zone);
wmark_ok = free_pages > pfmemalloc_reserve / 2;
if (!wmark_ok && waitqueue_active(&pgdat->kswapd_wait)) {
...
/*如果睡眠中(waitqueue_active()), 则唤醒kswapd*/
wake_up_interruptible(&pgdat->kswapd_wait);
}
}
https://lwn.net/Articles/422291/
The thresholds kswapd/direct reclaim starts(ends) depend on
watermark[min,low,high] and currently all watermarks are set
based on minfreekbytes. minfreekbytes is the amount of
free memory that Linux VM should keep at least.
linux-3.10.86/mm/page_alloc.c
__setup_per_zone_wmarks
{
zone->watermark[WMARK_MIN] = ...
zone->watermark[WMARK_LOW] = min_wmark_pages(zone) + (tmp >> 2);
zone->watermark[WMARK_HIGH] = min_wmark_pages(zone) + (tmp >> 1);
}
本文地址: https://awakening-fong.github.io/posts/mm/reclaim_04_parameter
转载请注明出处: https://awakening-fong.github.io
若无法评论, 请打开JavaScript, 并通过proxy.
blog comments powered by Disqus