linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Oeser <ingo.oeser@informatik.tu-chemnitz.de>
To: Rik van Riel <riel@conectiva.com.br>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] OOM killer API (was: [PATCH] VM fix for 2.4.0-test9 & OOM handler)
Date: Tue, 10 Oct 2000 17:07:08 +0200	[thread overview]
Message-ID: <20001010170708.C784@nightmaster.csn.tu-chemnitz.de> (raw)
In-Reply-To: <20001010013558.A784@nightmaster.csn.tu-chemnitz.de>; from ingo.oeser@informatik.tu-chemnitz.de on Tue, Oct 10, 2000 at 01:35:58AM +0200

[OOM killer war]

Hi there,

before you argue endlessly about the "Right OOM Killer (TM)", I
did a small patch to allow replacing the OOM killer at runtime.

You can even use modules, if you are careful (see khttpd on how
to do this without refcouting).

So now you can stop arguing about the one and only OOM killer,
implement it, provide it as module and get back to the important
stuff ;-)

PS: Patch is against test10-pre1.

Thanks for listening

Ingo Oeser

--- linux-2.4.0-test10-pre1/mm/oom_kill.c	Tue Oct 10 16:31:08 2000
+++ linux-2.4.0-test10-pre1-ioe/mm/oom_kill.c	Tue Oct 10 16:59:27 2000
@@ -13,6 +13,8 @@
  *  machine) this file will double as a 'coding guide' and a signpost
  *  for newbie kernel hackers. It features several pointers to major
  *  kernel subsystems and hints as to where to find out what things do.
+ *
+ *  Added oom_killer API for special needs - Ingo Oeser
  */
 
 #include <linux/mm.h>
@@ -136,7 +138,7 @@
 }
 
 /**
- * oom_kill - kill the "best" process when we run out of memory
+ * oom_kill_rik - kill the "best" process when we run out of memory
  *
  * If we run out of memory, we have the choice between either
  * killing a random task (bad), letting the system crash (worse)
@@ -147,7 +149,9 @@
  * CAP_SYS_RAW_IO set, send SIGTERM instead (but it's unlikely that
  * we select a process with CAP_SYS_RAW_IO set).
  */
-void oom_kill(void)
+
+
+static void oom_kill_rik(void)
 {
 
 	struct task_struct *p = select_bad_process();
@@ -207,4 +211,63 @@
 
 	/* Else... */
 	return 1;
+}
+
+/* Protects oom_killer against resetting during its execution */
+static rwlock_t oom_kill_lock = RW_LOCK_UNLOCKED;
+
+static oom_killer_t oom_killer = oom_kill_rik;
+
+/** 
+ * oom_kill - the oom_kill wrapper for installable OOM killers
+ *
+ * Wraper around the OOM killers, that can be installed via
+ * install_oom_killer and reset_default_oom_killer.
+ *
+ * This gets called from kswapd() in linux/mm/vmscan.c when we 
+ * really run out of memory.
+ */
+void oom_kill(void) {
+	read_lock(&oom_kill_lock);
+	oom_killer();
+	read_unlock(&oom_kill_lock);
+}
+
+/**
+ * install_oom_killer - install alternate OOM killer
+ * @new_oom_kill: the alternate OOM killer provided by the caller
+ *
+ * Since the default OOM killer (oom_kill_rik) is not suitable 
+ * for everyone, we provide an interface to install custom OOM killers.
+ * 
+ * You can take the most appropriate action for your application if the
+ * kernel goes OOM.
+ *
+ * Providing an NULL argument just returns the current OOM killer.
+ *
+ * Returns: The OOM killer, which has been installed so far.
+ * 
+ * NOTE: We don't do refcounting on OOM killers, so be careful with 
+ * 	modules
+ */
+oom_killer_t install_oom_killer(oom_killer_t new_oom_kill) {
+	oom_killer_t tmp;
+	write_lock(&oom_kill_lock);
+	tmp=oom_killer;
+	if (new_oom_kill) 
+		oom_killer=new_oom_kill;
+	write_unlock(&oom_kill_lock);
+	return tmp;
+}
+
+/**
+ * reset_default_oom_killer - reset back to default OOM killer
+ *
+ * If you are going to unload the module which provided 
+ * your OOM killer, you can install the default one by this.
+ *
+ * Returns: The OOM killer, which has been installed so far.
+ */
+oom_killer_t reset_default_oom_killer(void) {
+	return install_oom_killer(&oom_kill_rik);
 }
--- linux-2.4.0-test10-pre1/include/linux/swap.h	Tue Oct 10 16:31:08 2000
+++ linux-2.4.0-test10-pre1-ioe/include/linux/swap.h	Tue Oct 10 16:44:22 2000
@@ -127,8 +127,14 @@
 #define read_swap_cache(entry) read_swap_cache_async(entry, 1);
 
 /* linux/mm/oom_kill.c */
+typedef void (*oom_killer_t)(void);
+
 extern int out_of_memory(void);
 extern void oom_kill(void);
+
+oom_killer_t install_oom_killer(oom_killer_t new_oom_kill);
+oom_killer_t reset_default_oom_killer(void);
+
 
 /*
  * Make these inline later once they are working properly.
-- 
Feel the power of the penguin - run linux@your.pc
<esc>:x
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/

  reply	other threads:[~2000-10-10 15:07 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-06 18:59 [PATCH] VM fix for 2.4.0-test9 & OOM handler Rik van Riel
2000-10-06 20:19 ` Byron Stanoszek
2000-10-06 20:31   ` Rik van Riel
2000-10-09 10:12     ` Marco Colombo
2000-10-09 11:27       ` Byron Stanoszek
2000-10-09 16:26       ` Kurt Garloff
2000-10-09 18:29         ` Jamie Lokier
2000-10-09 17:27       ` Ingo Molnar
2000-10-09 17:25         ` Mark Hahn
2000-10-09 17:37           ` Ingo Molnar
2000-10-09 17:47           ` Ed Tomlinson
2000-10-09 18:01             ` Ingo Molnar
2000-10-09 18:14       ` Rik van Riel
2000-10-09 18:47         ` Ingo Molnar
2000-10-09 18:52           ` Rik van Riel
2000-10-09 19:27             ` Ingo Molnar
2000-10-09 19:38         ` Marco Colombo
2000-10-06 21:27   ` David Weinehall
2000-10-06 23:21     ` David Weinehall
2000-10-09 18:28   ` Andrea Arcangeli
2000-10-09 18:42     ` Ingo Molnar
2000-10-09 19:05       ` Andrea Arcangeli
2000-10-09 19:07         ` Rik van Riel
2000-10-09 19:42           ` Andrea Arcangeli
2000-10-09 20:06             ` Ingo Molnar
2000-10-09 20:06               ` Andi Kleen
2000-10-09 20:19                 ` Ingo Molnar
2000-10-09 20:12                   ` Rik van Riel
2000-10-09 20:24                     ` Ingo Molnar
2000-10-09 20:18                       ` Rik van Riel
2000-10-10  3:23                         ` Philipp Rumpf
2000-10-09 20:38                       ` James Sutherland
2000-10-09 20:40                         ` Rik van Riel
2000-10-10  9:59                           ` J.A. Sutherland
2000-10-09 20:44                         ` Andrea Arcangeli
2000-10-09 21:52                         ` Aaron Sethman
2000-10-09 21:54                           ` Rik van Riel
2000-10-09 22:29                       ` FORT David
2000-10-09 20:52                 ` Linus Torvalds
2000-10-09 20:58                   ` Andi Kleen
2000-10-09 21:21                     ` Jim Gettys
2000-10-09 21:28                       ` Alan Cox
2000-10-09 21:34                         ` Andi Kleen
2000-10-09 21:38                         ` Linus Torvalds
2000-10-09 21:39                           ` Rik van Riel
2000-10-09 21:44                             ` Linus Torvalds
2000-10-10 13:17                               ` Marco Colombo
2000-10-09 21:44                           ` Jim Gettys
2000-10-09 21:50                             ` Linus Torvalds
2000-10-09 22:07                               ` Jim Gettys
2000-10-09 23:13                                 ` Albert D. Cahalan
2000-10-09 23:16                                   ` Rik van Riel
2000-10-09 23:46                                   ` Jim Gettys
2000-10-10  9:46                                   ` Jamie Lokier
2000-10-10 14:41                               ` Rogier Wolff
2000-10-10 17:28                                 ` Linus Torvalds
2000-10-09 21:51                           ` Alan Cox
2000-10-09 21:40                         ` Jim Gettys
2000-10-09 21:05                   ` Rik van Riel
2000-10-09 22:08                     ` Gerrit.Huizenga
2000-10-09 22:34                       ` Byron Stanoszek
2000-10-09 22:57                         ` Rik van Riel
2000-10-10  0:25                         ` [RFC] New ideas for the " Byron Stanoszek
2000-10-09 20:11               ` [PATCH] VM fix for 2.4.0-test9 & " Andrea Arcangeli
2000-10-09 20:15                 ` Rik van Riel
2000-10-09 20:40               ` Linus Torvalds
2000-10-09 20:47                 ` Rik van Riel
2000-10-09 20:57                 ` Ingo Molnar
2000-10-09 21:10                   ` Peter Waltenberg
2000-10-09 22:25                     ` Andrea Arcangeli
2000-10-09 22:59                       ` Peter Waltenberg
2000-10-09 23:52                         ` Andrea Arcangeli
2000-10-09 23:10                       ` Rik van Riel
2000-10-09 21:10               ` Alan Cox
2000-10-09 21:25                 ` Ingo Molnar
2000-10-09 21:26                   ` Rik van Riel
2000-10-09 21:38                     ` Ingo Molnar
2000-10-09 21:34                       ` Rik van Riel
2000-10-10  9:09                         ` john slee
2000-10-09 20:06             ` Rik van Riel
2000-10-09 20:18               ` Andrea Arcangeli
2000-10-10  3:29               ` Philipp Rumpf
2000-10-10 15:06                 ` Rik van Riel
2000-10-10 15:24                   ` Philipp Rumpf
2000-10-10 15:30                     ` Rik van Riel
2000-10-10 15:37                       ` Philipp Rumpf
2000-10-09 20:13           ` Ingo Molnar
2000-10-09 20:08             ` Rik van Riel
2000-10-09 20:22               ` Ingo Molnar
2000-10-09 20:28                 ` David Ford
2000-10-09 20:34                   ` Rik van Riel
2000-10-09 20:45                     ` David Ford
2000-10-10  4:22                       ` Andreas Dilger
2000-10-10  4:30                         ` David Ford
2000-10-10  9:54                         ` Jamie Lokier
2000-10-09 23:35           ` Ingo Oeser
2000-10-10 15:07             ` Ingo Oeser [this message]
2000-10-10 15:32               ` [PATCH] OOM killer API (was: [PATCH] VM fix for 2.4.0-test9 & OOM handler) Rik van Riel
2000-10-10 16:11                 ` Ingo Oeser
2000-10-10 18:57                 ` Tom Rini
2000-10-10 20:58                   ` Rik van Riel
2000-10-10 22:46                     ` Tom Rini
2000-10-09 19:30       ` [PATCH] VM fix for 2.4.0-test9 & OOM handler David Ford
2000-10-09 19:58         ` Andrea Arcangeli
2000-10-09 20:14           ` David Ford
2000-10-09 20:05         ` Rik van Riel
2000-10-09 21:07         ` Alan Cox
2000-10-10  3:38           ` Philipp Rumpf
2000-10-10 14:07             ` Andrea Arcangeli

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=20001010170708.C784@nightmaster.csn.tu-chemnitz.de \
    --to=ingo.oeser@informatik.tu-chemnitz.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@conectiva.com.br \
    /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