[PATCH] fix OOM killing of swapoff

These days, if you swapoff when there isn't enough memory, OOM killer gives
"BUG: scheduling while atomic" and the machine hangs: badness() needs to do
its PF_SWAPOFF return after the task_unlock (tasklist_lock is also held
here, so p isn't going to be freed: PF_SWAPOFF might get turned off at any
moment, but that doesn't really matter).

Signed-off-by: Hugh Dickins <hugh@veritas.com>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Hugh Dickins and committed by Linus Torvalds 7ba34859 c8af57eb

+6 -6
+6 -6
mm/oom_kill.c
··· 61 } 62 63 /* 64 - * swapoff can easily use up all memory, so kill those first. 65 - */ 66 - if (p->flags & PF_SWAPOFF) 67 - return ULONG_MAX; 68 - 69 - /* 70 * The memory size of the process is the basis for the badness. 71 */ 72 points = mm->total_vm; ··· 69 * After this unlock we can no longer dereference local variable `mm' 70 */ 71 task_unlock(p); 72 73 /* 74 * Processes which fork a lot of child processes are likely
··· 61 } 62 63 /* 64 * The memory size of the process is the basis for the badness. 65 */ 66 points = mm->total_vm; ··· 75 * After this unlock we can no longer dereference local variable `mm' 76 */ 77 task_unlock(p); 78 + 79 + /* 80 + * swapoff can easily use up all memory, so kill those first. 81 + */ 82 + if (p->flags & PF_SWAPOFF) 83 + return ULONG_MAX; 84 85 /* 86 * Processes which fork a lot of child processes are likely