aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup_freezer.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2011-11-21 15:32:25 -0500
committerTejun Heo <tj@kernel.org>2011-11-21 15:32:25 -0500
commita3201227f803ad7fd43180c5195dbe5a2bf998aa (patch)
tree1845ba06346f8a8772fe1c90f8960bd1a430d05c /kernel/cgroup_freezer.c
parent22b4e111fa01a1147aa562ceaf18a752a928ef4e (diff)
freezer: make freezing() test freeze conditions in effect instead of TIF_FREEZE
Using TIF_FREEZE for freezing worked when there was only single freezing condition (the PM one); however, now there is also the cgroup_freezer and single bit flag is getting clumsy. thaw_processes() is already testing whether cgroup freezing in in effect to avoid thawing tasks which were frozen by both PM and cgroup freezers. This is racy (nothing prevents race against cgroup freezing) and fragile. A much simpler way is to test actual freeze conditions from freezing() - ie. directly test whether PM or cgroup freezing is in effect. This patch adds variables to indicate whether and what type of freezing conditions are in effect and reimplements freezing() such that it directly tests whether any of the two freezing conditions is active and the task should freeze. On fast path, freezing() is still very cheap - it only tests system_freezing_cnt. This makes the clumsy dancing aroung TIF_FREEZE unnecessary and freeze/thaw operations more usual - updating state variables for the new state and nudging target tasks so that they notice the new state and comply. As long as the nudging happens after state update, it's race-free. * This allows use of freezing() in freeze_task(). Replace the open coded tests with freezing(). * p != current test is added to warning printing conditions in try_to_freeze_tasks() failure path. This is necessary as freezing() is now true for the task which initiated freezing too. -v2: Oleg pointed out that re-freezing FROZEN cgroup could increment system_freezing_cnt. Fixed. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Paul Menage <paul@paulmenage.org> (for the cgroup portions)
Diffstat (limited to 'kernel/cgroup_freezer.c')
-rw-r--r--kernel/cgroup_freezer.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c
index e6a1b8d1b8bc..2327ad11725f 100644
--- a/kernel/cgroup_freezer.c
+++ b/kernel/cgroup_freezer.c
@@ -145,7 +145,11 @@ static struct cgroup_subsys_state *freezer_create(struct cgroup_subsys *ss,
145static void freezer_destroy(struct cgroup_subsys *ss, 145static void freezer_destroy(struct cgroup_subsys *ss,
146 struct cgroup *cgroup) 146 struct cgroup *cgroup)
147{ 147{
148 kfree(cgroup_freezer(cgroup)); 148 struct freezer *freezer = cgroup_freezer(cgroup);
149
150 if (freezer->state != CGROUP_THAWED)
151 atomic_dec(&system_freezing_cnt);
152 kfree(freezer);
149} 153}
150 154
151/* 155/*
@@ -307,10 +311,14 @@ static int freezer_change_state(struct cgroup *cgroup,
307 311
308 switch (goal_state) { 312 switch (goal_state) {
309 case CGROUP_THAWED: 313 case CGROUP_THAWED:
314 if (freezer->state != CGROUP_THAWED)
315 atomic_dec(&system_freezing_cnt);
310 freezer->state = CGROUP_THAWED; 316 freezer->state = CGROUP_THAWED;
311 unfreeze_cgroup(cgroup, freezer); 317 unfreeze_cgroup(cgroup, freezer);
312 break; 318 break;
313 case CGROUP_FROZEN: 319 case CGROUP_FROZEN:
320 if (freezer->state == CGROUP_THAWED)
321 atomic_inc(&system_freezing_cnt);
314 freezer->state = CGROUP_FREEZING; 322 freezer->state = CGROUP_FREEZING;
315 retval = try_to_freeze_cgroup(cgroup, freezer); 323 retval = try_to_freeze_cgroup(cgroup, freezer);
316 break; 324 break;