chiark / gitweb /
core: turn on memory/cpu/tasks accounting by default for the root slice
authorLennart Poettering <lennart@poettering.net>
Fri, 9 Feb 2018 18:07:01 +0000 (19:07 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:59:09 +0000 (07:59 +0200)
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.

src/core/cgroup.c
src/core/cgroup.h

index c5ca9947ecb995728c368c3ce26d38c2a0b04b6a..85575a589258f578e56c5a53a9df9e853c271c0e 100644 (file)
 #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;
 }
 
index 23e3344b9ca51e9a14ec7232b9ee4991ac064cd5..8bad6e710f488a72da970c71d735b3f74443120a 100644 (file)
@@ -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);