I noticed that at startup, the gerrit.sh script prints this output:
WARNING: Could not adjust Gerrit's process for the kernel's out-of-memory killer.
This may be caused by <gerrit's path>/bin/gerrit.sh not being run as root.
Consider changing the OOM score adjustment manually for Gerrit's PID=XXXXXX with e.g.:
echo “-1000” | sudo tee /proc/XXXXXX/oom_score_adj
systemd allows you to set oom_score_adj with a simple directive in the unit file:
[Service]
...
OOMScoreAdjust=-1000
The problem, in my case, is that gerrit.sh is not run as root and the setting made by systemd, although effective, does not suppress the warning. I also took a look at the unit file included in the official gerrit tree (resources/com/google/gerrit/pgm/init/gerrit.service), but that also starts the service as the gerritsrv user and therefore displays the same warning.
I suggest a small change to gerrit.sh that solves this problem. The lines I added are in red:
PID=`cat "$GERRIT_PID"`
if test $UID = 0; then
if test -f "/proc/${PID}/oom_score_adj" ; then
echo -1000 > "/proc/${PID}/oom_score_adj"
else
if test -f "/proc/${PID}/oom_adj" ; then
echo -16 > "/proc/${PID}/oom_adj"
fi
fi
elif test -f "/proc/${PID}/oom_score_adj" && [ "$(cat "/proc/${PID}/oom_score_adj")"=="-1000" ]; then
:
elif test -f "/proc/${PID}/oom_adj" && [ "$(cat "/proc/${PID}/oom_adj")"=="-16" ]; then
:
elif [ "$(uname -s)"=="Linux" ] && test -d "/proc/${PID}"; then
echo "WARNING: Could not adjust Gerrit's process for the kernel's out-of-memory killer."
echo " This may be caused by ${0} not being run as root."
echo " Consider changing the OOM score adjustment manually for Gerrit's PID=${PID} with e.g.:"
echo " echo '-1000' | sudo tee /proc/${PID}/oom_score_adj"
fi
If you think it might be useful, feel free to integrate them into the official code or use them as inspiration for something even better.
Regards,
Lorenzo Buzzi