From 7354936ef71026a0ac7f5c592d065e91e5d9426f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 27 Oct 2024 01:24:49 +0900 Subject: [PATCH] core/cgroup: rename CGROUP_PRESSURE_WATCH_ON/OFF -> CGROUP_PRESSURE_WATCH_YES/NO No functional change, but let's print yes/no rather than on/off in systemd-analyze. Similar to 2e8a581b9cc1132743c2341fc334461096266ad4 and edd3f4d9b7a63dc9a142ef20119e80d1d9527f2f. (Note, the commit messages of those commits are wrong, as parse_boolean() supports on/off anyway.) --- man/systemd.resource-control.xml | 27 +++++++++++++-------------- src/core/cgroup.c | 6 +++--- src/core/cgroup.h | 6 +++--- src/core/exec-invoke.c | 2 +- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml index 1f16052a33..ce4dfabfdd 100644 --- a/man/systemd.resource-control.xml +++ b/man/systemd.resource-control.xml @@ -1611,20 +1611,19 @@ DeviceAllow=/dev/loop-control MemoryPressureWatch= - Controls memory pressure monitoring for invoked processes. Takes one of - off, on, auto or skip. If - off tells the service not to watch for memory pressure events, by setting the - $MEMORY_PRESSURE_WATCH environment variable to the literal string - /dev/null. If on tells the service to watch for memory - pressure events. This enables memory accounting for the service, and ensures the - memory.pressure cgroup attribute file is accessible for reading and writing by the - service's user. It then sets the $MEMORY_PRESSURE_WATCH environment variable for - processes invoked by the unit to the file system path to this file. The threshold information - configured with MemoryPressureThresholdSec= is encoded in the - $MEMORY_PRESSURE_WRITE environment variable. If the auto value - is set the protocol is enabled if memory accounting is anyway enabled for the unit, and disabled - otherwise. If set to skip the logic is neither enabled, nor disabled and the two - environment variables are not set. + Controls memory pressure monitoring for invoked processes. Takes a boolean or one of + auto and skip. If no, tells the service not + to watch for memory pressure events, by setting the $MEMORY_PRESSURE_WATCH + environment variable to the literal string /dev/null. If yes, + tells the service to watch for memory pressure events. This enables memory accounting for the + service, and ensures the memory.pressure cgroup attribute file is accessible for + reading and writing by the service's user. It then sets the $MEMORY_PRESSURE_WATCH + environment variable for processes invoked by the unit to the file system path to this file. The + threshold information configured with MemoryPressureThresholdSec= is encoded in + the $MEMORY_PRESSURE_WRITE environment variable. If the auto + value is set the protocol is enabled if memory accounting is anyway enabled for the unit, and + disabled otherwise. If set to skip the logic is neither enabled, nor disabled and + the two environment variables are not set. Note that services are free to use the two environment variables, but it's unproblematic if they ignore them. Memory pressure handling must be implemented individually in each service, and diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 47a771d51e..6933aae54d 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -5614,13 +5614,13 @@ static const char* const cgroup_device_policy_table[_CGROUP_DEVICE_POLICY_MAX] = DEFINE_STRING_TABLE_LOOKUP(cgroup_device_policy, CGroupDevicePolicy); static const char* const cgroup_pressure_watch_table[_CGROUP_PRESSURE_WATCH_MAX] = { - [CGROUP_PRESSURE_WATCH_OFF] = "off", + [CGROUP_PRESSURE_WATCH_NO] = "no", + [CGROUP_PRESSURE_WATCH_YES] = "yes", [CGROUP_PRESSURE_WATCH_AUTO] = "auto", - [CGROUP_PRESSURE_WATCH_ON] = "on", [CGROUP_PRESSURE_WATCH_SKIP] = "skip", }; -DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(cgroup_pressure_watch, CGroupPressureWatch, CGROUP_PRESSURE_WATCH_ON); +DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(cgroup_pressure_watch, CGroupPressureWatch, CGROUP_PRESSURE_WATCH_YES); static const char* const cgroup_ip_accounting_metric_table[_CGROUP_IP_ACCOUNTING_METRIC_MAX] = { [CGROUP_IP_INGRESS_BYTES] = "IPIngressBytes", diff --git a/src/core/cgroup.h b/src/core/cgroup.h index 550c1ea88f..1ed74831c8 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -126,9 +126,9 @@ struct CGroupSocketBindItem { }; typedef enum CGroupPressureWatch { - CGROUP_PRESSURE_WATCH_OFF, /* → tells the service payload explicitly not to watch for memory pressure */ + CGROUP_PRESSURE_WATCH_NO, /* → tells the service payload explicitly not to watch for memory pressure */ + CGROUP_PRESSURE_WATCH_YES, CGROUP_PRESSURE_WATCH_AUTO, /* → on if memory account is on anyway for the unit, otherwise off */ - CGROUP_PRESSURE_WATCH_ON, CGROUP_PRESSURE_WATCH_SKIP, /* → doesn't set up memory pressure watch, but also doesn't explicitly tell payload to avoid it */ _CGROUP_PRESSURE_WATCH_MAX, _CGROUP_PRESSURE_WATCH_INVALID = -EINVAL, @@ -403,7 +403,7 @@ void cgroup_context_remove_socket_bind(CGroupSocketBindItem **head); static inline bool cgroup_context_want_memory_pressure(const CGroupContext *c) { assert(c); - return c->memory_pressure_watch == CGROUP_PRESSURE_WATCH_ON || + return c->memory_pressure_watch == CGROUP_PRESSURE_WATCH_YES || (c->memory_pressure_watch == CGROUP_PRESSURE_WATCH_AUTO && c->memory_accounting); } diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 4b63e2a204..0dbf34042d 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -4607,7 +4607,7 @@ int exec_invoke( "Failed to adjust ownership of '%s', ignoring: %m", memory_pressure_path); memory_pressure_path = mfree(memory_pressure_path); } - } else if (cgroup_context->memory_pressure_watch == CGROUP_PRESSURE_WATCH_OFF) { + } else if (cgroup_context->memory_pressure_watch == CGROUP_PRESSURE_WATCH_NO) { memory_pressure_path = strdup("/dev/null"); /* /dev/null is explicit indicator for turning of memory pressure watch */ if (!memory_pressure_path) { *exit_status = EXIT_MEMORY; -- 2.25.1