The root row in systemd-cgtop previously displayed whole-system RAM
usage read from /proc/meminfo (MemTotal - MemAvailable), not a cgroup
sum. This is a pragmatic fallback — the kernel intentionally does not
expose memory.current on the v2 root cgroup (see the existing
is_root_cgroup() comment about avoiding 'multiple truth about system
state'), so cgtop picked /proc/meminfo to fill the gap.
Nevertheless, that caued the '/' row to provide different information
than every other row in the table:
- All child rows: 'what is this cgroup charged for?' (anon + file
+ sock + shmem attributable to the cgroup).
- Root row: 'what is the whole system using?' (includes kernel
slab, vmalloc, pagetables, zram mem_used, and anything not
attributable to any cgroup).
On a typical desktop the root row can read ~10 GB while the sum of
direct children is ~5 GB, with no explanation visible in the tool
itself.
This commit:
1. Introduces --root-memory= command line option.
2. Flips the default for the root row to the sum of memory.current
over its direct children.
3. Adds a '/' interactive key that toggles between the two modes.
4. Updates the interactive help string ('?' / 'h'), the man page,
and the bash completion for the new option.
Inside a container (detect_container() > 0), is_root_cgroup() already
returns false, so none of this applies — the container's '/' still
reads memory.current from the namespaced cgroup as before.
Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>