GNU+Linux command memo

No swap but no freeze

If you turn off your swap (to spare save some storage for instance), you might get stranded with an unresponsive computer as soon as Firefox or LibreOffice eats all your RAM. Here is how to avoid this, allowing the Linux kernel to kill your guilty process via its OOM-Killer (Out of Memory Killer) before getting stranded.

Si vous désactivez votre swap (pour économiser du stockage par exemple) vous risquez d’être bloqué avec un ordinateur ne répondant plus dès que Firefox ou LibreOffice aura mangé toute la mémoire RAM. Voici comment éviter ça, en incitant le noyau Linux à tuer le processus le plus gourmand via son OOM-Killer (Out of Memory Killer) avant le blocage.

$ sudo sysctl vm.swappiness=0 (1)
$ sudo sysctl vm.vfs_cache_pressure=200 (2)
$ sudo sysctl vm.user_reserve_kbytes=8192 (3)
$ sudo sysctl vm.min_free_kbytes=16384 (4)
1 Tells the kernel that there is no swap (seems overkill)
2 Tells the kernel to sacrifice cache over user application memory requests
3 Lower the memory reserved for user space to 8MO (8 * 1024ko) (default is 128MO)
4 Lower the overall (user and kernel) minimum free memory to 16MO (default is 64MO)

To keep those settings over a reboot :

$ sudo echo "vm.swappiness=0" >> /etc/sysctl.conf
$ sudo echo "vm.vfs_cache_pressure=200" >> /etc/sysctl.conf
$ sudo echo "vm.user_reserve_kbytes=8192" >> /etc/sysctl.conf
$ sudo echo "vm.min_free_kbytes=16384" >> /etc/sysctl.conf

As a consequence, you may keep an eye on memory usage and restart Firefox or close unused applications to free some memory and avoid loosing your current LibreOffice work when the OOM-Killer start working. Although Firefox and LibreOffice don’t suffer too much from an impromptu closing.