From f561e8c659f9f3d8c06ab0b28440bc9f2822f29c Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Mon, 19 Oct 2020 01:44:17 -0700 Subject: [PATCH] core: move where we send unit change updates to oomd Post-merge suggestion from #15206 --- src/core/load-fragment-gperf.gperf.m4 | 2 +- src/core/load-fragment.c | 20 +++++--------------- src/core/unit.c | 3 ++- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4 index a22695d9245..b5ccf62ae09 100644 --- a/src/core/load-fragment-gperf.gperf.m4 +++ b/src/core/load-fragment-gperf.gperf.m4 @@ -226,7 +226,7 @@ $1.IPIngressFilterPath, config_parse_ip_filter_bpf_progs, $1.IPEgressFilterPath, config_parse_ip_filter_bpf_progs, 0, offsetof($1, cgroup_context.ip_filters_egress) $1.ManagedOOMSwap, config_parse_managed_oom_mode, 0, offsetof($1, cgroup_context.moom_swap) $1.ManagedOOMMemoryPressure, config_parse_managed_oom_mode, 0, offsetof($1, cgroup_context.moom_mem_pressure) -$1.ManagedOOMMemoryPressureLimitPercent, config_parse_managed_oom_mem_pressure_limit, 0, offsetof($1, cgroup_context) +$1.ManagedOOMMemoryPressureLimitPercent, config_parse_managed_oom_mem_pressure_limit, 0, offsetof($1, cgroup_context.moom_mem_pressure_limit) $1.NetClass, config_parse_warn_compat, DISABLED_LEGACY, 0' )m4_dnl Unit.Description, config_parse_unit_string_printf, 0, offsetof(Unit, description) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 9361e930515..60c9a5f03a9 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -3824,7 +3824,6 @@ int config_parse_managed_oom_mode( const char *rvalue, void *data, void *userdata) { - Unit *u = userdata; ManagedOOMMode *mode = data, m; UnitType t; @@ -3836,7 +3835,7 @@ int config_parse_managed_oom_mode( if (isempty(rvalue)) { *mode = MANAGED_OOM_AUTO; - goto finish; + return 0; } m = managed_oom_mode_from_string(rvalue); @@ -3845,9 +3844,6 @@ int config_parse_managed_oom_mode( return 0; } *mode = m; - -finish: - (void) manager_varlink_send_managed_oom_update(u); return 0; } @@ -3862,8 +3858,7 @@ int config_parse_managed_oom_mem_pressure_limit( const char *rvalue, void *data, void *userdata) { - Unit *u = userdata; - CGroupContext *c = data; + int *limit = data; UnitType t; int r; @@ -3874,8 +3869,8 @@ int config_parse_managed_oom_mem_pressure_limit( return log_syntax(unit, LOG_WARNING, filename, line, 0, "%s= is not supported for this unit type, ignoring.", lvalue); if (isempty(rvalue)) { - c->moom_mem_pressure_limit = 0; - goto finish; + *limit = 0; + return 0; } r = parse_percent(rvalue); @@ -3884,12 +3879,7 @@ int config_parse_managed_oom_mem_pressure_limit( return 0; } - c->moom_mem_pressure_limit = r; - -finish: - /* Only update the limit if memory pressure detection is enabled because the information is irrelevant otherwise */ - if (c->moom_mem_pressure == MANAGED_OOM_KILL) - (void) manager_varlink_send_managed_oom_update(u); + *limit = r; return 0; } diff --git a/src/core/unit.c b/src/core/unit.c index fd73ad2949f..0cd45b33bbe 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1684,6 +1684,7 @@ int unit_load(Unit *u) { unit_add_to_dbus_queue(unit_follow_merge(u)); unit_add_to_gc_queue(u); + (void) manager_varlink_send_managed_oom_update(u); return 0; @@ -2630,7 +2631,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlag * sets one of the ManagedOOM*= properties to "kill", then later removes it. systemd-oomd needs to * know to stop monitoring when the unit changes from "kill" -> "auto" on daemon-reload, but we don't * have the information on the property. Thus, indiscriminately send an update. */ - if (UNIT_IS_INACTIVE_OR_FAILED(ns) || ns == UNIT_ACTIVE) + if (UNIT_IS_INACTIVE_OR_FAILED(ns) || UNIT_IS_ACTIVE_OR_RELOADING(ns)) (void) manager_varlink_send_managed_oom_update(u); }