]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: move where we send unit change updates to oomd
authorAnita Zhang <the.anitazha@gmail.com>
Mon, 19 Oct 2020 08:44:17 +0000 (01:44 -0700)
committerAnita Zhang <the.anitazha@gmail.com>
Mon, 19 Oct 2020 09:46:07 +0000 (02:46 -0700)
Post-merge suggestion from #15206

src/core/load-fragment-gperf.gperf.m4
src/core/load-fragment.c
src/core/unit.c

index a22695d9245457021dce96b9c0b5d3d6f646113d..b5ccf62ae09124bc4dbc41888dddc6d8a5447d18 100644 (file)
@@ -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)
index 9361e930515b8e67d04e5e8461e4805e6e6e7346..60c9a5f03a94fed093a1f1521c2eb45add4b9ff5 100644 (file)
@@ -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;
 }
 
index fd73ad2949fade026f5657b068a4c684b1d2fa89..0cd45b33bbe5b8c583b0aecad7d7c067cd55bf2f 100644 (file)
@@ -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);
         }