From f26b2ec46118a4493608618da2253bb9dfc6b517 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Wed, 5 Jun 2024 20:45:12 +0200 Subject: [PATCH] core: do not set up cgroup runtime on coldplug Currently, unit_setup_cgroup_runtime() is called in various _coldplug() functions if the unit is not inactive. That seems unnecessary though, and kinda defeats the purpose of CGroupRuntime. If we need to fork off a process for the unit or got something during deserialization, the CGroupRuntime would be automatically set up by unit_prepare_exec() / cgroup_runtime_deserialize_one(). Otherwise it would mean the cgroup doesn't exist and we don't need to allocate that in the first place. Plus, note that socket units might also carry a cgroup with ExecStartPre=/ExecStartPost=/... Hence the existing code is really inconsistent. --- src/core/mount.c | 4 +--- src/core/service.c | 1 - src/core/swap.c | 4 +--- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index c6100b0b0a0..e040f151f42 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -764,10 +764,8 @@ static int mount_coldplug(Unit *u) { return r; } - if (!IN_SET(m->deserialized_state, MOUNT_DEAD, MOUNT_FAILED)) { + if (!IN_SET(m->deserialized_state, MOUNT_DEAD, MOUNT_FAILED)) (void) unit_setup_exec_runtime(u); - (void) unit_setup_cgroup_runtime(u); - } mount_set_state(m, m->deserialized_state); return 0; diff --git a/src/core/service.c b/src/core/service.c index 937729cd068..9af10df0cd8 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1366,7 +1366,6 @@ static int service_coldplug(Unit *u) { SERVICE_DEAD_RESOURCES_PINNED)) { (void) unit_enqueue_rewatch_pids(u); (void) unit_setup_exec_runtime(u); - (void) unit_setup_cgroup_runtime(u); } if (IN_SET(s->deserialized_state, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD, SERVICE_RELOAD_SIGNAL, SERVICE_RELOAD_NOTIFY)) diff --git a/src/core/swap.c b/src/core/swap.c index c4d2ba8f3ac..e6f6f78dc9c 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -548,10 +548,8 @@ static int swap_coldplug(Unit *u) { return r; } - if (!IN_SET(new_state, SWAP_DEAD, SWAP_FAILED)) { + if (!IN_SET(new_state, SWAP_DEAD, SWAP_FAILED)) (void) unit_setup_exec_runtime(u); - (void) unit_setup_cgroup_runtime(u); - } swap_set_state(s, new_state); return 0; -- 2.47.3