From 399d80ba8c604d57e7df6c5118ea3258cce026d9 Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Mon, 8 Mar 2021 10:51:12 -0800 Subject: [PATCH 1/3] oomd: add unit test to repro #18926 --- src/oom/test-oomd-util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/oom/test-oomd-util.c b/src/oom/test-oomd-util.c index a0e583ac6b..0b1a3adfcc 100644 --- a/src/oom/test-oomd-util.c +++ b/src/oom/test-oomd-util.c @@ -150,6 +150,7 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) { assert_se(oomd_insert_cgroup_context(NULL, h1, cgroup) == 0); c1 = hashmap_get(h1, cgroup); assert_se(c1); + assert_se(oomd_insert_cgroup_context(NULL, h1, cgroup) == -EEXIST); /* make sure certain values from h1 get updated in h2 */ c1->pgscan = 5555; From 45da27fa053898c1b94c175070a0dd63128875c9 Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Mon, 8 Mar 2021 10:35:31 -0800 Subject: [PATCH 2/3] oomd: move TAKE_PTR to end of oomd_insert_cgroup_context() Fixes #18926 --- src/oom/oomd-util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c index b054ccacc4..82bc9e2529 100644 --- a/src/oom/oomd-util.c +++ b/src/oom/oomd-util.c @@ -384,7 +384,7 @@ int oomd_system_context_acquire(const char *proc_swaps_path, OomdSystemContext * int oomd_insert_cgroup_context(Hashmap *old_h, Hashmap *new_h, const char *path) { _cleanup_(oomd_cgroup_context_freep) OomdCGroupContext *curr_ctx = NULL; - OomdCGroupContext *old_ctx, *ctx; + OomdCGroupContext *old_ctx; int r; assert(new_h); @@ -401,11 +401,11 @@ int oomd_insert_cgroup_context(Hashmap *old_h, Hashmap *new_h, const char *path) curr_ctx->last_hit_mem_pressure_limit = old_ctx->last_hit_mem_pressure_limit; } - ctx = TAKE_PTR(curr_ctx); - r = hashmap_put(new_h, ctx->path, ctx); + r = hashmap_put(new_h, curr_ctx->path, curr_ctx); if (r < 0) return r; + TAKE_PTR(curr_ctx); return 0; } From 50c0578b619e7298375afdffec7a8b3a40a68c21 Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Mon, 8 Mar 2021 10:21:37 -0800 Subject: [PATCH 3/3] oomd: wrap paths in oomd_insert_cgroup_context with empty_to_root --- src/oom/oomd-manager.c | 2 +- src/oom/oomd-util.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index fad1fb0d45..085fc6487f 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -112,7 +112,7 @@ static int process_managed_oom_reply( continue; } - ret = oomd_insert_cgroup_context(NULL, monitor_hm, empty_to_root(reply.path)); + ret = oomd_insert_cgroup_context(NULL, monitor_hm, reply.path); if (ret == -ENOMEM) { r = ret; goto finish; diff --git a/src/oom/oomd-util.c b/src/oom/oomd-util.c index 82bc9e2529..d8dbb75013 100644 --- a/src/oom/oomd-util.c +++ b/src/oom/oomd-util.c @@ -390,10 +390,14 @@ int oomd_insert_cgroup_context(Hashmap *old_h, Hashmap *new_h, const char *path) assert(new_h); assert(path); + path = empty_to_root(path); + r = oomd_cgroup_context_acquire(path, &curr_ctx); if (r < 0) return log_debug_errno(r, "Failed to get OomdCGroupContext for %s: %m", path); + assert_se(streq(path, curr_ctx->path)); + old_ctx = hashmap_get(old_h, path); if (old_ctx) { curr_ctx->last_pgscan = old_ctx->pgscan;