From: Yu Watanabe Date: Sat, 12 Oct 2024 01:36:02 +0000 (+0900) Subject: oomctl: sort contexts with cgroup path X-Git-Tag: v257-rc1~226^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c678159f2eed72fd3a5a908ba0f61f63234db6da;p=thirdparty%2Fsystemd.git oomctl: sort contexts with cgroup path --- diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index 6ff4d98c32d..33e9f288b41 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -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); } diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c index 7c08d6714f0..b0b13d6c3c4 100644 --- a/src/oom/oomd-util.c +++ b/src/oom/oomd-util.c @@ -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);