Index: oom-2.4.21-RHEL3/mm/oom_kill.c =================================================================== --- oom-2.4.21-RHEL3.orig/mm/oom_kill.c 2004-05-17 22:24:35.000000000 +0000 +++ oom-2.4.21-RHEL3/mm/oom_kill.c 2004-06-23 21:55:28.000000000 +0000 @@ -206,9 +206,15 @@ */ 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; + spin_lock(&oom_lock); now = jiffies; since = now - last; last = now; @@ -227,14 +233,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 @@ -243,15 +249,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 (time_after(now, first)) + first = now; count = 0; + +out_unlock: + spin_unlock(&oom_lock); }