]> git.hungrycats.org Git - linux/commitdiff
[PATCH] oom-kill: preferentially kill swapoff
authorAndrew Morton <akpm@digeo.com>
Sun, 20 Apr 2003 07:28:52 +0000 (00:28 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Sun, 20 Apr 2003 07:28:52 +0000 (00:28 -0700)
From: Hugh Dickins <hugh@veritas.com>

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
mm/oom_kill.c
mm/swapfile.c

index c30c44f3cfcc922f8c6cbae959b5e82b53847fa3..eee58c7354b4d1f4ef57a92d5270397132c28814 100644 (file)
@@ -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);
index 34a3aeb50799b3a4ff10429a35698cd02257b059..e537462aaf584e0e8a6741a1d985243696dee0ed 100644 (file)
@@ -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;
index 144915b74734610217f3d4a1b9e2e8979f0b392a..48ffb627914df18dd2d40f67291e5478b7c57803 100644 (file)
@@ -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();