diff options
author | Anita Zhang <the.anitazha@gmail.com> | 2021-02-09 01:47:34 -0800 |
---|---|---|
committer | Anita Zhang <the.anitazha@gmail.com> | 2021-02-09 02:27:40 -0800 |
commit | 59331b8e292a93bc7a03a51fe54cb65a4257e894 (patch) | |
tree | 3b420e7a81168b54d8a6578fd3ea52b593c2a4af /test/units | |
parent | 242d75bdaaa6f222a47148f8a83cc425d6ceefb3 (diff) | |
download | systemd-59331b8e292a93bc7a03a51fe54cb65a4257e894.tar.gz |
oom: implement avoid/omit xattr support
There may be situations where a cgroup should be protected from killing
or deprioritized as a candidate. In FB oomd xattrs are used to bias oomd
away from supervisor cgroups and towards worker cgroups in container
tasks. On desktops this can be used to protect important units with
unpredictable resource consumption.
The patch allows systemd-oomd to understand 2 xattrs:
"user.oomd_avoid" and "user.oomd_omit". If systemd-oomd sees these
xattrs set to 1 on a candidate cgroup (i.e. while attempting to kill something)
AND the cgroup is owned by root, it will either deprioritize the cgroup as
a candidate (avoid) or remove it completely as a candidate (omit).
Usage is restricted to root owned cgroups to prevent situations where an
unprivileged user can set their own cgroups lower in the kill priority than
another user's (and prevent them from omitting their units from
systemd-oomd killing).
Diffstat (limited to 'test/units')
-rw-r--r-- | test/units/testsuite-56-testmunch.service | 7 | ||||
-rwxr-xr-x | test/units/testsuite-56.sh | 31 |
2 files changed, 34 insertions, 4 deletions
diff --git a/test/units/testsuite-56-testmunch.service b/test/units/testsuite-56-testmunch.service new file mode 100644 index 0000000000..b4b925a7af --- /dev/null +++ b/test/units/testsuite-56-testmunch.service @@ -0,0 +1,7 @@ +[Unit] +Description=Create some memory pressure + +[Service] +MemoryHigh=2M +Slice=testsuite-56-workload.slice +ExecStart=/usr/lib/systemd/tests/testdata/units/testsuite-56-slowgrowth.sh diff --git a/test/units/testsuite-56.sh b/test/units/testsuite-56.sh index 8b01fe37ed..88c185b886 100755 --- a/test/units/testsuite-56.sh +++ b/test/units/testsuite-56.sh @@ -23,20 +23,43 @@ oomctl | grep "/testsuite-56-workload.slice" oomctl | grep "1.00%" oomctl | grep "Default Memory Pressure Duration: 5s" -# systemd-oomd watches for elevated pressure for 30 seconds before acting. -# It can take time to build up pressure so either wait 5 minutes or for the service to fail. -timeout=$(date -ud "5 minutes" +%s) +# systemd-oomd watches for elevated pressure for 5 seconds before acting. +# It can take time to build up pressure so either wait 2 minutes or for the service to fail. +timeout=$(date -ud "2 minutes" +%s) while [[ $(date -u +%s) -le $timeout ]]; do if ! systemctl status testsuite-56-testbloat.service; then break fi - sleep 15 + sleep 5 done # testbloat should be killed and testchill should be fine if systemctl status testsuite-56-testbloat.service; then exit 42; fi if ! systemctl status testsuite-56-testchill.service; then exit 24; fi +# only run this portion of the test if we can set xattrs +if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then + sleep 120 # wait for systemd-oomd kill cool down and elevated memory pressure to come down + + systemctl start testsuite-56-testchill.service + systemctl start testsuite-56-testmunch.service + systemctl start testsuite-56-testbloat.service + setfattr -n user.oomd_avoid -v 1 /sys/fs/cgroup/testsuite.slice/testsuite-56.slice/testsuite-56-workload.slice/testsuite-56-testbloat.service + + timeout=$(date -ud "2 minutes" +%s) + while [[ $(date -u +%s) -le $timeout ]]; do + if ! systemctl status testsuite-56-testmunch.service; then + break + fi + sleep 5 + done + + # testmunch should be killed since testbloat had the avoid xattr on it + if ! systemctl status testsuite-56-testbloat.service; then exit 25; fi + if systemctl status testsuite-56-testmunch.service; then exit 43; fi + if ! systemctl status testsuite-56-testchill.service; then exit 24; fi +fi + systemd-analyze log-level info echo OK > /testok |