diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-02-09 19:07:01 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-05-30 07:59:09 +0200 |
commit | 8ca5c2226c125a6b266aab556cafe0d6b59bb671 (patch) | |
tree | 0bd89ac6ab4c72c0a87cdb560470f192b99b6183 | |
parent | 581473bcb149098f94f684c5f526a2ce932a7df1 (diff) |
core: turn on memory/cpu/tasks accounting by default for the root slice
The kernel exposes the necessary data in /proc anyway, let's expose it
hence by default.
With this in place "systemctl status -- -.slice" will show accounting
data out-of-the-box now.
-rw-r--r-- | src/core/cgroup.c | 27 | ||||
-rw-r--r-- | src/core/cgroup.h | 6 |
2 files changed, 24 insertions, 9 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c index c5ca9947e..85575a589 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -37,19 +37,34 @@ #include "stdio-util.h" #include "string-table.h" #include "string-util.h" +//#include "virt.h" #define CGROUP_CPU_QUOTA_PERIOD_USEC ((usec_t) 100 * USEC_PER_MSEC) +bool manager_owns_root_cgroup(Manager *m) { + assert(m); + + /* Returns true if we are managing the root cgroup. Note that it isn't sufficient to just check whether the + * group root path equals "/" since that will also be the case if CLONE_NEWCGROUP is in the mix. Since there's + * appears to be no nice way to detect whether we are in a CLONE_NEWCGROUP namespace we instead just check if + * we run in any kind of container virtualization. */ + + if (detect_container() > 0) + return false; + + return isempty(m->cgroup_root) || path_equal(m->cgroup_root, "/"); +} + bool unit_has_root_cgroup(Unit *u) { assert(u); - /* Returns whether this unit manages the root cgroup. Note that this is different from being named "-.slice", - * as inside of containers the root slice won't be identical to the root cgroup. */ + /* Returns whether this unit manages the root cgroup. This will return true if this unit is the root slice and + * the manager manages the root cgroup. */ - if (!u->cgroup_path) + if (!manager_owns_root_cgroup(u->manager)) return false; - return isempty(u->cgroup_path) || path_equal(u->cgroup_path, "/"); + return unit_has_name(u, SPECIAL_ROOT_SLICE); } #if 0 /// UNNEEDED by elogind @@ -59,7 +74,9 @@ static void cgroup_compat_warn(void) { if (cgroup_compat_warned) return; - log_warning("cgroup compatibility translation between legacy and unified hierarchy settings activated. See cgroup-compat debug messages for details."); + log_warning("cgroup compatibility translation between legacy and unified hierarchy settings activated. " + "See cgroup-compat debug messages for details."); + cgroup_compat_warned = true; } diff --git a/src/core/cgroup.h b/src/core/cgroup.h index 23e3344b9..8bad6e710 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -168,7 +168,6 @@ bool unit_get_needs_bpf(Unit *u); void unit_update_cgroup_members_masks(Unit *u); -const char *unit_get_realized_cgroup_path(Unit *u, CGroupMask mask); char *unit_default_cgroup_path(Unit *u); int unit_set_cgroup_path(Unit *u, const char *path); int unit_pick_cgroup_path(Unit *u); @@ -180,7 +179,7 @@ int unit_watch_cgroup(Unit *u); void unit_add_to_cgroup_empty_queue(Unit *u); -int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path); +int unit_attach_pids_to_cgroup(Unit *u); #else # include "logind.h" #endif // 0 @@ -215,6 +214,7 @@ int unit_reset_ip_accounting(Unit *u); }) #endif // 0 +bool manager_owns_root_cgroup(Manager *m); bool unit_has_root_cgroup(Unit *u); int manager_notify_cgroup_empty(Manager *m, const char *group); @@ -228,5 +228,3 @@ void manager_invalidate_startup_units(Manager *m); const char* cgroup_device_policy_to_string(CGroupDevicePolicy i) _const_; CGroupDevicePolicy cgroup_device_policy_from_string(const char *s) _pure_; #endif // 0 - -bool unit_cgroup_delegate(Unit *u); |