Skip to content

Commit

Permalink
freezer: fix racy usage of try_to_freeze in kswapd
Browse files Browse the repository at this point in the history
Currently we can miss freeze_process()->signal_wake_up() in kswapd() if it
happens between try_to_freeze() and prepare_to_wait().  To prevent this
from happening we should check freezing(current) before calling schedule().

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Rafael J. Wysocki authored and Linus Torvalds committed May 7, 2007
1 parent d1d241c commit b1296cc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mm/vmscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1323,8 +1323,6 @@ static int kswapd(void *p)
for ( ; ; ) {
unsigned long new_order;

try_to_freeze();

prepare_to_wait(&pgdat->kswapd_wait, &wait, TASK_INTERRUPTIBLE);
new_order = pgdat->kswapd_max_order;
pgdat->kswapd_max_order = 0;
Expand All @@ -1335,12 +1333,19 @@ static int kswapd(void *p)
*/
order = new_order;
} else {
schedule();
if (!freezing(current))
schedule();

order = pgdat->kswapd_max_order;
}
finish_wait(&pgdat->kswapd_wait, &wait);

balance_pgdat(pgdat, order);
if (!try_to_freeze()) {
/* We can speed up thawing tasks if we don't call
* balance_pgdat after returning from the refrigerator
*/
balance_pgdat(pgdat, order);
}
}
return 0;
}
Expand Down

0 comments on commit b1296cc

Please sign in to comment.