How to control the size of page cache in RHEL?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux (RHEL) 4, 5, 6, 7, 8, 9, 10

Issue

  • How to control the size of the page cache in Red Hat Enterprise Linux?

Resolution

  • In RHEL 4, 5, 6, 7, 8, 9 and 10 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 = 30, RHEL 9: 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, 8, 9 and 10: 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, 8, 9 and 10: 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, 8 and 10: default = 30, RHEL 9: default = 60)

      • 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.
      • In RHEL8, at 100, the VM assumes equal I/O cost of swapping and filesystem paging. Lower value indicates signify more expensive I/O cost of swapping. In RHEL8.4 or later, RHEL9 and RHEL 10, it can be set higher values to indicate relative cheaper I/O cost of swapping for in-memory swap such as zswap.
  • 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}.

SBR
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.