Re: 2.5.68-mm2

William Lee Irwin III (wli@holomorphy.com)
Wed, 23 Apr 2003 02:59:26 -0700


On Wed, Apr 23, 2003 at 01:20:46AM -0700, Andrew Morton wrote:
> http://www.zip.com.au/~akpm/linux/patches/2.5/2.5.68/2.5.68-mm2.gz
> Will appear sometime at:
> ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.5/2.5.68/2.5.68-mm2/
> . Zillions of new fixes.
> . I got tired of the objrmap code going BUG under stress, so it is now in
> disgrace in the experimental/ directory.

rml and I coordinated to put together a small patch (combining both
our own) for properly locking the static variables in out_of_memory().
There's not any evidence things are going wrong here now, but it at
least addresses the visible lack of locking in out_of_memory().

Applies cleanly to 2.5.68-mm2.

-- wli

diff -urpN mm1-2.5.68-1/mm/oom_kill.c mm1-2.5.68-1A/mm/oom_kill.c
--- mm1-2.5.68-1/mm/oom_kill.c 2003-04-20 00:24:46.000000000 -0700
+++ mm1-2.5.68-1A/mm/oom_kill.c 2003-04-22 21:43:40.000000000 -0700
@@ -208,6 +208,11 @@ static void oom_kill(void)
*/
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;

@@ -217,6 +222,7 @@ void out_of_memory(void)
if (nr_swap_pages > 0)
return;

+ spin_lock(&oom_lock);
now = jiffies;
since = now - last;
last = now;
@@ -235,14 +241,14 @@ void out_of_memory(void)
*/
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
@@ -251,15 +257,27 @@ void out_of_memory(void)
*/
since = now - lastkill;
if (since < HZ*5)
- return;
+ goto out_unlock;

/*
* Ok, really out of memory. Kill something.
*/
lastkill = now;
+
+ /* oom_kill() sleeps */
+ spin_unlock(&oom_lock);
oom_kill();
+ spin_lock(&oom_lock);

reset:
- first = now;
+ /*
+ * We dropped the lock above, so check to be sure the variable
+ * first only ever increases to prevent false OOM's.
+ */
+ if (time_after(now, first))
+ first = now;
count = 0;
+
+out_unlock:
+ spin_unlock(&oom_lock);
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/