From cca095e03401e4a1c6cd1a747d8e278986b9d6a4 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 20 Apr 2003 00:28:52 -0700 Subject: [PATCH] [PATCH] oom-kill: preferentially kill swapoff From: Hugh Dickins The current behaviour is that once swapoff has filled memory, other tasks get OOMkilled one by one until swapoff completes, or more likely hangs. It is better that swapoff be the first choice for OOMkill. The patch changes the oom-killer so that it will kill off any currently-running swapoff instance before killing any other task. (Bit kludgy, couldn't think of a better way) --- include/linux/sched.h | 1 + mm/oom_kill.c | 2 ++ mm/swapfile.c | 2 ++ 3 files changed, 5 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index c30c44f3cfcc9..eee58c7354b4d 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -465,6 +465,7 @@ do { if (atomic_dec_and_test(&(tsk)->usage)) __put_task_struct(tsk); } while(0) #define PF_FROZEN 0x00010000 /* frozen for system suspend */ #define PF_FSTRANS 0x00020000 /* inside a filesystem transaction */ #define PF_KSWAPD 0x00040000 /* I am kswapd */ +#define PF_SWAPOFF 0x00080000 /* I am in swapoff */ #if CONFIG_SMP extern void set_cpus_allowed(task_t *p, unsigned long new_mask); diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 34a3aeb50799b..e537462aaf584 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -129,6 +129,8 @@ static struct task_struct * select_bad_process(void) chosen = p; maxpoints = points; } + if (p->flags & PF_SWAPOFF) + return p; } while_each_thread(g, p); return chosen; diff --git a/mm/swapfile.c b/mm/swapfile.c index 144915b747346..48ffb627914df 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1058,7 +1058,9 @@ asmlinkage long sys_swapoff(const char __user * specialfile) total_swap_pages -= p->pages; p->flags &= ~SWP_WRITEOK; swap_list_unlock(); + current->flags |= PF_SWAPOFF; err = try_to_unuse(type); + current->flags &= ~PF_SWAPOFF; if (err) { /* re-insert swap space back into swap_list */ swap_list_lock(); -- 2.53.0