为什么RHEL系统使用交换空间而不是释放缓存和缓冲内存?
环境
- Red Hat Enterprise Linux (RHEL) All versions
问题
- Why does my system utilize swap space instead of freeing up cache and buffer memory?
- What is the impact of scaling up and down the value of "swappiness"?
- Why am I getting out of memory while swap is unused?
- Why swap is not being used or under used?
决议
-
The kernel uses heuristics to guess which pages of memory are likely to be needed in the near future and tries to keep those pages in memory, regardless of whether they belong to processes or kernel caches. It is normal for the kernel to swap out process memory, even when there is plenty of cache memory that could easily be freed.
-
The
swappiness
parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. -
The kernel heuristics can be tuned by changing the
vm.swappiness
parameter ofsysctl
. The default value, which is60
, is reasonable for most workloads, but some systems may benefit from lower or higher values. Increasing this value will make the system more inclined to swap inactive memory pages to disk, rather than dropping pages from the page cache, leaving more memory free for cached I/O. This may be preferred for heavy I/O workloads. Decreasing this value will make the system less inclined to swap, and more inclined to drop pages from the page cache. -
Tuning
vm.swappiness
may hurt performance, or may have a different impact between light and heavy workloads. Changes to this parameter should be made in small increments, and should be tested under the same conditions that the system normally operates. -
For example, to set the
vm.swappiness
parameter to 50:
# echo '50'> /proc/sys/vm/swappiness
- To make this setting persistent across reboots, add this line to the
/etc/sysctl.conf
file:
vm.swappiness = 50
Note: while vm.swappiness
accepts 0-100 values, it should not be set to 0, as this can cause an unexpected behaviour on the system. 0 is a special value which works differently depending on the RHEL version in use:
- Prior to RHEL 6.4: vm.swappiness = 0 disables swapping for the most part, except to avoid an out-of-memory situation.
- RHEL 6.4 and later: vm.swappines = 0 disables swapping in most cases, If we set swappiness==0, the kernel does not swap out completely (for global reclaim until the amount of free pages and filebacked pages in a zone has been reduced to something very very small (nr_free + nr_filebacked < high watermark)).
诊断步骤
Value of swappiness can be checked as follow:
$ cat /proc/sys/vm/swappiness
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· Open-Sora 2.0 重磅开源!
2020-06-28 centos7 netstat命令使用场景 杂记