Merge pull request #4670 from htejun/systemd-controller-on-unified-v2
Systemd controller on unified v2
This commit is contained in:
+16
-22
@@ -678,7 +678,7 @@ static void cgroup_context_apply(Unit *u, CGroupMask mask, ManagerState state) {
|
||||
bool has_weight = cgroup_context_has_cpu_weight(c);
|
||||
bool has_shares = cgroup_context_has_cpu_shares(c);
|
||||
|
||||
if (cg_all_unified() > 0) {
|
||||
if (cg_all_unified()) {
|
||||
uint64_t weight;
|
||||
|
||||
if (has_weight)
|
||||
@@ -858,7 +858,7 @@ static void cgroup_context_apply(Unit *u, CGroupMask mask, ManagerState state) {
|
||||
}
|
||||
|
||||
if ((mask & CGROUP_MASK_MEMORY) && !is_root) {
|
||||
if (cg_all_unified() > 0) {
|
||||
if (cg_all_unified()) {
|
||||
uint64_t max;
|
||||
uint64_t swap_max = CGROUP_LIMIT_MAX;
|
||||
|
||||
@@ -1033,7 +1033,7 @@ CGroupMask unit_get_own_mask(Unit *u) {
|
||||
e = unit_get_exec_context(u);
|
||||
if (!e ||
|
||||
exec_context_maintains_privileges(e) ||
|
||||
cg_all_unified() > 0)
|
||||
cg_all_unified())
|
||||
return _CGROUP_MASK_ALL;
|
||||
}
|
||||
|
||||
@@ -1260,10 +1260,7 @@ int unit_watch_cgroup(Unit *u) {
|
||||
return 0;
|
||||
|
||||
/* Only applies to the unified hierarchy */
|
||||
r = cg_unified(SYSTEMD_CGROUP_CONTROLLER);
|
||||
if (r < 0)
|
||||
return log_unit_error_errno(u, r, "Failed detect whether the unified hierarchy is used: %m");
|
||||
if (r == 0)
|
||||
if (!cg_unified(SYSTEMD_CGROUP_CONTROLLER))
|
||||
return 0;
|
||||
|
||||
/* Don't watch the root slice, it's pointless. */
|
||||
@@ -1683,7 +1680,7 @@ int unit_watch_all_pids(Unit *u) {
|
||||
if (!u->cgroup_path)
|
||||
return -ENOENT;
|
||||
|
||||
if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) > 0) /* On unified we can use proper notifications */
|
||||
if (cg_unified(SYSTEMD_CGROUP_CONTROLLER)) /* On unified we can use proper notifications */
|
||||
return 0;
|
||||
|
||||
return unit_watch_pids_in_path(u, u->cgroup_path);
|
||||
@@ -1756,7 +1753,7 @@ static int on_cgroup_inotify_event(sd_event_source *s, int fd, uint32_t revents,
|
||||
int manager_setup_cgroup(Manager *m) {
|
||||
_cleanup_free_ char *path = NULL;
|
||||
CGroupController c;
|
||||
int r, all_unified, systemd_unified;
|
||||
int r;
|
||||
char *e;
|
||||
|
||||
assert(m);
|
||||
@@ -1793,25 +1790,22 @@ int manager_setup_cgroup(Manager *m) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Cannot find cgroup mount point: %m");
|
||||
|
||||
all_unified = cg_all_unified();
|
||||
systemd_unified = cg_unified(SYSTEMD_CGROUP_CONTROLLER);
|
||||
r = cg_unified_flush();
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Couldn't determine if we are running in the unified hierarchy: %m");
|
||||
|
||||
if (all_unified < 0 || systemd_unified < 0)
|
||||
return log_error_errno(all_unified < 0 ? all_unified : systemd_unified,
|
||||
"Couldn't determine if we are running in the unified hierarchy: %m");
|
||||
|
||||
if (all_unified > 0)
|
||||
if (cg_all_unified())
|
||||
log_debug("Unified cgroup hierarchy is located at %s.", path);
|
||||
else if (systemd_unified > 0)
|
||||
else if (cg_unified(SYSTEMD_CGROUP_CONTROLLER))
|
||||
log_debug("Unified cgroup hierarchy is located at %s. Controllers are on legacy hierarchies.", path);
|
||||
else
|
||||
log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER ". File system hierarchy is at %s.", path);
|
||||
log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER_LEGACY ". File system hierarchy is at %s.", path);
|
||||
|
||||
if (!m->test_run) {
|
||||
const char *scope_path;
|
||||
|
||||
/* 3. Install agent */
|
||||
if (systemd_unified) {
|
||||
if (cg_unified(SYSTEMD_CGROUP_CONTROLLER)) {
|
||||
|
||||
/* In the unified hierarchy we can get
|
||||
* cgroup empty notifications via inotify. */
|
||||
@@ -1871,7 +1865,7 @@ int manager_setup_cgroup(Manager *m) {
|
||||
return log_error_errno(errno, "Failed to open pin file: %m");
|
||||
|
||||
/* 6. Always enable hierarchical support if it exists... */
|
||||
if (!all_unified)
|
||||
if (!cg_all_unified())
|
||||
(void) cg_set_attribute("memory", "/", "memory.use_hierarchy", "1");
|
||||
}
|
||||
|
||||
@@ -1997,7 +1991,7 @@ int unit_get_memory_current(Unit *u, uint64_t *ret) {
|
||||
if ((u->cgroup_realized_mask & CGROUP_MASK_MEMORY) == 0)
|
||||
return -ENODATA;
|
||||
|
||||
if (cg_all_unified() <= 0)
|
||||
if (!cg_all_unified())
|
||||
r = cg_get_attribute("memory", u->cgroup_path, "memory.usage_in_bytes", &v);
|
||||
else
|
||||
r = cg_get_attribute("memory", u->cgroup_path, "memory.current", &v);
|
||||
@@ -2042,7 +2036,7 @@ static int unit_get_cpu_usage_raw(Unit *u, nsec_t *ret) {
|
||||
if (!u->cgroup_path)
|
||||
return -ENODATA;
|
||||
|
||||
if (cg_all_unified() > 0) {
|
||||
if (cg_all_unified()) {
|
||||
const char *keys[] = { "usage_usec", NULL };
|
||||
_cleanup_free_ char *val = NULL;
|
||||
uint64_t us;
|
||||
|
||||
+1
-1
@@ -776,7 +776,7 @@ static int manager_setup_cgroups_agent(Manager *m) {
|
||||
if (!MANAGER_IS_SYSTEM(m))
|
||||
return 0;
|
||||
|
||||
if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) > 0) /* We don't need this anymore on the unified hierarchy */
|
||||
if (cg_unified(SYSTEMD_CGROUP_CONTROLLER)) /* We don't need this anymore on the unified hierarchy */
|
||||
return 0;
|
||||
|
||||
if (m->cgroups_agent_fd < 0) {
|
||||
|
||||
@@ -96,15 +96,15 @@ static const MountPoint mount_table[] = {
|
||||
{ "tmpfs", "/run", "tmpfs", "mode=755", MS_NOSUID|MS_NODEV|MS_STRICTATIME,
|
||||
NULL, MNT_FATAL|MNT_IN_CONTAINER },
|
||||
{ "cgroup", "/sys/fs/cgroup", "cgroup2", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||
cg_is_unified_wanted, MNT_FATAL|MNT_IN_CONTAINER },
|
||||
cg_is_unified_wanted, MNT_IN_CONTAINER },
|
||||
{ "tmpfs", "/sys/fs/cgroup", "tmpfs", "mode=755", MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME,
|
||||
cg_is_legacy_wanted, MNT_FATAL|MNT_IN_CONTAINER },
|
||||
{ "cgroup", "/sys/fs/cgroup/systemd", "cgroup2", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||
cg_is_unified_systemd_controller_wanted, MNT_IN_CONTAINER },
|
||||
{ "cgroup", "/sys/fs/cgroup/unified", "cgroup2", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||
cg_is_hybrid_wanted, MNT_IN_CONTAINER },
|
||||
{ "cgroup", "/sys/fs/cgroup/systemd", "cgroup", "none,name=systemd,xattr", MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||
cg_is_legacy_systemd_controller_wanted, MNT_IN_CONTAINER },
|
||||
cg_is_legacy_wanted, MNT_IN_CONTAINER },
|
||||
{ "cgroup", "/sys/fs/cgroup/systemd", "cgroup", "none,name=systemd", MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||
cg_is_legacy_systemd_controller_wanted, MNT_FATAL|MNT_IN_CONTAINER },
|
||||
cg_is_legacy_wanted, MNT_FATAL|MNT_IN_CONTAINER },
|
||||
{ "pstore", "/sys/fs/pstore", "pstore", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||
NULL, MNT_NONE },
|
||||
#ifdef ENABLE_EFI
|
||||
|
||||
+1
-1
@@ -475,7 +475,7 @@ static void scope_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
|
||||
/* If the PID set is empty now, then let's finish this off
|
||||
(On unified we use proper notifications) */
|
||||
if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) <= 0 && set_isempty(u->pids))
|
||||
if (!cg_unified(SYSTEMD_CGROUP_CONTROLLER) && set_isempty(u->pids))
|
||||
scope_notify_cgroup_empty_event(u);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2938,7 +2938,7 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
|
||||
/* If the PID set is empty now, then let's finish this off
|
||||
(On unified we use proper notifications) */
|
||||
if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) <= 0 && set_isempty(u->pids))
|
||||
if (!cg_unified(SYSTEMD_CGROUP_CONTROLLER) && set_isempty(u->pids))
|
||||
service_notify_cgroup_empty_event(u);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -3897,8 +3897,8 @@ int unit_kill_context(
|
||||
* there we get proper events. Hence rely on
|
||||
* them.*/
|
||||
|
||||
if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) > 0 ||
|
||||
(detect_container() == 0 && !unit_cgroup_delegate(u)))
|
||||
if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) ||
|
||||
(detect_container() == 0 && !unit_cgroup_delegate(u)))
|
||||
wait_for_exit = true;
|
||||
|
||||
if (send_sighup) {
|
||||
|
||||
Reference in New Issue
Block a user