Skip to content

Instantly share code, notes, and snippets.

@ReactiveRaven
Last active December 16, 2022 18:30
Show Gist options
  • Save ReactiveRaven/9348401 to your computer and use it in GitHub Desktop.
Save ReactiveRaven/9348401 to your computer and use it in GitHub Desktop.
Ubuntu memory tuning

Add these lines to the end of /etc/sysctl.conf:

vm.swappiness=5
vm.min_free_kbytes=122880
vm.vfs_cache_pressure=500

Run these commands as root:

sudo sysctl -w vm.swappiness=5;
sudo sysctl -w vm.min_free_kbytes=122880
sudo sysctl -w vm.vfs_cache_pressure=500

Explanation:

  • vm.swappiness - Reducing this value tells the virtual machine to avoid swapping to disk unless it is actually running low on memory.
  • vm.min_free_kbytes - Increasing this value makes sure files can be loaded from the disk without first having to swap other things out of memory.
  • vm.vfs_cache_pressure - Increasing this causes file-caches to be thrown away rather than swapped out to disk. Opening files will be a tiny amount slower, but switching between applications will be faster.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment