yae*_*ael 4 rhel kernel memory swap
RHEL 7.2 内存使用,每个free -m
:
total used free shared buff/cache available
Mem: 386564 77941 57186 687 251435 306557
Swap: 13383 2936 16381
Run Code Online (Sandbox Code Playgroud)
我们看到使用的swap是2936M
所以我们想通过以下方式将其减少到 min
echo 1 > /proc/sys/vm/swappiness
sysctl -w vm.swappiness=1
echo "vm.swappiness = 1" >> /etc/sysctl.conf
Run Code Online (Sandbox Code Playgroud)
10 分钟后我们再次检查,但操作系统仍然使用交换
free -m
:
total used free shared buff/cache available
Mem: 386564 77941 57186 687 251435 306557
Swap: 13389 2930 16381
Run Code Online (Sandbox Code Playgroud)
为什么我们没有采取的行动会立即产生影响?
我们是否需要重新启动操作系统,以便让交换曾经是 0 ?
例子
我们运行vmstat
:
vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
3 0 85740 20255872 2238248 183126400 0 0 7 162 0 0 7 1 92 0 0
Run Code Online (Sandbox Code Playgroud)
我们减少 vm.swappiness=1
并在 10 分钟后运行 vmstat:
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
3 0 85740 20255872 2238248 183126400 0 0 7 162 0 0 7 1 92 0 0
Run Code Online (Sandbox Code Playgroud)
Ste*_*itt 10
正如您之前被告知的(请参阅为什么 swappiness 不起作用?),更改swappiness
只会影响内核在需要释放内存时做出的未来决策。减少它不会导致内核重新加载已换出的所有内容。
您的vmstat
输出显示交换没有被积极使用,即您当前的工作负载确实不需要已换出的页面。
尝试以您倾向于做的方式对内核对交换的使用进行微观管理是没有意义的。根据您的工作负载,决定是否需要支持页面缓存,进行相应调整swappiness
,然后让系统继续运行。
如果你真的想清除交换,禁用它并重新启用它:
swapoff -a && swapon -a
Run Code Online (Sandbox Code Playgroud)
free -m
不是有关交换使用的可靠信息来源。相反,请在暂时更改交换性的 echo 命令之前和之后使用vmstat 。
1) swapoff -a && swapon -a && vmstat
2)做需要交换的工作
3)vmstat
现在您知道在更改 swappiness 之前进行了多少交换。如果没有交换,就寻找其他可以交换的工作。
4) 使用 echo 命令临时更改交换性
5) swapoff -a && swapon -a && vmstat
6)执行需要交换的工作
7)vmstat
8)比较si和so值。
需要注意的值是:
si: Amount of memory swapped in from disk (/s).
so: Amount of memory swapped to disk (/s).
Run Code Online (Sandbox Code Playgroud)
您还可以在《RHEL 7 性能调优指南》中找到有用的信息。
非常感谢Stephen Kitt提醒我有关 swapon 和 swapoff 的信息。
归档时间: |
|
查看次数: |
4046 次 |
最近记录: |