为什么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 of sysctl. The default value, which is 60, 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
posted @   augusite  阅读(110)  评论(0编辑  收藏  举报
编辑推荐:
· 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命令使用场景 杂记
点击右上角即可分享
微信分享提示