From 8f9acf8e10e398c982d3372b686f5bcdc1ca966a Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Thu, 9 May 2024 01:12:17 +0800 Subject: [PATCH] systemctl-show: make show_memory_available cover memory_available itself Follow-up for f380473edfa899706d630bb64750ab50c5c04961 This cleans up the code a bit. Also, before this commit, if MemoryAvailable is set but show_memory_available is false, and we have nothing else to output, empty parenthesis is shown. This can be easily reproduced on -.slice: > systemctl status -- -.slice > ... > Memory: 1.8G () > ... --- src/systemctl/systemctl-show.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index aee839de4ca..74d6465739d 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -714,13 +714,12 @@ static void print_status_info( if (i->memory_current != UINT64_MAX) { 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). - Only show the available memory if it was artificially limited. */ bool 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; + /* Only show the available memory if it was artificially limited. */ + show_memory_available = i->memory_available != CGROUP_LIMIT_MAX && + (i->memory_high != CGROUP_LIMIT_MAX || i->memory_max != CGROUP_LIMIT_MAX); if (show_memory_peak || - show_memory_swap_peak || + show_memory_swap_peak || /* We don't need to check memory_swap_current, as if peak is 0 that must also be 0 */ show_memory_zswap_current || show_memory_available || i->memory_min > 0 || @@ -729,7 +728,6 @@ static void print_status_info( i->memory_max != CGROUP_LIMIT_MAX || i->startup_memory_max != CGROUP_LIMIT_MAX || i->memory_swap_max != CGROUP_LIMIT_MAX || i->startup_memory_swap_max != CGROUP_LIMIT_MAX || i->memory_zswap_max != CGROUP_LIMIT_MAX || i->startup_memory_zswap_max != CGROUP_LIMIT_MAX || - i->memory_available != CGROUP_LIMIT_MAX || i->memory_limit != CGROUP_LIMIT_MAX) { const char *prefix = ""; -- 2.47.3