From 1cafbecabecc619b4e147abd9925282d0ff323bd Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 8 Oct 2024 06:19:04 +0900 Subject: [PATCH 1/5] core: suppress one debugging log Otherwise, the log is shown even when getting properties. Even though it is in the debug level, that's quite noisy. [ 338.785847] TEST-55-OOMD.sh[1624]: Oct 07 16:35:15 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount [ 338.786985] TEST-55-OOMD.sh[1624]: Oct 07 16:35:17 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount [ 338.787412] TEST-55-OOMD.sh[1624]: Oct 07 16:35:20 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount [ 338.791776] TEST-55-OOMD.sh[1624]: Oct 07 16:35:22 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount [ 338.792938] TEST-55-OOMD.sh[1624]: Oct 07 16:35:24 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount [ 338.793225] TEST-55-OOMD.sh[1624]: Oct 07 16:35:26 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount [ 338.793424] TEST-55-OOMD.sh[1624]: Oct 07 16:35:28 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount [ 338.796448] TEST-55-OOMD.sh[1624]: Oct 07 16:35:31 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount [ 338.797997] TEST-55-OOMD.sh[1624]: Oct 07 16:35:33 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount [ 338.799206] TEST-55-OOMD.sh[1624]: Oct 07 16:35:35 H systemd[1]: TEST-55-OOMD-testmunch.service: Unit not running in private mount namespace, cannot live mount --- src/core/service.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/service.c b/src/core/service.c index 7162016313..c008849b78 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -5309,7 +5309,11 @@ static int service_can_live_mount(const Unit *u, sd_bus_error *error) { /* Ensure that the unit runs in a private mount namespace */ if (!exec_needs_mount_namespace(unit_get_exec_context(u), /* params= */ NULL, unit_get_exec_runtime(u))) { - log_unit_debug(u, "Unit not running in private mount namespace, cannot live mount"); + + /* This is also called in property_get_can_live_mount(). Suppress the debugging log when called in it. */ + if (error) + log_unit_debug(u, "Unit not running in private mount namespace, cannot live mount"); + return sd_bus_error_setf( error, SD_BUS_ERROR_INVALID_ARGS, From 483ab07534ccf91b0b9b2b0489c854b0cd6fa079 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 8 Oct 2024 11:07:47 +0900 Subject: [PATCH 2/5] systemctl: separate memory usage with comma Just for readability. Before: $ build/systemctl status -n 0 systemd-networkd.service | grep Memory: Memory: 4.7M (peak: 14.3M swap: 1M swap peak: 1.1M) After: $ build/systemctl status -n 0 systemd-networkd.service | grep Memory: Memory: 4.7M (peak: 14.3M, swap: 1M, swap peak: 1.1M) --- src/systemctl/systemctl-show.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 6f3fd76622..335b365be2 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -758,68 +758,68 @@ static void print_status_info( printf(" ("); if (i->memory_min > 0) { printf("%smin: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_min)); - prefix = " "; + prefix = ", "; } if (i->memory_low > 0) { printf("%slow: %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->memory_low)); - prefix = " "; + prefix = ", "; } if (i->startup_memory_low > 0) { printf("%slow (startup): %s", prefix, FORMAT_BYTES_CGROUP_PROTECTION(i->startup_memory_low)); - prefix = " "; + prefix = ", "; } if (i->memory_high != CGROUP_LIMIT_MAX) { printf("%shigh: %s", prefix, FORMAT_BYTES(i->memory_high)); - prefix = " "; + prefix = ", "; } if (i->startup_memory_high != CGROUP_LIMIT_MAX) { printf("%shigh (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_high)); - prefix = " "; + prefix = ", "; } if (i->memory_max != CGROUP_LIMIT_MAX) { printf("%smax: %s", prefix, FORMAT_BYTES(i->memory_max)); - prefix = " "; + prefix = ", "; } if (i->startup_memory_max != CGROUP_LIMIT_MAX) { printf("%smax (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_max)); - prefix = " "; + prefix = ", "; } if (i->memory_swap_max != CGROUP_LIMIT_MAX) { printf("%sswap max: %s", prefix, FORMAT_BYTES(i->memory_swap_max)); - prefix = " "; + prefix = ", "; } if (i->startup_memory_swap_max != CGROUP_LIMIT_MAX) { printf("%sswap max (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_swap_max)); - prefix = " "; + prefix = ", "; } if (i->memory_zswap_max != CGROUP_LIMIT_MAX) { printf("%szswap max: %s", prefix, FORMAT_BYTES(i->memory_zswap_max)); - prefix = " "; + prefix = ", "; } if (i->startup_memory_zswap_max != CGROUP_LIMIT_MAX) { printf("%szswap max (startup): %s", prefix, FORMAT_BYTES(i->startup_memory_zswap_max)); - prefix = " "; + prefix = ", "; } if (i->memory_limit != CGROUP_LIMIT_MAX) { printf("%slimit: %s", prefix, FORMAT_BYTES(i->memory_limit)); - prefix = " "; + prefix = ", "; } if (show_memory_available) { printf("%savailable: %s", prefix, FORMAT_BYTES(i->memory_available)); - prefix = " "; + prefix = ", "; } if (show_memory_peak) { printf("%speak: %s", prefix, FORMAT_BYTES(i->memory_peak)); - prefix = " "; + prefix = ", "; } if (show_memory_swap_peak) { - printf("%sswap: %s swap peak: %s", prefix, + printf("%sswap: %s, swap peak: %s", prefix, FORMAT_BYTES(i->memory_swap_current), FORMAT_BYTES(i->memory_swap_peak)); - prefix = " "; + prefix = ", "; } if (show_memory_zswap_current) { printf("%szswap: %s", prefix, FORMAT_BYTES(i->memory_zswap_current)); - prefix = " "; + prefix = ", "; } printf(")"); } From 0f1a09203ef28ef79a702fb3706ccd1b958c3ebe Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 8 Oct 2024 12:12:25 +0900 Subject: [PATCH 3/5] oomd: drop unused usec_now --- src/oom/oomd-manager.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index a7b0717958..5e25daadcb 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -340,17 +340,12 @@ static int acquire_managed_oom_connect(Manager *m) { static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void *userdata) { Manager *m = ASSERT_PTR(userdata); - usec_t usec_now; int r; assert(s); assert(!hashmap_isempty(m->monitored_swap_cgroup_contexts)); /* Reset timer */ - r = sd_event_now(sd_event_source_get_event(s), CLOCK_MONOTONIC, &usec_now); - if (r < 0) - return log_error_errno(r, "Failed to reset event timer: %m"); - r = sd_event_source_set_time_relative(s, SWAP_INTERVAL_USEC); if (r < 0) return log_error_errno(r, "Failed to set relative time for timer: %m"); From 05314b18233a6f936915aa39c29aef85a402c483 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 8 Oct 2024 12:26:52 +0900 Subject: [PATCH 4/5] oomd: update system context when oomctl is invoked Otherwise, oomctl shows 0 memory and swap usage when swap monitoring is not enabled. ======= $ oomctl Dry Run: no Swap Used Limit: 90.00% Default Memory Pressure Limit: 60.00% Default Memory Pressure Duration: 20s System Context: Memory: Used: 0B Total: 0B Swap: Used: 0B Total: 0B Swap Monitored CGroups: Memory Pressure Monitored CGroups: ... ====== --- src/oom/oomd-manager.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index 5e25daadcb..6ff4d98c32 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -799,10 +799,17 @@ int manager_get_dump_string(Manager *m, char **ret) { _cleanup_(memstream_done) MemStream ms = {}; OomdCGroupContext *c; FILE *f; + int r; assert(m); assert(ret); + /* Always reread memory/swap info here. Otherwise it may be outdated if swap monitoring is off. + * Let's make sure to always report up-to-date data. */ + r = oomd_system_context_acquire("/proc/meminfo", &m->system_context); + if (r < 0) + log_debug_errno(r, "Failed to acquire system context, ignoring: %m"); + f = memstream_init(&ms); if (!f) return -ENOMEM; From e607a7317f602e9bcd87b4ca5cf096035c4fe839 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 8 Oct 2024 12:27:44 +0900 Subject: [PATCH 5/5] oomd: separate entries with comma for readability --- src/oom/oomd-util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c index 69d103e71f..7c08d6714f 100644 --- a/src/oom/oomd-util.c +++ b/src/oom/oomd-util.c @@ -607,7 +607,7 @@ void oomd_dump_memory_pressure_cgroup_context(const OomdCGroupContext *ctx, FILE fprintf(f, "%sPath: %s\n" "%s\tMemory Pressure Limit: %lu.%02lu%%\n" - "%s\tPressure: Avg10: %lu.%02lu Avg60: %lu.%02lu Avg300: %lu.%02lu Total: %s\n" + "%s\tPressure: Avg10: %lu.%02lu, Avg60: %lu.%02lu, Avg300: %lu.%02lu, Total: %s\n" "%s\tCurrent Memory Usage: %s\n", strempty(prefix), ctx->path, strempty(prefix), LOADAVG_INT_SIDE(ctx->mem_pressure_limit), LOADAVG_DECIMAL_SIDE(ctx->mem_pressure_limit), @@ -635,8 +635,8 @@ void oomd_dump_system_context(const OomdSystemContext *ctx, FILE *f, const char assert(f); fprintf(f, - "%sMemory: Used: %s Total: %s\n" - "%sSwap: Used: %s Total: %s\n", + "%sMemory: Used: %s, Total: %s\n" + "%sSwap: Used: %s, Total: %s\n", strempty(prefix), FORMAT_BYTES(ctx->mem_used), FORMAT_BYTES(ctx->mem_total),