今天给大家分享一下关闭透明大页的方法,废话不多说,直奔主题
关闭大页【即关闭透明大页】【Centos 7】
一.主要步骤
step 1.修改文件
[root@littlelawson conf]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@littlelawson conf]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[root@littlelawson conf]# cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
[root@littlelawson conf]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
step 2.永久追加never到/sys/kernel…/文件中
echo 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.d/rc.local
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.local
step 3.验证是否关闭了透明大页
[root@littlelawson ~]# grep Huge /proc/meminfo
AnonHugePages: 83968 kB
HugePages_Total: 0 #success
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
[root@littlelawson ~]# cat /proc/sys/vm/nr_hugepages
0 #success
二.注意事项:
(1)标准大页(Huge Pages)是从Linux Kernel 2.6后被引入的。目的是使用更大的内存页面(memory page size) 以适应越来越大的系统内存,让操作系统可以支持现代硬件架构的大页面容量功能。
(2)透明大页(Transparent Huge Pages)缩写为THP,这个是RHEL 6开始引入的一个功能。大页的分配机制,标准大页管理是预分配的方式,而透明大页管理则是动态分配的方式
(3)cat /sys/kernel/mm/transparent_hugepage/enabled
(4)vi /etc/default/grub[针对centos 7版本]
(5)/sys/kernel/mm/transparent_hugepage/defrag与/sys/kernel/mm/transparent_hugepage/enabled这两个文件只能输入值always或者never。否则报错,测试如下:
[root@littlelawson rc.d]# cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never
[root@littlelawson rc.d]# echo never >> /sys/kernel/mm/transparent_hugepage/defrag
[root@littlelawson rc.d]# cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]
[root@littlelawson rc.d]# echo ndfsdfsdfever >> /sys/kernel/mm/transparent_hugepage/defrag
-bash: echo: write error: Invalid argument
(6)检查是否关闭透明大页的命令:grep Huge /proc/meminfo
3.脚本如下【适合关闭集群中的透明大页】:
#!/bin/bash
for HOST in `cat hosts`
do
echo $HOST
ssh -t laowang@$HOST "sudo bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'"
ssh -t laowang@$HOST "sudo bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/defrag'"
ssh -t laowang@$HOST "sudo cat /sys/kernel/mm/transparent_hugepage/defrag"
ssh -t laowang@$HOST "sudo cat /sys/kernel/mm/transparent_hugepage/enabled"
ssh -t laowang@$HOST "sudo bash -c echo 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.d/rc.local"
ssh -t laowang@$HOST "sudo grep -i HugePages_Total /proc/meminfo"
done
总结:
以上就是全部内容了,希望能帮助到大家,更多信息,请关注
iis7站长之家!