6

I need to protect mysql process so that it won't be killed when system runs out of memory, we have a bunch of adhoc job run on the server from time to time, so I would prefer the adhoc jobs being killed rather than mysql.

I know I can adjust the oom_score_adj, by setting it to -1000, I can exclude it from OOM killer's consideration. But I am not sure if I need to restart the mysql process for new oom_score_adj to take effect? Does adjust the oom_score_adj for a running process still takes effect?

I was following this post and nobody else mentioned about restarting the server for new oom_score_adj to take effect: https://blog.rimuhosting.com/2015/12/11/dont-let-the-oom-killer-stop-mysql/

Another dumb question is that I can't seem to write to the oom_score_adj file, always getting the permission denied. The oom_score_adj is not owned by root, I have tried a couple of options but keep getting the permission issue:

 echo "echo '-100' > /proc/5653/oom_score_adj" | sudo -u {file_owner} sh

Appreciated for any help!

2
  • Restarting the server or mysqld process will loose the oom adjustment. What distro version are you running (there may be a better way than your script here)?
    – danblack
    Commented Jan 3, 2020 at 5:38
  • @danblack I am using AWS EC2 machine, the distro is Linux version 4.9.184-0.1.ac.235.83.329.metal1.x86_64 (gcc version 7.2.1 20170915 (Red Hat 7.2.1-2) (GCC) ). I have read about Ubuntu having the mechanism to specify OOM score in the init script, it does not look like REHL has the same thing?
    – Jialun Liu
    Commented Jan 3, 2020 at 7:50

1 Answer 1

10

RHEL7 uses systemd. Using the OOMScoreAdjust as follows:

sudo systemctl edit mysqld.service

Note: I'm not sure of the exact service name

Add the following text:

[Service]
OOMScoreAdjust=-1000

restart with:

systemctl restart mysqld.service

Check by looking at the score:

cat /proc/$(pidof mysqld)/oom_score_adj
3
  • I looked into the /etc/init directory on the server, it does not have any service files that remotely relate to mysql process, does this work if the way mysql setup does not rely on the service file at all for my application?
    – Jialun Liu
    Commented Jan 3, 2020 at 18:14
  • Systemd files aren't in /etc/init. Use systemctl | grep -i mysql to find the service name. I'm not sure how your mysql setup is, what package you've used or how it was started, your question was very short on these details. There is a check listed here.
    – danblack
    Commented Jan 3, 2020 at 20:54
  • In my case oom_score_adj keeps throwing 0 after the edit/restart..
    – Pablo A
    Commented Jul 20, 2023 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.