RHEL中如何控制页面缓存的大小?
环境
- Red Hat Enterprise Linux (RHEL) 4, 5, 6, 7, 8
问题
- How to control the size of the page cache in Red Hat Enterprise Linux?
决议
-
In RHEL 4, 5, 6, 7 and 8 the page cache is dynamically adjusted. There is no kernel parameter to control its size directly.
-
However, it is possible to indirectly influence the page cache size via tuning of the virtual memory settings.
-
The primary
sysctl
tunables (along with their default values) for controlling the behaviour of the page cache are as follows:-
vm.vfs_cache_pressure
(default = 100)- At the default value of vfs_cache_pressure=100 the kernel will attempt to reclaim dentries and inodes at a "fair" rate with respect to pagecache and swapcache reclaim.
- Controls the tendency of the kernel to reclaim the memory which is used for caching of directory and inode objects.
- Decreasing vfs_cache_pressure causes the kernel to prefer to retain dentry and inode caches. Increasing vfs_cache_pressure beyond 100 causes the kernel to prefer to reclaim dentries and inodes
- To limit the size of page cache, you would want to increase this value so the kernel will be more likely to reclaim these objects.
-
vm.dirty_background_ratio
(default = 10)- Contains, as a percentage of total system memory, the number of pages at which the pdflush background writeback daemon will start writing out dirty data.
- To limit the size of page cache, decrease this number so the pdflush daemon will start writing out dirty data sooner.
-
vm.dirty_ratio
(default = 20)- Contains (as a percentage of total system memory) the number of pages at which a process which is generating disk writes will itself start writing out dirty data.
- To limit the size of page cache, decrease this number so processes will start writing out dirty data sooner.
-
vm.dirty_writeback_centisecs
(Red Hat Enterprise Linux 4 and 5: default = 499, Red Hat Enterprise Linux 6, 7 and 8: default = 500)- The pdflush writeback daemons will periodically wake up and write "old" data out to disk. This tunable expresses the interval between those wakeups, in 100'ths of a second. Setting this to zero disables periodic writeback altogether.
- To limit the size of page cache, decrease this value so the pdflush daemon will wake up more often and write dirty data out to disk.
-
vm.dirty_expire_centisecs
(Red Hat Enterprise Linux 4 and 5: default = 2999, Red Hat Enterprise Linux 6, 7 and 8: default = 3000)- This tunable is used to define when dirty data is old enough to be eligible for writeout by the pdflush daemons. It is expressed in 100ths of a second. Data which has been dirty in-memory for longer than this interval will be written out next time a pdflush daemon wakes up.
- To limit the size of page cache, decrease this value so data will be considered dirty sooner and will be written out by pdflush.
-
vm.swappiness
(RHEL 5 and 6: default = 60, RHEL 7 and 8: default = 30)- This controls how likely the vm is to swap out inactive memory pages (the higher the value, the more likely it is to swap).
- To limit the size of page cache, decrease this value so the kernel is less likely to swap and thus more likely to drop pages from the page cache.
- A value of zero here does not prevent the system from swapping.
-
-
You do not need to reboot for sysctl changes to take effect.
-
Modifications to these values could effect a significant change in behavior and performance of the system (positive or negative). It is highly recommended that you modify them slightly at first and test each change thoroughly to ensure they do not have any negative effects in your environment.
-
For further details please check the following documents that are contained in the
kernel-doc
package:/usr/share/doc/kernel-doc-$VERSION/Documentation/{filesystems/proc.txt, sysctl/vm.txt}
.
【推荐】国内首个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命令使用场景 杂记