From 2747cd6d17039b6c384faacd3563716a14063509 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 9 Dec 2023 20:19:57 +0800 Subject: [PATCH] systemctl-show: always show memory peak if available --- src/systemctl/systemctl-show.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 963ba69ab6e..c74bcf2642e 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -703,17 +703,19 @@ static void print_status_info( if (i->n_fd_store > 0 || i->fd_store_max > 0) printf(" FD Store: %u%s (limit: %u)%s\n", i->n_fd_store, ansi_grey(), i->fd_store_max, ansi_normal()); + bool show_memory_peak = i->memory_peak != CGROUP_LIMIT_MAX, + show_memory_swap_peak = !IN_SET(i->memory_swap_peak, 0, CGROUP_LIMIT_MAX); + 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_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), + 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; - if (i->memory_peak != CGROUP_LIMIT_MAX || - show_memory_swap || + if (show_memory_peak || + show_memory_swap_peak || show_memory_zswap_current || show_memory_available || i->memory_min > 0 || @@ -779,11 +781,11 @@ static void print_status_info( printf("%savailable: %s", prefix, FORMAT_BYTES(i->memory_available)); prefix = " "; } - if (i->memory_peak != CGROUP_LIMIT_MAX) { + if (show_memory_peak) { printf("%speak: %s", prefix, FORMAT_BYTES(i->memory_peak)); prefix = " "; } - if (show_memory_swap) { + if (show_memory_swap_peak) { printf("%sswap: %s swap peak: %s", prefix, FORMAT_BYTES(i->memory_swap_current), FORMAT_BYTES(i->memory_swap_peak)); prefix = " "; @@ -795,6 +797,14 @@ static void print_status_info( printf(")"); } printf("\n"); + + } else if (show_memory_peak) { + printf(" Mem peak: %s", FORMAT_BYTES(i->memory_peak)); + + if (show_memory_swap_peak) + printf(" (swap: %s)", FORMAT_BYTES(i->memory_swap_peak)); + + putchar('\n'); } if (i->cpu_usage_nsec != UINT64_MAX) -- 2.47.3