From: Geoffrey Thomas <geofft@MIT.EDU>
To: linux-kernel@vger.kernel.org
Cc: Geoffrey Thomas <geofft@MIT.EDU>
Subject: [PATCH] sysrq: Don't panic_on_oom if the user requested an OOM kill.
Date: Mon, 18 May 2009 06:41:14 -0400 [thread overview]
Message-ID: <1242643274-26733-1-git-send-email-geofft@mit.edu> (raw)
If I specifically request an OOM kill via magic sysrq, I don't want
panic_on_oom to apply and crash the machine. I ran into this on a server
with panic_on_oom and automatic reboot after panic configured on the
assumption that nobody is likely physically present. If I'm able to use
magic sysrq, though, I can use that to reboot the machine slightly more
safely, if that's what I wanted.
This patch adds an extra parameter to out_of_memory to ignore the value
of sysctl_panic_on_oom, and just proceed with the OOM kill.
Signed-off-by: Geoffrey Thomas <geofft@mit.edu>
---
drivers/char/sysrq.c | 2 +-
include/linux/oom.h | 3 ++-
mm/oom_kill.c | 8 +++++---
mm/page_alloc.c | 2 +-
4 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index d6a807f..0233d5a 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -329,7 +329,7 @@ static struct sysrq_key_op sysrq_term_op = {
static void moom_callback(struct work_struct *ignored)
{
- out_of_memory(node_zonelist(0, GFP_KERNEL), GFP_KERNEL, 0);
+ out_of_memory(node_zonelist(0, GFP_KERNEL), GFP_KERNEL, 0, 1);
}
static DECLARE_WORK(moom_work, moom_callback);
diff --git a/include/linux/oom.h b/include/linux/oom.h
index a7979ba..b273c7c 100644
--- a/include/linux/oom.h
+++ b/include/linux/oom.h
@@ -26,7 +26,8 @@ enum oom_constraint {
extern int try_set_zone_oom(struct zonelist *zonelist, gfp_t gfp_flags);
extern void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_flags);
-extern void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order);
+extern void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
+ int order, int dontpanic);
extern int register_oom_notifier(struct notifier_block *nb);
extern int unregister_oom_notifier(struct notifier_block *nb);
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 92bcf1d..7bc4dcf 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -583,13 +583,15 @@ rest_and_return:
* @zonelist: zonelist pointer
* @gfp_mask: memory allocation flags
* @order: amount of memory being requested as a power of 2
+ * @dontpanic: whether to ignore panic_on_oom (used by magic-sysrq)
*
* If we run out of memory, we have the choice between either
* killing a random task (bad), letting the system crash (worse)
* OR try to be smart about which process to kill. Note that we
* don't have to be perfect here, we just have to be good.
*/
-void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
+void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
+ int order, int dontpanic)
{
unsigned long freed = 0;
enum oom_constraint constraint;
@@ -599,7 +601,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
/* Got some memory back in the last second. */
return;
- if (sysctl_panic_on_oom == 2)
+ if (!dontpanic && sysctl_panic_on_oom == 2)
panic("out of memory. Compulsory panic_on_oom is selected.\n");
/*
@@ -616,7 +618,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
break;
case CONSTRAINT_NONE:
- if (sysctl_panic_on_oom)
+ if (!dontpanic && sysctl_panic_on_oom)
panic("out of memory. panic_on_oom is selected\n");
/* Fall-through */
case CONSTRAINT_CPUSET:
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index fe753ec..b5f42d6 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -1625,7 +1625,7 @@ nofail_alloc:
goto nopage;
}
- out_of_memory(zonelist, gfp_mask, order);
+ out_of_memory(zonelist, gfp_mask, order, 0);
clear_zonelist_oom(zonelist, gfp_mask);
goto restart;
}
--
1.6.0
next reply other threads:[~2009-05-18 11:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-18 10:41 Geoffrey Thomas [this message]
2009-05-18 20:52 ` David Rientjes
[not found] <cD8Tq-1IB-7@gated-at.bofh.it>
[not found] ` <cDi6w-7CM-27@gated-at.bofh.it>
2009-05-18 22:35 ` Bodo Eggert
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=1242643274-26733-1-git-send-email-geofft@mit.edu \
--to=geofft@mit.edu \
--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
all inboxes | Powered by JetHome®