Adjust Virtual Memory (VM) Tunables

Virtual Memory (VM) tunables are kernel parameters that control how the system manages memory, including how aggressively it uses swap space. Adjusting these settings can significantly impact system performance based on the workload.

About this task

The vm.swappiness parameter controls the kernel’s tendency to move processes out of physical memory and into swap space. The value is a percentage, ranging from 0 to 100:

  • Higher Value (e.g., 60 or 100): The kernel will swap processes to disk more aggressively. This can free up physical memory for other uses (like the file system cache), but it may increase I/O operations and latency if swapped processes are frequently needed.
  • Lower Value (e.g., 0 or 10): The kernel will try to avoid swapping and keep processes in physical memory for as long as possible. This is generally preferred for desktop systems or servers with fast I/O and large amounts of RAM.

Following other relevant VM tunables can influence swap behavior:

  • vm.dirty_ratio: The percentage of system memory that can be filled with "dirty" pages (memory pages that have been modified but not yet written to disk) before the kernel begins actively writing them out.
  • vm.dirty_background_ratio: The percentage of system memory that can be filled with dirty pages before a background kernel process begins writing them out. This is a less aggressive action than vm.dirty_ratio.

Procedure

  1. View the current value:
    $ cat /proc/sys/vm/swappiness

    The default value is 60.

  2. Set the value temporarily, for example, to 10:
    # sysctl vm.swappiness=10
  3. Set the value permanently to persist across reboots by editing the /etc/sysctl.d/99-sysctl.conf or a similar configuration file:
    vm.swappiness = 10
  4. Apply the changes:
    # sysctl -p