Commit 884a45d964dd395eda945842afff5e16bcaedf56
Committed by
Tejun Heo
1 parent
860ca0e6f7
Exists in
master
and in
6 other branches
cgroup_freezer: fix freezing groups with stopped tasks
2d3cbf8b (cgroup_freezer: update_freezer_state() does incorrect state transitions) removed is_task_frozen_enough and replaced it with a simple frozen call. This, however, breaks freezing for a group with stopped tasks because those cannot be frozen and so the group remains in CGROUP_FREEZING state (update_if_frozen doesn't count stopped tasks) and never reaches CGROUP_FROZEN. Let's add is_task_frozen_enough back and use it at the original locations (update_if_frozen and try_to_freeze_cgroup). Semantically we consider stopped tasks as frozen enough so we should consider both cases when testing frozen tasks. Testcase: mkdir /dev/freezer mount -t cgroup -o freezer none /dev/freezer mkdir /dev/freezer/foo sleep 1h & pid=$! kill -STOP $pid echo $pid > /dev/freezer/foo/tasks echo FROZEN > /dev/freezer/foo/freezer.state while true do cat /dev/freezer/foo/freezer.state [ "`cat /dev/freezer/foo/freezer.state`" = "FROZEN" ] && break sleep 1 done echo OK Signed-off-by: Michal Hocko <mhocko@suse.cz> Acked-by: Li Zefan <lizf@cn.fujitsu.com> Cc: Tomasz Buchert <tomasz.buchert@inria.fr> Cc: Paul Menage <paul@paulmenage.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: stable@kernel.org Signed-off-by: Tejun Heo <htejun@gmail.com>
Showing 1 changed file with 9 additions and 2 deletions Side-by-side Diff
kernel/cgroup_freezer.c
... | ... | @@ -153,6 +153,13 @@ |
153 | 153 | kfree(cgroup_freezer(cgroup)); |
154 | 154 | } |
155 | 155 | |
156 | +/* task is frozen or will freeze immediately when next it gets woken */ | |
157 | +static bool is_task_frozen_enough(struct task_struct *task) | |
158 | +{ | |
159 | + return frozen(task) || | |
160 | + (task_is_stopped_or_traced(task) && freezing(task)); | |
161 | +} | |
162 | + | |
156 | 163 | /* |
157 | 164 | * The call to cgroup_lock() in the freezer.state write method prevents |
158 | 165 | * a write to that file racing against an attach, and hence the |
... | ... | @@ -231,7 +238,7 @@ |
231 | 238 | cgroup_iter_start(cgroup, &it); |
232 | 239 | while ((task = cgroup_iter_next(cgroup, &it))) { |
233 | 240 | ntotal++; |
234 | - if (frozen(task)) | |
241 | + if (is_task_frozen_enough(task)) | |
235 | 242 | nfrozen++; |
236 | 243 | } |
237 | 244 | |
... | ... | @@ -284,7 +291,7 @@ |
284 | 291 | while ((task = cgroup_iter_next(cgroup, &it))) { |
285 | 292 | if (!freeze_task(task, true)) |
286 | 293 | continue; |
287 | - if (frozen(task)) | |
294 | + if (is_task_frozen_enough(task)) | |
288 | 295 | continue; |
289 | 296 | if (!freezing(task) && !freezer_should_skip(task)) |
290 | 297 | num_cant_freeze_now++; |