Skip to content

Commit 74a1166

Browse files
bblumtorvalds
authored andcommitted
cgroups: make procs file writable
Make procs file writable to move all threads by tgid at once. Add functionality that enables users to move all threads in a threadgroup at once to a cgroup by writing the tgid to the 'cgroup.procs' file. This current implementation makes use of a per-threadgroup rwsem that's taken for reading in the fork() path to prevent newly forking threads within the threadgroup from "escaping" while the move is in progress. Signed-off-by: Ben Blum <bblum@andrew.cmu.edu> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Li Zefan <lizf@cn.fujitsu.com> Cc: Matt Helsley <matthltc@us.ibm.com> Reviewed-by: Paul Menage <menage@google.com> Cc: Oleg Nesterov <oleg@redhat.com> Cc: David Rientjes <rientjes@google.com> Cc: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f780bdb commit 74a1166

2 files changed

Lines changed: 401 additions & 47 deletions

File tree

‎Documentation/cgroups/cgroups.txt‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ containing the following files describing that cgroup:
236236
- cgroup.procs: list of tgids in the cgroup. This list is not
237237
guaranteed to be sorted or free of duplicate tgids, and userspace
238238
should sort/uniquify the list if this property is required.
239-
This is a read-only file, for now.
239+
Writing a thread group id into this file moves all threads in that
240+
group into this cgroup.
240241
- notify_on_release flag: run the release agent on exit?
241242
- release_agent: the path to use for release notifications (this file
242243
exists in the top cgroup only)
@@ -430,6 +431,12 @@ You can attach the current shell task by echoing 0:
430431

431432
# echo 0 > tasks
432433

434+
You can use the cgroup.procs file instead of the tasks file to move all
435+
threads in a threadgroup at once. Echoing the pid of any task in a
436+
threadgroup to cgroup.procs causes all tasks in that threadgroup to be
437+
be attached to the cgroup. Writing 0 to cgroup.procs moves all tasks
438+
in the writing task's threadgroup.
439+
433440
Note: Since every task is always a member of exactly one cgroup in each
434441
mounted hierarchy, to remove a task from its current cgroup you must
435442
move it into a new cgroup (possibly the root cgroup) by writing to the

0 commit comments

Comments
 (0)