[lkml]   [2017]   [Oct]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[RFC 1/2] cgroup, kthread: do not allow moving kthreads out of the root cgroup
Attaching kernel threads to a non-root cgroup is generally a bad
idea. Kernel threads are generally performing the work required
to keep the system working and healthy, and applying various
resource limits may affect system stability and performance.

Some examples of dangerous behavior are limiting CPU time available
to rcu stuff, memory limits applied to almost all kthreads, etc.

To prevent this dangerous behavior, let's deny all kthread
movements between cgroups. Right now only kthreads bounded
to CPUs are not allowed to move, which is not sufficient.

If there are examples of kthreads which can be limited,
and it's guaranteed to be safe, we can allow explicit
exceptions further.

Signed-off-by: Roman Gushchin <>
Cc: Tejun Heo <>
Cc: Oleg Nesterov <>
Cc: Linus Torvalds <>
Cc: Andrew Morton <>
Cc: Peter Zijlstra (Intel) <>
Cc: Thomas Gleixner <>
Cc: Chris Mason <>
kernel/cgroup/cgroup.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index c7086c8835da..a3d7a1b5720d 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2629,12 +2629,12 @@ struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup)
tsk = tsk->group_leader;

- * kthreads may acquire PF_NO_SETAFFINITY during initialization.
- * If userland migrates such a kthread to a non-root cgroup, it can
+ * If userland migrates a kthread to a non-root cgroup, it can
* become trapped in a cpuset, or RT kthread may be born in a
- * cgroup with no rt_runtime allocated. Just say no.
+ * cgroup with no rt_runtime allocated, or it can suffer from
+ * memory shortage, etc. Just say no.
- if (tsk->no_cgroup_migration || (tsk->flags & PF_NO_SETAFFINITY)) {
+ if (tsk->flags & (PF_KTHREAD | PF_NO_SETAFFINITY)) {
goto out_unlock_threadgroup;
 \ /
  Last update: 2017-10-12 19:39    [W:0.070 / U:10.940 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site