From: Hugh Dickins 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. 25-akpm/mm/swapfile.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff -puN mm/swapfile.c~overcommit-stop-swapoff mm/swapfile.c --- 25/mm/swapfile.c~overcommit-stop-swapoff Thu Apr 17 15:02:01 2003 +++ 25-akpm/mm/swapfile.c Thu Apr 17 15:02:01 2003 @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -1029,12 +1030,18 @@ asmlinkage long sys_swapoff(const char _ } prev = type; } - err = -EINVAL; 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(); goto out_dput; } - if (prev < 0) { swap_list.head = p->next; } else { _