对zone_reclaim_mode的解释

zone_reclaim_mode参数影响NUMA系统内存回收策略。0表示避免跨节点分配,1启用本地回收,2允许脏页回写,4允许交换页面。设置2或4可能影响性能。文件服务器建议设0,保留磁盘缓存。可通过/proc/sys/vm/zone_reclaim_mode查看当前设置。内核在不同内存分配路径中触发不同回收方式:快速、直接和kswapd内存回收。
摘要由CSDN通过智能技术生成
根据内核文档理解

/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     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值