Commit 464f4e78 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Disallow swapoff if there is insufficient memory

From: Hugh Dickins <hugh@veritas.com>

First of three small "stop swapoff" patches based on 2.5.67-mm3:

stop swapoff 1/3 vm_enough_memory?

Before embarking upon swapoff, check vm_enough_memory.  Mainly
for consistency in the overcommit_memory 2 (strict accounting) case:
fail with -ENOMEM if it wouldn't let the amount removed be committed.

Will always succeed in the overcommit_memory 1 case, as it should in
root-shoot-foot mode.  In the overcommit_memory 0 case, well, I don't
care much either way, so opted for the simplest code: no special case.
Which means it could now fail at the start; but that's unlikely (case 0
is over-generous) and only when it would have got stuck later on anyway.
parent 36f6aa1b
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <linux/config.h> #include <linux/config.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/mman.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/kernel_stat.h> #include <linux/kernel_stat.h>
#include <linux/swap.h> #include <linux/swap.h>
...@@ -1028,12 +1029,18 @@ asmlinkage long sys_swapoff(const char __user * specialfile) ...@@ -1028,12 +1029,18 @@ asmlinkage long sys_swapoff(const char __user * specialfile)
} }
prev = type; prev = type;
} }
err = -EINVAL;
if (type < 0) { if (type < 0) {
err = -EINVAL;
swap_list_unlock();
goto out_dput;
}
if (vm_enough_memory(p->pages))
vm_unacct_memory(p->pages);
else {
err = -ENOMEM;
swap_list_unlock(); swap_list_unlock();
goto out_dput; goto out_dput;
} }
if (prev < 0) { if (prev < 0) {
swap_list.head = p->next; swap_list.head = p->next;
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment