根据内核文档理解
/proc/sys/vm/zone_reclaim_mode.
A value of 0 means that no local reclaim should take place.
A value of 1 tells the kernel that a reclaim pass should be run in order to avoid allocations from the other node.
如果zone_reclaim_mode 设置为0, 当NUMA系统某个node内存不足的时候,会从相邻的node分配内存。
如果zone_reclaim_mode 设置为1, 当NUMA系统某个node内存不足的时候,会从这个node本地启动内存回收机制,避免从其它node分配内存。
只有这个node的unmmap的cache大于min_unmapped_ratio,才会启动内存回收。unmmap的cache的页面为unmapped pages backed by normal files。
如果zone_reclaim_mode 设置大于5(设置了这个值:4 = Zone reclaim swaps pages),unmmap的cache的页面为all file-backed unmapped pages including swapcache pages and tmpfs
files
如果zone_reclaim_mode 设置2或4, 可能会对系统性能有较大影响。
如果运行的应用是一个文件服务器或数据库服务器,推荐zone_reclaim_mode 设置为0, 减少内存回收,保留disk cache比数据的本地化对性能更有好处。
每个进程使用的NUMA node内存分布情况可以从这个文件查到:/proc//numa_maps。 换成进程的数字pid。
Numactl 和 taskset 可以用来限制进程或线程使用CPU和内存的范围,是另外一种限制内存资源本地化分配的方法。
也可以使用cgroup的cpuset限制进程使用的CPU集合。
还可以设置进程内部特定内存快的分配策略参考mbind 和 set_mempolicy 的man page.
lscpu 和 numactl --hardware 可以显示更多的CPU和NUMA信息
numastat 可以显示系统整体内存分布情况,numa_miss和other_node 表示从另外的node分配的内存大小
numastat -p 显示进程的内存分布在不同node上的统计信息
numastat -m 输出每个node上的类似meminfo的统计信息,或者 cat /sys/devices/system/node/node/meminfo
引用参考【1】
The kernel reclaims pages when the number of free pages in a zone falls below the low water mark.
The page reclaim stops when the number of free pages rise above the ‘LOW’ watermark.
Further, these computations are per-zone:
a zone reclaim can be triggered on a particular zone even if other zones on the host have plenty of free memory.
内核代码
linux-3.0.101-108.87/mm/vmscan.c
3833 /* Work out how many page cache pages we can reclaim in this reclaim_mode */
3834 static long zone_pagecache_reclaimable(struct zone *zone)
3835 {
3836 long nr_pagecache_reclaimable;
3837 long delta = 0;
3838
3839 /*
3840 * If RECLAIM_SWAP is set, then all file pages are considered
3841 * potentially reclaimable. Otherwise, we have to worry about
3842 * pages like swapcache and zone_unmapped_file_pages() provides
3843