]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
tools/cgclassify: add -r option for systemd scope
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 20 Jun 2023 11:44:25 +0000 (17:14 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 21 Jun 2023 16:11:19 +0000 (10:11 -0600)
commitdb4e3521647e55224c862dc5dd3a67b9824988c9
tree54092ac275035fff4ab0847aec7aeb8deaa7c198
parent77d55e0ee86731c180fec10c5cc67ab1b2b92320
tools/cgclassify: add -r option for systemd scope

Provide an option for users to replace the default idle_thread created
for systemd scope.  With '-r' option specified, the first pid passed as
the argument to cgclassify will replace the default idle_thread, if it
exists.  Also, if it's the only task, killing it will remove the .scope
cgroup it's running in.

$ sudo cgclassify -r -gcpu:libcgroup.slice/db.scope 1234 1235

For non scope cgroups, it launches the task program. The algorithm in
brief is as follows:
Once the first pid of argument list migrated to the expected cgroup(s):
1. The controller, cgroups details of the pid is captured before the
   migration, so incase an error occurs, it easy to roll back to the
   original cgroups the pid belonged to.
2. Once the migrated is done, parse /proc/<pid>/cgroup of the first
   pid and if the cgroup name ends with .scope and has a task with
   /proc/<pid>/cmdline as "libcgroup_systemd_idle_thread", kill
   the task. This gives the illusion of replacement.
3. If an error occurs, migrate the pid back to the original cgroups.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/cgclassify.c