linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Davis <linux@j-davis.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH] badness() dramatically overcounts memory
Date: Mon, 04 Feb 2008 19:34:40 -0800	[thread overview]
Message-ID: <1202182480.24634.22.camel@dogma.ljc.laika.com> (raw)

[-- 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);
 	}
 

             reply	other threads:[~2008-02-05  3:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-05  3:34 Jeff Davis [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1202182480.24634.22.camel@dogma.ljc.laika.com \
    --to=linux@j-davis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox