gerrit.sh - OOM score adjustment (suggestion)

75 views
Skip to first unread message

Lorenzo Buzzi

unread,
Feb 27, 2026, 7:34:08 AMFeb 27
to Repo and Gerrit Discussion
Hello everybody,
I have been using Gerrit since version 3.8 (I am currently on 3.12) on a Linux server and manage it with systemd using the unit file from https://github.com/eloy83/gerrit-systemd/.

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

Lorenzo Buzzi

unread,
Feb 27, 2026, 11:16:24 AMFeb 27
to Repo and Gerrit Discussion
I found a small error in my lines and also in one of the original lines of the script.
[ "${VARIABLE}"=="value" ] in POSIX returns always true.
The correct syntax is [ "${VARIABLE}" "value" ].
The fixes are in-line red below.
Alternatives in blue.

Il giorno venerdì 27 febbraio 2026 alle 13:34:08 UTC+1 Lorenzo Buzzi ha scritto:
Hello everybody,
I have been using Gerrit since version 3.8 (I am currently on 3.12) on a Linux server and manage it with systemd using the unit file from https://github.com/eloy83/gerrit-systemd/.

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_score_adj" && [ "$(cat "/proc/${PID}/oom_score_adj")" = "-1000" ]; then
or
elif test -f "/proc/${PID}/oom_score_adj" && ! [ "$(cat "/proc/${PID}/oom_score_adj")" = "0" ]; then
        :
    elif test -f "/proc/${PID}/oom_adj" && [ "$(cat "/proc/${PID}/oom_adj")"=="-16" ]; then
elif test -f "/proc/${PID}/oom_adj" && [ "$(cat "/proc/${PID}/oom_adj")" = "-16" ]; then
or
elif test -f "/proc/${PID}/oom_adj" && ! [ "$(cat "/proc/${PID}/oom_adj")" = "0" ]; then
        :
    elif [ "$(uname -s)"=="Linux" ] && test -d "/proc/${PID}"; then
elif [ "$(uname -s)" = "Linux" ] && test -d "/proc/${PID}"; then

mfick

unread,
Feb 27, 2026, 11:20:14 AMFeb 27
to Repo and Gerrit Discussion
Unfortunately, we cannot accept email contributions as the gerrit CLA must be signed first. Could you upload these as changes to the Gerrit project?

Thanks,

-Martin

Daniele Sassoli

unread,
Mar 3, 2026, 4:12:29 PMMar 3
to Repo and Gerrit Discussion
On Friday, 27 February 2026 at 16:20:14 UTC mfick wrote:
Unfortunately, we cannot accept email contributions as the gerrit CLA must be signed first. Could you upload these as changes to the Gerrit project?

For posterity, Lorenzo raised a change at [1].

[1] https://gerrit-review.googlesource.com/c/gerrit/+/556861 
Reply all
Reply to author
Forward
0 new messages