summaryrefslogtreecommitdiff
path: root/src/core/cgroup.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-02-09 19:07:01 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:59:09 +0200
commit8ca5c2226c125a6b266aab556cafe0d6b59bb671 (patch)
tree0bd89ac6ab4c72c0a87cdb560470f192b99b6183 /src/core/cgroup.c
parent581473bcb149098f94f684c5f526a2ce932a7df1 (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.
Diffstat (limited to 'src/core/cgroup.c')
-rw-r--r--src/core/cgroup.c27
1 files changed, 22 insertions, 5 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;
}