Linux/OOM

From Omnia
Jump to: navigation, search

Swappiness

Set Swappiness Level: [1]

sudo sysctl -w vm.swappiness=0     # The kernel will swap only to avoid an out of memory condition
sudo sysctl -w vm.swappiness=60    # The default value.
sudo sysctl -w vm.swappiness=100   # The kernel will swap aggressively.


See: https://www.digitalocean.com/community/tutorials/how-to-configure-virtual-memory-swap-file-on-a-vps

Mem Eater

#include <stdlib.h>
int main() {
    for (;;) {char* mem=malloc(4096); mem[0]=1;};
}
gcc memeater.c -o memeater
./memeater

much slower:

#include <stdlib.h>
int main() {
    int i;
    for (;;) {char* mem=malloc(256); mem[0]=1;for(i=1;i<=100000;i++){;;}};
}

Source: http://unix.stackexchange.com/questions/135114/out-of-swap-what-happens