]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
oomctl: sort contexts with cgroup path
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Oct 2024 01:36:02 +0000 (10:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Oct 2024 20:45:04 +0000 (05:45 +0900)
src/oom/oomd-manager.c
src/oom/oomd-util.c

index 6ff4d98c32db4497a6fd088395f04c59da102868..33e9f288b41170e3aeb5a843f8d260e58a753ce1 100644 (file)
@@ -797,7 +797,8 @@ int manager_start(
 
 int manager_get_dump_string(Manager *m, char **ret) {
         _cleanup_(memstream_done) MemStream ms = {};
-        OomdCGroupContext *c;
+        _cleanup_free_ OomdCGroupContext **sorted = NULL;
+        size_t n;
         FILE *f;
         int r;
 
@@ -826,13 +827,22 @@ int manager_get_dump_string(Manager *m, char **ret) {
                 FORMAT_TIMESPAN(m->default_mem_pressure_duration_usec, USEC_PER_SEC));
         oomd_dump_system_context(&m->system_context, f, "\t");
 
+        r = hashmap_dump_sorted(m->monitored_swap_cgroup_contexts, (void***) &sorted, &n);
+        if (r < 0)
+                return r;
+
         fprintf(f, "Swap Monitored CGroups:\n");
-        HASHMAP_FOREACH(c, m->monitored_swap_cgroup_contexts)
-                oomd_dump_swap_cgroup_context(c, f, "\t");
+        FOREACH_ARRAY(c, sorted, n)
+                oomd_dump_swap_cgroup_context(*c, f, "\t");
+
+        sorted = mfree(sorted);
+        r = hashmap_dump_sorted(m->monitored_mem_pressure_cgroup_contexts, (void***) &sorted, &n);
+        if (r < 0)
+                return r;
 
         fprintf(f, "Memory Pressure Monitored CGroups:\n");
-        HASHMAP_FOREACH(c, m->monitored_mem_pressure_cgroup_contexts)
-                oomd_dump_memory_pressure_cgroup_context(c, f, "\t");
+        FOREACH_ARRAY(c, sorted, n)
+                oomd_dump_memory_pressure_cgroup_context(*c, f, "\t");
 
         return memstream_finalize(&ms, ret, NULL);
 }
index 7c08d6714f050e708fe31b816fa6378b87e3ece0..b0b13d6c3c4581fb25af835ed555c3fece8146d0 100644 (file)
@@ -21,8 +21,8 @@
 DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
                 oomd_cgroup_ctx_hash_ops,
                 char,
-                string_hash_func,
-                string_compare_func,
+                path_hash_func,
+                path_compare,
                 OomdCGroupContext,
                 oomd_cgroup_context_free);