patch-2.4.7 linux/mm/oom_kill.c

Next file: linux/mm/shmem.c
Previous file: linux/mm/memory.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.6/linux/mm/oom_kill.c linux/mm/oom_kill.c
@@ -191,11 +191,28 @@
  */
 int out_of_memory(void)
 {
+	long cache_mem, limit;
+
 	/* Enough free memory?  Not OOM. */
 	if (nr_free_pages() > freepages.min)
 		return 0;
 
 	if (nr_free_pages() + nr_inactive_clean_pages() > freepages.low)
+		return 0;
+
+	/*
+	 * If the buffer and page cache (excluding swap cache) are over
+	 * their (/proc tunable) minimum, we're still not OOM.  We test
+	 * this to make sure we don't return OOM when the system simply
+	 * has a hard time with the cache.
+	 */
+	cache_mem = atomic_read(&page_cache_size);
+	cache_mem += atomic_read(&buffermem_pages);
+	cache_mem -= swapper_space.nrpages;
+	limit = (page_cache.min_percent + buffer_mem.min_percent);
+	limit *= num_physpages / 100;
+
+	if (cache_mem > limit)
 		return 0;
 
 	/* Enough swap space left?  Not OOM. */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)