Skip to content

Swapping and OOM

Nils Deppe edited this page Dec 11, 2021 · 9 revisions
  • Changing swappiness (basically how likely Linux will use swap space):

    sudo sysctl vm.swappiness=10
    

    The range is 0 - 100, 0 means no swap, 100 means lots of swapping. The default on my Arch Linux system was 60. Not that you would have to change the swappiness every time you log in. That can probably made permanent via a kernel flag.

  • Custom user-space OOM killer.

    Building C++ projects can lead to OOM, and then the OOM killer must be activated. Unfortunately the Linux OOM killer starts killing Chrome tabs, electron apps, etc. that basically take up no memory, rather than the C++ compiler that's taking up 10GB+ of memory. The earlyoom provides a user-space OOM killer that can be told to prefer certain processes.

    I changed /etc/default/earlyoom to have:

    EARLYOOM_ARGS="-r 60 -m 10 -s 40,40 --avoid '(^|/)(init|Xorg|ssh)$' --prefer '(^|/usr/bin/)(clang|gcc|g++).*'"
    

    Then run

    systemctl restart earlyoom
    
Clone this wiki locally