tools/xenstore: set oom score for xenstore daemon on Linux
authorJuergen Gross <jgross@suse.com>
Tue, 12 Oct 2021 13:41:47 +0000 (15:41 +0200)
committerIan Jackson <iwj@xenproject.org>
Mon, 18 Oct 2021 13:15:59 +0000 (14:15 +0100)
Xenstored is absolutely mandatory for a Xen host and it can't be
restarted, so being killed by OOM-killer in case of memory shortage is
to be avoided.

Set /proc/$pid/oom_score_adj (if available) per default to -500 (this
translates to 50% of dom0 memory size) in order to allow xenstored to
use large amounts of memory without being killed.

The percentage of dom0 memory above which the oom killer is allowed to
kill xenstored can be set via XENSTORED_OOM_MEM_THRESHOLD in
xencommons.

Make sure the pid file isn't a left-over from a previous run delete it
before starting xenstored.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Ian Jackson <iwj@xenproject.org>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
tools/hotplug/Linux/init.d/sysconfig.xencommons.in
tools/hotplug/Linux/launch-xenstore.in

index 00cf7f91d4a18007df21f962c1c48b04bde1a261..b83101ab7e03caee3756380ffb7aa1b3fa385ffa 100644 (file)
@@ -48,6 +48,15 @@ XENSTORED_ARGS=
 # Only evaluated if XENSTORETYPE is "daemon".
 #XENSTORED_TRACE=[yes|on|1]
 
+## Type: integer
+## Default: 50
+#
+# Percentage of dom0 memory size the xenstore daemon can use before the
+# OOM killer is allowed to kill it.
+# The specified value is multiplied by -10 and echoed to
+# /proc/PID/oom_score_adj.
+#XENSTORED_OOM_MEM_THRESHOLD=50
+
 ## Type: string
 ## Default: @LIBEXEC@/boot/xenstore-stubdom.gz
 #
index 019f9d6f4d68ce80c1439083e82843c0734be78b..1747c9606563204e208fc3693837b2a7b169fb47 100644 (file)
@@ -59,11 +59,17 @@ test -f @CONFIG_DIR@/@CONFIG_LEAF_DIR@/xencommons && . @CONFIG_DIR@/@CONFIG_LEAF
                echo "No xenstored found"
                exit 1
        }
+       [ -z "$XENSTORED_OOM_MEM_THRESHOLD" ] || XENSTORED_OOM_MEM_THRESHOLD=50
+       XS_OOM_SCORE=-$(($XENSTORED_OOM_MEM_THRESHOLD * 10))
+
+       rm -f @XEN_RUN_DIR@/xenstored.pid
 
        echo -n Starting $XENSTORED...
        $XENSTORED --pid-file @XEN_RUN_DIR@/xenstored.pid $XENSTORED_ARGS
 
        systemd-notify --booted 2>/dev/null || timeout_xenstore $XENSTORED || exit 1
+       XS_PID=`cat @XEN_RUN_DIR@/xenstored.pid`
+       echo $XS_OOM_SCORE >/proc/$XS_PID/oom_score_adj
 
        exit 0
 }