The Linux kernel allocates memory upon the demand of the applications running on the system. Because many applications allocate their memory up front and often don’t utilize the memory allocated, the kernel was designed with the ability to over-commit memory to make memory usage more efficient. This over-commit model allows the kernel to allocate more memory than it actually has physically available. If a process actually utilizes the memory it was allocated, the kernel then provides these resources to the application. When too many applications start utilizing the memory they were allocated, the over-commit model sometimes becomes problematic and the kernel must start killing processes in order to stay operational. The mechanism the kernel uses to recover memory on the system is referred to as the out-of-memory killer or OOM killer for short.
In the latest version of the proc filesystem, the OOMKiller has had some adjustments. The valid range is now -1000 to +1000; previously it was -16 to +15 with a special score of -17 to outright disable it. It also now uses /proc/
On Centos 7, systemd now includes OOMScoreAdjust specifically for altering this. To fully disable OOMKiller on a service simply add OOMScoreAdjust=-1000 directly underneath a [Service] definition, as follows.
This score can be adjusted if you want to ensure the parent PID lives, but children processes can be safely reaped by setting it to something like -999, then if “/bin/parent”, has “/bin/parent –memory-hungry-child,” it will be killed first.
Or you can run a cron to set the OOM Kill value manually. This will be very helpful in third-party applications:
For Rhel 6/7 vi /etc/cron.d/oom_disable * * * * * pgrep -f "/usr/bin/mongod" | while read PID; do echo "-1000" >/proc/$PID/oom_score_adj; done Note: Change the cron timing as per your requirement. The same cron can be set to Rhel 6 Reference: https://access.redhat.com/solutions/1171183 For Rhel 5 vi /etc/cron.d/oom_disable * * * * * pgrep -f "/usr/bin/mongod" | while read PID; do echo "-1000" >/proc/$PID/oom_adj; done Note: Change the cron timing as per your requirement.
You can check the more info from the server /usr/share/doc/kernel-doc-/Documentation/filesystems/proc.txt
If you need any further assistance contact me @ [email protected].. prefer hangout 🙂