This writeup is assuming you are tweaking to the minimise swap and maximise physical memory. This tweaking should be considered especially for High Performance MPI applications where good low latency parallelism between nodes is very essential.
In addition, this writeup also help you to “kill” runaway memory applications
1. Preventing Swapping unless absolutely necessary
If you have lots of RAM, you may want to use RAM as I/O caches and buffers. The benefits of using RAM as I/O caches and buffers are definitely speed when compared to swapping data.
To review the value of swappiness can be seen by running the following commands
# cat /proc/sys/vm/swappiness
To modified by running the following command (0 will prevent swapping unless absolutely required)
# echo 0 > /proc/sys/vm/swappiness
To make the settings permanent, edit /etc/sysctl.conf.
vm.swappiness=0
Remember to reboot.
2. Memory Management – Preventing the kernel from dishing out more memory than required
I think for us who have been running computational jobs have seen the memory got eaten up by some buggy or stray applications. Hopefully the kernel kills it. But somehow you must have seen that the kernel may not have kill the culprit and the server go to a linbo.
Let’s say if we wish to ensure that the kernel only gives out memory to processes equal to the physical memory, then we have to do the following at /etc/sysctl.conf or /etc/sysctl.d/myapp.conf
My assumption is that you have 10GB of swap and 20GB of memory and you wish the kernel to stop handling processes at 18GB RAM, then the calculation should be (swap size + 0.4 * RAM size)
So at /etc/sysctlf.conf, the configuration will be
vm.overcommit_memory = 2 vm.overcommit_ratio = 40
Note: The ratio is (40/100). For explanation of vm.overcommit_memory =2. Do look at Tweaking Linux Kernel Overcommit Behaviour for memory
Once the memory hits 18GB, the so-called OOM killer of the Linux kernel will kick in.
Another calculation example is that your RAM size and SWAP size are the same and you wish exactly the physical memory to be used only. then
vm.overcommit_memory = 2 vm.overcommit_ratio = 0
For more information, do read
- Preventing Swapping unless absolutely necessary (Linux Toolkit)
- Speeding up boot time by Optimising Physical Memory and Swap (Linux Toolkit)
- Memory Management – Preventing the kernel from dishing out more memory than required (Linux Toolkit)
- Tweaking Linux Kernel Overcommit Behaviour for memory (Linux Toolkit)