linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hugh@veritas.com>
To: Andrew Morton <akpm@digeo.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] stop swapoff 1/3 vm_enough_memory?
Date: Thu, 17 Apr 2003 21:46:26 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0304172142530.2039-100000@localhost.localdomain> (raw)

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 {


             reply	other threads:[~2003-04-17 20:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-17 20:46 Hugh Dickins [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44.0304172142530.2039-100000@localhost.localdomain \
    --to=hugh@veritas.com \
    --cc=akpm@digeo.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).