From a617007417a09061a6f5f86b5751a080b3701b18 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 9 Mar 2023 12:34:23 +0100 Subject: [PATCH] mempress: change default PSI window duration to 2s This changes the PSI window duration we default to for watching memory pressure events from 1s to 2s. This is because apparently the kernel will soon disallow window durations other than 2s for unprivileged processes. Hence, we'll bump the threshold from 100m to 200ms, and the window from 1s to 2s. --- man/systemd-system.conf.xml | 2 +- man/systemd.resource-control.xml | 4 ++-- src/basic/psi-util.h | 4 ++-- src/libsystemd/sd-event/sd-event.c | 4 +++- test/units/testsuite-79.sh | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml index 829b4be0ed5..554d0fbd451 100644 --- a/man/systemd-system.conf.xml +++ b/man/systemd-system.conf.xml @@ -565,7 +565,7 @@ MemoryPressureWatch= and MemoryPressureThresholdSec= settings. See systemd.resource-control5 - for details. Defaults to auto and 100ms, respectively. This + for details. Defaults to auto and 200ms, respectively. This also sets the memory pressure monitoring threshold for the service manager itself. diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml index d18fd9a94cd..21e43421653 100644 --- a/man/systemd.resource-control.xml +++ b/man/systemd.resource-control.xml @@ -1332,10 +1332,10 @@ DeviceAllow=/dev/loop-control Sets the memory pressure threshold time for memory pressure monitor as configured via MemoryPressureWatch=. Specifies the maximum allocation latency before a memory - pressure event is signalled to the service, per 1s window. If not specified defaults to the + pressure event is signalled to the service, per 2s window. If not specified defaults to the DefaultMemoryPressureThresholdSec= setting in systemd-system.conf5 - (which in turn defaults to 100ms). The specified value expects a time unit such as + (which in turn defaults to 200ms). The specified value expects a time unit such as ms or µs, see systemd.time7 for details on the permitted syntax. diff --git a/src/basic/psi-util.h b/src/basic/psi-util.h index 558a130996b..bf8f4fe51c2 100644 --- a/src/basic/psi-util.h +++ b/src/basic/psi-util.h @@ -31,5 +31,5 @@ int is_pressure_supported(void); /* Default parameters for memory pressure watch logic in sd-event and PID 1 */ #define MEMORY_PRESSURE_DEFAULT_TYPE "some" -#define MEMORY_PRESSURE_DEFAULT_THRESHOLD_USEC (100 * USEC_PER_MSEC) -#define MEMORY_PRESSURE_DEFAULT_WINDOW_USEC USEC_PER_SEC +#define MEMORY_PRESSURE_DEFAULT_THRESHOLD_USEC (200 * USEC_PER_MSEC) +#define MEMORY_PRESSURE_DEFAULT_WINDOW_USEC (2 * USEC_PER_SEC) diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 413ac16aa29..f11f35ef6e8 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -2005,7 +2005,9 @@ _public_ int sd_event_add_memory_pressure( * some 100000 1000000 * full 100000 1000000 * - * We'll default to the middle level that both agree on */ + * We'll default to the middle level that both agree on. Except we do it on a 2s window + * (i.e. 200ms per 2s, rather than 100ms per 1s), because that's the window duration the + * kernel will allow us to do unprivileged, also in the future. */ if (asprintf((char**) &write_buffer, "%s " USEC_FMT " " USEC_FMT, MEMORY_PRESSURE_DEFAULT_TYPE, diff --git a/test/units/testsuite-79.sh b/test/units/testsuite-79.sh index b11923bc07d..cced3205c59 100755 --- a/test/units/testsuite-79.sh +++ b/test/units/testsuite-79.sh @@ -43,7 +43,7 @@ test -w "$MEMORY_PRESSURE_WATCH" ls -al "$MEMORY_PRESSURE_WATCH" -EXPECTED="$(echo -n -e "some 123000 1000000\x00" | base64)" +EXPECTED="$(echo -n -e "some 123000 2000000\x00" | base64)" test "$EXPECTED" = "$MEMORY_PRESSURE_WRITE"