From: Florian Schmaus Date: Tue, 21 Nov 2023 08:10:10 +0000 (+0100) Subject: systemctl-show: only show available memory if it was artifically limited X-Git-Tag: v255-rc3~27 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f380473edfa899706d630bb64750ab50c5c04961;p=thirdparty%2Fsystemd.git systemctl-show: only show available memory if it was artifically limited Systemd 255 changed the semantic of MemoryAvailable with 3565c709f587 ("cgroup: Fix MemoryAvailable= by considering physical memory"). If there is no artificial constraint, it will hold the amount of available physical memory, while it previously contained UINT64_MAX. While the change in MemoryAvailable's semantic is sensible, it causes `systemctl status` to always display the available physical memory. This creates a lot of noise, especially since systemd recently started to also show the "peak" memory. For example $ systemctl status foo … Memory: 3.9G (available: 21.2G peak: 5.4G) … However, while peak memory is a unit specific value, the available memory, when not derived from artificial memory limits, is a generic property that holds the same value for all units that are not under memory accounting constraints. Displaying it under those circumstances can therefore be considered being noisy. Before 3565c709f587 ("cgroup: Fix MemoryAvailable= by considering physical memory") "systemctl status" would only show the available memory if it was caused by a explicit memory limitation due to MemoryHigh or MemoryMax. This commit restores this behavior by supressing displaying the available memory if is is merely the available phyiscal memory. For example $ systemctl status foo … Memory: 3.9G (peak: 5.4G) … Fixes #30102. --- diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index de3d8a3cdcc..7c5bf1e6792 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -707,12 +707,15 @@ static void print_status_info( printf(" Memory: %s", FORMAT_BYTES(i->memory_current)); /* Only show current swap if it ever was non-zero or is currently non-zero. In both cases - memory_swap_peak will be non-zero (and not CGROUP_LIMIT_MAX). */ + memory_swap_peak will be non-zero (and not CGROUP_LIMIT_MAX). + Only show the available memory if it was artifically limited. */ bool show_memory_swap = !IN_SET(i->memory_swap_peak, 0, CGROUP_LIMIT_MAX), - show_memory_zswap_current = !IN_SET(i->memory_zswap_current, 0, CGROUP_LIMIT_MAX); + show_memory_zswap_current = !IN_SET(i->memory_zswap_current, 0, CGROUP_LIMIT_MAX), + show_memory_available = i->memory_high != CGROUP_LIMIT_MAX || i->memory_max != CGROUP_LIMIT_MAX; if (i->memory_peak != CGROUP_LIMIT_MAX || show_memory_swap || show_memory_zswap_current || + show_memory_available || i->memory_min > 0 || i->memory_low > 0 || i->startup_memory_low > 0 || i->memory_high != CGROUP_LIMIT_MAX || i->startup_memory_high != CGROUP_LIMIT_MAX || @@ -772,7 +775,7 @@ static void print_status_info( printf("%slimit: %s", prefix, FORMAT_BYTES(i->memory_limit)); prefix = " "; } - if (i->memory_available != CGROUP_LIMIT_MAX) { + if (show_memory_available) { printf("%savailable: %s", prefix, FORMAT_BYTES(i->memory_available)); prefix = " "; }