summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d4ce839)
A following patch will update cgroup handling so that the elogind controller
(/sys/fs/cgroup/elogind) can use the unified hierarchy even if the kernel
resource controllers are on the legacy hierarchies. This would require
distinguishing whether all controllers are on cgroup v2 or only the elogind
controller is. In preparation, this patch renames cg_unified() to
cg_all_unified().
This patch doesn't cause any functional changes.
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
if (unified)
if (unified < 0)
return unified;
if (unified)
assert(path);
assert(pid >= 0);
assert(path);
assert(pid >= 0);
- if (controller) {
- if (!cg_controller_is_valid(controller))
- return -EINVAL;
- } else
- controller = SYSTEMD_CGROUP_CONTROLLER;
-
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
if (unified < 0)
return unified;
+ if (unified == 0) {
+ if (controller) {
+ if (!cg_controller_is_valid(controller))
+ return -EINVAL;
+ } else
+ controller = SYSTEMD_CGROUP_CONTROLLER;
+
fs = procfs_file_alloca(pid, "cgroup");
log_debug_elogind("Searching for PID %u in \"%s\" (controller \"%s\")",
fs = procfs_file_alloca(pid, "cgroup");
log_debug_elogind("Searching for PID %u in \"%s\" (controller \"%s\")",
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
if (unified) /* doesn't apply to unified hierarchy */
if (unified < 0)
return unified;
if (unified) /* doesn't apply to unified hierarchy */
_cleanup_free_ char *fs = NULL;
int r, unified;
_cleanup_free_ char *fs = NULL;
int r, unified;
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
if (unified) /* Doesn't apply to unified hierarchy */
if (unified < 0)
return unified;
if (unified) /* Doesn't apply to unified hierarchy */
if (controller && (isempty(path) || path_equal(path, "/")))
return false;
if (controller && (isempty(path) || path_equal(path, "/")))
return false;
- unified = cg_unified(controller);
+ unified = cg_all_unified();
if (unified < 0)
return unified;
if (unified < 0)
return unified;
-static thread_local CGroupUnified unified_cache = CGROUP_UNIFIED_UNKNOWN;
-
-static int cg_update_unified(void) {
+static thread_local int unified_cache = -1;
+int cg_all_unified(void) {
struct statfs fs;
/* Checks if we support the unified hierarchy. Returns an
struct statfs fs;
/* Checks if we support the unified hierarchy. Returns an
* have any other trouble determining if the unified hierarchy
* is supported. */
* have any other trouble determining if the unified hierarchy
* is supported. */
- if (unified_cache >= CGROUP_UNIFIED_NONE)
- return 0;
+ if (unified_cache >= 0)
+ return unified_cache;
if (statfs("/sys/fs/cgroup/", &fs) < 0)
return -errno;
#if 0 /// UNNEEDED by elogind
if (F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC))
if (statfs("/sys/fs/cgroup/", &fs) < 0)
return -errno;
#if 0 /// UNNEEDED by elogind
if (F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC))
- unified_cache = CGROUP_UNIFIED_ALL;
- else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC)) {
#else
/* elogind can not support the unified hierarchy as a controller,
* so always assume a classical hierarchy.
#else
/* elogind can not support the unified hierarchy as a controller,
* so always assume a classical hierarchy.
* add such a support. */
if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC)) {
#endif // 0
* add such a support. */
if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC)) {
#endif // 0
- if (statfs("/sys/fs/cgroup/systemd/", &fs) < 0)
- return -errno;
-
- unified_cache = F_TYPE_EQUAL(fs.f_type, CGROUP2_SUPER_MAGIC) ?
- CGROUP_UNIFIED_SYSTEMD : CGROUP_UNIFIED_NONE;
- } else
- return -ENOMEDIUM;
-
- return 0;
-}
-
-int cg_unified(const char *controller) {
-
- int r;
-
- r = cg_update_unified();
- if (r < 0)
- return r;
-
- if (streq_ptr(controller, SYSTEMD_CGROUP_CONTROLLER))
- return unified_cache >= CGROUP_UNIFIED_SYSTEMD;
+ unified_cache = true;
+ else if (F_TYPE_EQUAL(fs.f_type, TMPFS_MAGIC))
+ unified_cache = false;
- return unified_cache >= CGROUP_UNIFIED_ALL;
-}
-
-int cg_all_unified(void) {
- return cg_unified(NULL);
}
#if 0 /// UNNEEDED by elogind
void cg_unified_flush(void) {
}
#if 0 /// UNNEEDED by elogind
void cg_unified_flush(void) {
- unified_cache = CGROUP_UNIFIED_UNKNOWN;
}
int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p) {
}
int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p) {
-typedef enum CGroupUnified {
- CGROUP_UNIFIED_UNKNOWN = -1,
- CGROUP_UNIFIED_NONE = 0, /* Both systemd and controllers on legacy */
- CGROUP_UNIFIED_SYSTEMD = 1, /* Only systemd on unified */
- CGROUP_UNIFIED_ALL = 2, /* Both systemd and controllers on unified */
-} CGroupUnified;
-
#if 0 /// UNNEEDED by elogind
int cg_all_unified(void);
#if 0 /// UNNEEDED by elogind
int cg_all_unified(void);
-int cg_unified(const char *controller);
void cg_unified_flush(void);
bool cg_is_unified_wanted(void);
#endif // 0
bool cg_is_legacy_wanted(void);
void cg_unified_flush(void);
bool cg_is_unified_wanted(void);
#endif // 0
bool cg_is_legacy_wanted(void);
-bool cg_is_unified_systemd_controller_wanted(void);
const char* cgroup_controller_to_string(CGroupController c) _const_;
CGroupController cgroup_controller_from_string(const char *s) _pure_;
const char* cgroup_controller_to_string(CGroupController c) _const_;
CGroupController cgroup_controller_from_string(const char *s) _pure_;
return 0;
/* Only applies to the unified hierarchy */
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 (r < 0)
return log_unit_error_errno(u, r, "Failed detect whether the unified hierarchy is used: %m");
if (r == 0)
if (!u->cgroup_path)
return -ENOENT;
if (!u->cgroup_path)
return -ENOENT;
- if (cg_unified(SYSTEMD_CGROUP_CONTROLLER) > 0) /* On unified we can use proper notifications */
+ if (cg_all_unified() > 0) /* On unified we can use proper notifications */
return 0;
return unit_watch_pids_in_path(u, u->cgroup_path);
return 0;
return unit_watch_pids_in_path(u, u->cgroup_path);
int manager_setup_cgroup(Manager *m) {
_cleanup_free_ char *path = NULL;
CGroupController c;
int manager_setup_cgroup(Manager *m) {
_cleanup_free_ char *path = NULL;
CGroupController c;
- int r, all_unified, systemd_unified;
if (r < 0)
return log_error_errno(r, "Cannot find cgroup mount point: %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);
-
- 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)
+ unified = cg_all_unified();
+ if (unified < 0)
+ return log_error_errno(r, "Couldn't determine if we are running in the unified hierarchy: %m");
+ if (unified > 0)
log_debug("Unified cgroup hierarchy is located at %s.", path);
log_debug("Unified cgroup hierarchy is located at %s.", path);
- else if (systemd_unified > 0)
- 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);
else
log_debug("Using cgroup controller " SYSTEMD_CGROUP_CONTROLLER ". File system hierarchy is at %s.", path);
const char *scope_path;
/* 3. Install agent */
const char *scope_path;
/* 3. Install agent */
/* In the unified hierarchy we can get
* cgroup empty notifications via inotify. */
/* In the unified hierarchy we can get
* cgroup empty notifications via inotify. */
return log_error_errno(errno, "Failed to open pin file: %m");
/* 6. Always enable hierarchical support if it exists... */
return log_error_errno(errno, "Failed to open pin file: %m");
/* 6. Always enable hierarchical support if it exists... */
(void) cg_set_attribute("memory", "/", "memory.use_hierarchy", "1");
}
(void) cg_set_attribute("memory", "/", "memory.use_hierarchy", "1");
}