]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/cgroup: cache the last memory usage values before destroying cgroup
authorMike Yuan <me@yhndnzj.com>
Sat, 9 Dec 2023 12:10:31 +0000 (20:10 +0800)
committerMike Yuan <me@yhndnzj.com>
Sat, 9 Dec 2023 12:42:48 +0000 (20:42 +0800)
Currently, memory accounting values are only cached if it was queued
at least once before destroying cgroup. Let's always cache it like
what we already do for CPU usage.

Preparation for later changes.

src/core/cgroup.c

index 61ac4df1a65ce421cdc919a0f6805f7eac036dc6..5e66ef76b55909c2058ed0656fa1e81864759884 100644 (file)
@@ -3131,7 +3131,11 @@ void unit_prune_cgroup(Unit *u) {
         if (!u->cgroup_path)
                 return;
 
-        (void) unit_get_cpu_usage(u, NULL); /* Cache the last CPU usage value before we destroy the cgroup */
+        /* Cache the last CPU and memory usage values before we destroy the cgroup */
+        (void) unit_get_cpu_usage(u, /* ret = */ NULL);
+
+        for (CGroupMemoryAccountingMetric metric = 0; metric <= _CGROUP_MEMORY_ACCOUNTING_METRIC_CACHED_LAST; metric++)
+                (void) unit_get_memory_accounting(u, metric, /* ret = */ NULL);
 
 #if BPF_FRAMEWORK
         (void) lsm_bpf_cleanup(u); /* Remove cgroup from the global LSM BPF map */