]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl-show: make show_memory_available cover memory_available itself
authorMike Yuan <me@yhndnzj.com>
Wed, 8 May 2024 17:12:17 +0000 (01:12 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 8 May 2024 19:20:05 +0000 (21:20 +0200)
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

index aee839de4cae1d4f4fba64c767f3e09da62fc2e7..74d6465739dda2d4da2d86c0524c5d96352a9831 100644 (file)
@@ -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 = "";