Skip to contentSkip to conversation

Modular OOM handlers for 2.6.4 (1/2)

PATCH In review Tvrtko A. Uršulin 1 participant 2 messages Mar 16, 2004

Subsystems (9)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Modular OOM handlers for 2.6.4 (1/2)

Hello to all!

Here goes my effort in making modular infrastructure for OOM handling.

Config is added under "General options" and it defaults to same behavior as so far. Don't know what else to write here.. I guess you will look at the patch and that will tell you everything.

Base patch contains only the infrastructure with existing handler which is called classic OOM killer.

Regards,
Tvrtko

include/linux/notifier.h +2 -0
diff -Naur linux-2.6.4/include/linux/notifier.h linux-2.6.4-moom/include/linux/notifier.h
@@ -58,6 +58,8 @@
 #define SYS_HALT	0x0002	/* Notify of system halt */
 #define SYS_POWER_OFF	0x0003	/* Notify of system power off */
 
+#define OUT_OF_MEMORY  0x00001 /* Notify of critical memory shortage */
+
 #define NETLINK_URELEASE	0x0001	/* Unicast netlink socket released */
 
 #define CPU_ONLINE	0x0002 /* CPU (unsigned)v is up */
include/linux/oom_notify.h +40 -0
diff -Naur linux-2.6.4/include/linux/oom_notify.h linux-2.6.4-moom/include/linux/oom_notify.h
@@ -0,0 +1,40 @@
+#ifndef _LINUX_OOM_NOTIFY_H
+#define _LINUX_OOM_NOTIFY_H
+
+
+#ifdef debug
+#undef dbg
+#endif
+#define dbg(format, arg...)					\
+do {							\
+		printk (KERN_DEBUG "Out of memory: " format "\n",	## arg);                        \
+} while(0)
+
+#ifdef warn
+#undef warn
+#endif
+#define warn(format, arg...)					  \
+do {							  \
+		printk (KERN_WARNING "Out of memory: " format "\n", ## arg);                          \
+} while(0)
+
+#ifdef info
+#undef info
+#endif
+#define info(format, arg...)					  \
+do {							  \
+		printk (KERN_INFO "Out of Memory: " format "\n", ## arg);                          \
+} while(0)
+
+#ifdef error
+#undef error
+#endif
+#define error(format, arg...)					        \
+do {							        \
+		printk (KERN_ERR "Out of Memory: " format "\n",	## arg);                                \
+} while(0)
+
+int register_oom_notifier(struct notifier_block * nb);
+int unregister_oom_notifier(struct notifier_block * nb);
+
+#endif /* _LINUX_OOM_NOTIFY_H */
include/linux/sysctl.h +1 -0
diff -Naur linux-2.6.4/include/linux/sysctl.h linux-2.6.4-moom/include/linux/sysctl.h
@@ -158,6 +158,7 @@
 	VM_SWAPPINESS=19,	/* Tendency to steal mapped memory */
 	VM_LOWER_ZONE_PROTECTION=20,/* Amount of protection of lower zones */
 	VM_MIN_FREE_KBYTES=21,	/* Minimum free kilobytes to maintain */
+	VM_OOM=22,   /* Out of memory */
 };
 
 
init/Kconfig +25 -0
diff -Naur linux-2.6.4/init/Kconfig linux-2.6.4-moom/init/Kconfig
@@ -181,7 +181,32 @@
 	  This option enables access to kernel configuration file and build
 	  information through /proc/config.gz.
 
+menuconfig OOM_KILLER
+	bool "Select task to kill on out of memory condition"
+	default y
+	help
+	  This option selects the kernel behaviour during total out of memory
+	  condition.
+
+	  The default behaviour is to, as soon as no freeable memory and no swap
+	  space are available, kill the task which tries to allocate memory.
+	  The default behaviour is very reliable.
 
+	  If you select this option, as soon as no freeable memory is available,
+	  the kernel will try to select the "best" task to be killed.
+
+	  If unsure, say Y.
+
+config OOM_KILLER_CLASSIC	  
+	tristate "Classic OOM killer" if OOM_KILLER
+	default y
+	help
+	  This option enables the traditional oom_kill.c mechanism for
+	  killing processes in an attempt to recover from an out-of-memory
+	  condition.
+  
+	  If unsure, say Y.
+			  	  
 menuconfig EMBEDDED
 	bool "Remove kernel features (for embedded systems)"
 	help
kernel/fork.c +4 -1
diff -Naur linux-2.6.4/kernel/fork.c linux-2.6.4-moom/kernel/fork.c
@@ -1,4 +1,3 @@
-/*
  *  linux/kernel/fork.c
  *
  *  Copyright (C) 1991, 1992  Linus Torvalds
@@ -450,6 +449,8 @@
 	}
 }
 
+EXPORT_SYMBOL_GPL(mmput);
+
 /*
  * Checks if the use count of an mm is non-zero and if so
  * returns a reference to it after bumping up the use count.
@@ -467,6 +468,8 @@
 	return mm;
 }
 
+EXPORT_SYMBOL_GPL(mmgrab);
+
 /* Please note the differences between mmput and mm_release.
  * mmput is called whenever we stop holding onto a mm_struct,
  * error success whatever.
mm/Makefile +4 -1
diff -Naur linux-2.6.4/mm/Makefile linux-2.6.4-moom/mm/Makefile
@@ -7,8 +7,11 @@
 			   mlock.o mmap.o mprotect.o mremap.o msync.o rmap.o \
 			   shmem.o vmalloc.o
 
-obj-y			:= bootmem.o filemap.o mempool.o oom_kill.o fadvise.o \
+obj-y			:= bootmem.o filemap.o mempool.o fadvise.o \
 			   page_alloc.o page-writeback.o pdflush.o readahead.o \
 			   slab.o swap.o truncate.o vmscan.o $(mmu-y)
 
 obj-$(CONFIG_SWAP)	+= page_io.o swap_state.o swapfile.o
+
+obj-$(CONFIG_OOM_KILLER)  += oom_notify.o
+obj-$(CONFIG_OOM_KILLER_CLASSIC)  += oom_kill.o
mm/oom_kill.c +48 -8

99 lines not on this page · raw message

mm/oom_notify.c +44 -0

44 lines not on this page · raw message

mm/page_alloc.c +2 -0
diff -Naur linux-2.6.4/mm/page_alloc.c linux-2.6.4-moom/mm/page_alloc.c
@@ -1058,6 +1058,8 @@
 	show_swap_cache_info();
 }
 
+EXPORT_SYMBOL_GPL(show_free_areas);
+
 /*
  * Builds allocation fallback zone lists.
  */
mm/vmscan.c +3 -0
diff -Naur linux-2.6.4/mm/vmscan.c linux-2.6.4-moom/mm/vmscan.c
@@ -893,8 +893,11 @@
 			}
 		}
 	}
+#ifdef CONFIG_OOM_KILLER	
 	if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY))
 		out_of_memory();
+#endif
+
 out:
 	for (i = 0; zones[i] != 0; i++)
 		zones[i]->prev_priority = zones[i]->temp_priority;
#1 lore raw

Re: [PATCH] Modular OOM handlers for 2.6.4 (2/2)

These are two additional handlers for OOM situation.

oom_panic - will make kernel panic in oom condition. It is usefull for some embedded developers as I understand.

oom_kill_parent - keeps tracks of parents whose children were killed in the past. When configurable (sysctl) threshold is passed, parent itself is killed. Also, parent sins are expired after some time (also configurable).

Regards,
Tvrtko

init/Kconfig +27 -0
diff -Naur linux-2.6.4/init/Kconfig linux-2.6.4-moom/init/Kconfig
@@ -207,6 +207,33 @@
   
 	  If unsure, say Y.
 			  	  
+config OOM_KILLER_PARENT_PROCESS_KILL	  
+	tristate "Parent process killer" if OOM_KILLER
+	default y
+	help
+	  This option enables an out-of-memory handler that not only attempts
+	  to kill bad processes to free up memory, but also kills parents
+	  that repeatedly produce bad children.
+
+	  Two tunables, oom_parent_max and oom_parent_expire, will be added
+	  and  to /proc/sys/vm/ to control how many children a parent is
+	  allowed to have terminated, and how long between terminated children
+	  before a parent is forgiven.
+  
+	  If unsure, say N.
+
+config OOM_KILLER_PANIC	  
+	tristate "OOM Panic" if OOM_KILLER
+	default y
+	help
+	  This option enables panic() to be called when a system is out of
+	  memory.  This feature along with /proc/sys/kernel/panic allows a
+	  different behavior on out-of-memory conditions when the standard
+	  behavior (killing processes in an attempt to recover) does not
+	  make sense.
+  
+	  If unsure, say N.
+
 menuconfig EMBEDDED
 	bool "Remove kernel features (for embedded systems)"
 	help
mm/Makefile +2 -0
diff -Naur linux-2.6.4/mm/Makefile linux-2.6.4-moom/mm/Makefile
@@ -15,3 +15,5 @@
 
 obj-$(CONFIG_OOM_KILLER)  += oom_notify.o
 obj-$(CONFIG_OOM_KILLER_CLASSIC)  += oom_kill.o
+obj-$(CONFIG_OOM_KILLER_PANIC)  += oom_panic.o
+obj-$(CONFIG_OOM_KILLER_PARENT_PROCESS_KILL)  += oom_kill_parent.o
mm/oom_kill_parent.c +485 -0

485 lines not on this page · raw message

mm/oom_panic.c +50 -0

50 lines not on this page · raw message