linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] stop swapoff 1/3 vm_enough_memory?
@ 2003-04-17 20:46 Hugh Dickins
  2003-04-17 20:47 ` [PATCH] stop swapoff 2/3 EINTR Hugh Dickins
  2003-04-17 20:49 ` [PATCH] stop swapoff 3/3 OOMkill Hugh Dickins
  0 siblings, 2 replies; 5+ messages in thread
From: Hugh Dickins @ 2003-04-17 20:46 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Alan Cox, linux-kernel

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

 include/linux/sched.h |    1 +
 mm/oom_kill.c         |    2 ++
 mm/swapfile.c         |   21 +++++++++++++++++----
 3 files changed, 20 insertions(+), 4 deletions(-)

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.

--- 2.5.67-mm3/mm/swapfile.c	Mon Apr 14 13:05:36 2003
+++ swapoff1/mm/swapfile.c	Thu Apr 17 18:32:40 2003
@@ -7,6 +7,7 @@
 
 #include <linux/config.h>
 #include <linux/mm.h>
+#include <linux/mman.h>
 #include <linux/slab.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
@@ -1030,12 +1031,18 @@
 		}
 		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 {


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-04-17 22:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-17 20:46 [PATCH] stop swapoff 1/3 vm_enough_memory? Hugh Dickins
2003-04-17 20:47 ` [PATCH] stop swapoff 2/3 EINTR Hugh Dickins
2003-04-17 20:49 ` [PATCH] stop swapoff 3/3 OOMkill Hugh Dickins
2003-04-17 21:55   ` Andrew Morton
2003-04-17 23:10     ` Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).