linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] badness() dramatically overcounts memory
@ 2008-02-05  3:34 Jeff Davis
  2008-02-05  4:13 ` Balbir Singh
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff Davis @ 2008-02-05  3:34 UTC (permalink / raw)
  To: linux-kernel, linux-mm

[-- Attachment #1: Type: text/plain, Size: 821 bytes --]


In oom_kill.c, one of the badness calculations is wildly inaccurate. If
memory is shared among child processes, that same memory will be counted
for each child, effectively multiplying the memory penalty by N, where N
is the number of children.

This makes it almost certain that the parent will always be chosen as
the victim of the OOM killer (assuming any substantial amount memory
shared among the children), even if the parent and children are well
behaved and have a reasonable and unchanging VM size.

Usually this does not actually alleviate the memory pressure because the
truly bad process is completely unrelated; and the OOM killer must later
kill the truly bad process.

This trivial patch corrects the calculation so that it does not count a
child's shared memory against the parent.

Regards,
	Jeff Davis

[-- Attachment #2: linux-badness.diff --]
[-- Type: text/x-patch, Size: 776 bytes --]

--- mm/oom_kill.c.orig	2007-08-01 10:41:53.000000000 -0700
+++ mm/oom_kill.c	2008-02-04 14:47:10.000000000 -0800
@@ -83,11 +83,14 @@
 	 * machine with an endless amount of children. In case a single
 	 * child is eating the vast majority of memory, adding only half
 	 * to the parents will make the child our kill candidate of choice.
+	 * When counting the children's vmsize against the parent, we
+	 * subtract shared_vm first, to avoid overcounting memory that is
+	 * shared among the child processes and the parent.
 	 */
 	list_for_each_entry(child, &p->children, sibling) {
 		task_lock(child);
 		if (child->mm != mm && child->mm)
-			points += child->mm->total_vm/2 + 1;
+			points += (child->mm->total_vm - child->mm->shared_vm)/2 + 1;
 		task_unlock(child);
 	}
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-02-06  4:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-05  3:34 [PATCH] badness() dramatically overcounts memory Jeff Davis
2008-02-05  4:13 ` Balbir Singh
2008-02-05 23:02   ` Jeff Davis
2008-02-05 23:09     ` David Rientjes
2008-02-06  1:54       ` KOSAKI Motohiro
2008-02-06  2:05         ` David Rientjes
2008-02-06  4:00         ` Balbir Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).