patch-2.4.25 linux-2.4.25/mm/oom_kill.c
Next file: linux-2.4.25/mm/page_alloc.c
Previous file: linux-2.4.25/mm/mremap.c
Back to the patch index
Back to the overall index
- Lines: 82
- Date:
2004-02-18 05:36:32.000000000 -0800
- Orig file:
linux-2.4.24/mm/oom_kill.c
- Orig date:
2003-11-28 10:26:21.000000000 -0800
diff -urN linux-2.4.24/mm/oom_kill.c linux-2.4.25/mm/oom_kill.c
@@ -21,8 +21,6 @@
#include <linux/swapctl.h>
#include <linux/timex.h>
-#if 0 /* Nothing in this file is used */
-
/* #define DEBUG */
/**
@@ -153,6 +151,7 @@
* exit() and clear out its resources quickly...
*/
p->counter = 5 * HZ;
+ p->flags |= PF_MEMALLOC | PF_MEMDIE;
/* This process has hardware access, be more careful. */
if (cap_t(p->cap_effective) & CAP_TO_MASK(CAP_SYS_RAWIO)) {
@@ -202,6 +201,11 @@
*/
void out_of_memory(void)
{
+ /*
+ * oom_lock protects out_of_memory()'s static variables.
+ * It's a global lock; this is not performance-critical.
+ */
+ static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
static unsigned long first, last, count, lastkill;
unsigned long now, since;
@@ -211,6 +215,7 @@
if (nr_swap_pages > 0)
return;
+ spin_lock(&oom_lock);
now = jiffies;
since = now - last;
last = now;
@@ -229,14 +234,14 @@
*/
since = now - first;
if (since < HZ)
- return;
+ goto out_unlock;
/*
* If we have gotten only a few failures,
* we're not really oom.
*/
if (++count < 10)
- return;
+ goto out_unlock;
/*
* If we just killed a process, wait a while
@@ -245,17 +250,23 @@
*/
since = now - lastkill;
if (since < HZ*5)
- return;
+ goto out_unlock;
/*
* Ok, really out of memory. Kill something.
*/
lastkill = now;
+
+ /* oom_kill() can sleep */
+ spin_unlock(&oom_lock);
oom_kill();
+ spin_lock(&oom_lock);
reset:
- first = now;
+ if (first < now)
+ first = now;
count = 0;
-}
-#endif /* Unused file */
+out_unlock:
+ spin_unlock(&oom_lock);
+}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)