summaryrefslogtreecommitdiff
path: root/src/core/cgroup.c
diff options
context:
space:
mode:
authorPeter Morrow <pemorrow@linux.microsoft.com>2021-09-16 12:21:20 +0100
committerPeter Morrow <pemorrow@linux.microsoft.com>2021-09-24 14:43:01 +0100
commit9dfb6a3a8e1183a7988691377fe7bf747ff38bc0 (patch)
treef64c22ecc629d85cb7672c093fcc056bf04ad300 /src/core/cgroup.c
parent37eb7108fbe67550e92ed97e092fc0507bd4b4b1 (diff)
downloadsystemd-9dfb6a3a8e1183a7988691377fe7bf747ff38bc0.tar.gz
cgroup: re-evaluate startup units during shutdown as well
Apply startup cgroup configuration options to the shutdown phase as well. I.e. all directives prefixed with Startup are applied during boot and shutdown. For example: StartupAllowedCPU= applies during boot and shutdown. AllowedCPUs= applies during normal runtime.
Diffstat (limited to 'src/core/cgroup.c')
-rw-r--r--src/core/cgroup.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 17e93d7af1..c19454e8bd 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -68,6 +68,25 @@ bool manager_owns_host_root_cgroup(Manager *m) {
return empty_or_root(m->cgroup_root);
}
+bool unit_has_startup_cgroup_constraints(Unit *u) {
+ assert(u);
+
+ /* Returns true if this unit has any directives which apply during
+ * startup/shutdown phases. */
+
+ CGroupContext *c;
+
+ c = unit_get_cgroup_context(u);
+ if (!c)
+ return false;
+
+ return c->startup_cpu_shares != CGROUP_CPU_SHARES_INVALID ||
+ c->startup_io_weight != CGROUP_WEIGHT_INVALID ||
+ c->startup_blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID ||
+ c->startup_cpuset_cpus.set ||
+ c->startup_cpuset_mems.set;
+}
+
bool unit_has_host_root_cgroup(Unit *u) {
assert(u);
@@ -844,7 +863,7 @@ static bool cgroup_context_has_allowed_mems(CGroupContext *c) {
}
static uint64_t cgroup_context_cpu_weight(CGroupContext *c, ManagerState state) {
- if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING) &&
+ if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) &&
c->startup_cpu_weight != CGROUP_WEIGHT_INVALID)
return c->startup_cpu_weight;
else if (c->cpu_weight != CGROUP_WEIGHT_INVALID)
@@ -854,7 +873,7 @@ static uint64_t cgroup_context_cpu_weight(CGroupContext *c, ManagerState state)
}
static uint64_t cgroup_context_cpu_shares(CGroupContext *c, ManagerState state) {
- if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING) &&
+ if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) &&
c->startup_cpu_shares != CGROUP_CPU_SHARES_INVALID)
return c->startup_cpu_shares;
else if (c->cpu_shares != CGROUP_CPU_SHARES_INVALID)
@@ -864,7 +883,7 @@ static uint64_t cgroup_context_cpu_shares(CGroupContext *c, ManagerState state)
}
static CPUSet *cgroup_context_allowed_cpus(CGroupContext *c, ManagerState state) {
- if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING) &&
+ if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) &&
c->startup_cpuset_cpus.set)
return &c->startup_cpuset_cpus;
else
@@ -872,7 +891,7 @@ static CPUSet *cgroup_context_allowed_cpus(CGroupContext *c, ManagerState state)
}
static CPUSet *cgroup_context_allowed_mems(CGroupContext *c, ManagerState state) {
- if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING) &&
+ if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) &&
c->startup_cpuset_mems.set)
return &c->startup_cpuset_mems;
else
@@ -993,7 +1012,7 @@ static bool cgroup_context_has_blockio_config(CGroupContext *c) {
}
static uint64_t cgroup_context_io_weight(CGroupContext *c, ManagerState state) {
- if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING) &&
+ if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) &&
c->startup_io_weight != CGROUP_WEIGHT_INVALID)
return c->startup_io_weight;
else if (c->io_weight != CGROUP_WEIGHT_INVALID)
@@ -1003,7 +1022,7 @@ static uint64_t cgroup_context_io_weight(CGroupContext *c, ManagerState state) {
}
static uint64_t cgroup_context_blkio_weight(CGroupContext *c, ManagerState state) {
- if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING) &&
+ if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) &&
c->startup_blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID)
return c->startup_blockio_weight;
else if (c->blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID)
@@ -3971,7 +3990,7 @@ void manager_invalidate_startup_units(Manager *m) {
assert(m);
SET_FOREACH(u, m->startup_units)
- unit_invalidate_cgroup(u, CGROUP_MASK_CPU|CGROUP_MASK_IO|CGROUP_MASK_BLKIO);
+ unit_invalidate_cgroup(u, CGROUP_MASK_CPU|CGROUP_MASK_IO|CGROUP_MASK_BLKIO|CGROUP_MASK_CPUSET);
}
static int unit_get_nice(Unit *u) {