mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rik van Riel <riel@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, srikar@linux.vnet.ibm.com,
	mingo@kernel.org, mgorman@suse.de
Subject: [PATCH] sched,numa: document and fix numa_preferred_nid setting
Date: Tue, 16 Jun 2015 15:54:50 -0400	[thread overview]
Message-ID: <20150616155450.62ec234b@cuia.usersys.redhat.com> (raw)

There are two places where the numa balancing code sets a task's
numa_preferred_nid.

The primary location is task_numa_placement(), where the kernel
examines the NUMA fault statistics to determine the location where
most of the memory that the task (or numa_group) accesses is.

The second location is only used for large workloads, where a
numa_group has enough tasks that the tasks are spread out over
several NUMA nodes, and multiple nodes are in the numa group's
active_nodes mask.

In order to allow those workloads to settle down, we pretend
that any node inside the numa_group's active_nodes mask is the
task's new preferred node. This dissuades task_numa_fault()
from continuously retrying to migrate the task to the group's
preferred node, and allows a multi-node workload to settle down.
This in turn improves locality of private faults inside a numa
group.

Reported-by: Shrikar Dronamraju <srikar@linux.vnet.ibm.com>
Signed-off-by: Rik van Riel <riel@redhat.com>
---
 kernel/sched/fair.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index c2980e8733bc..54bb57f09e75 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1485,7 +1485,12 @@ static int task_numa_migrate(struct task_struct *p)
 				groupweight = group_weight(p, env.src_nid, dist);
 			}
 
-			/* Only consider nodes where both task and groups benefit */
+			/*
+			 * Only consider nodes where placement is better for
+			 * either the group (help large workloads converge),
+			 * or the task (placement of tasks within a numa group,
+			 * and single threaded processes).
+			 */
 			taskimp = task_weight(p, nid, dist) - taskweight;
 			groupimp = group_weight(p, nid, dist) - groupweight;
 			if (taskimp < 0 && groupimp < 0)
@@ -1499,12 +1504,14 @@ static int task_numa_migrate(struct task_struct *p)
 	}
 
 	/*
-	 * If the task is part of a workload that spans multiple NUMA nodes,
-	 * and is migrating into one of the workload's active nodes, remember
-	 * this node as the task's preferred numa node, so the workload can
-	 * settle down.
-	 * A task that migrated to a second choice node will be better off
-	 * trying for a better one later. Do not set the preferred node here.
+	 * The primary place for setting a task's numa_preferred_nid is in
+	 * task_numa_placement(). If a task is moved to a sub-optimal node,
+	 * leave numa_preferred_nid alone, so task_numa_fault() will retry
+	 * migrating the task to where it really belongs.
+	 * The exception is a task that belongs to a large numa_group, which
+	 * spans multiple NUMA nodes. If that task migrates into one of the
+	 * workload's active nodes, remember that node as the task's
+	 * numa_preferred_nid, so the workload can settle down.
 	 */
 	if (p->numa_group) {
 		if (env.best_cpu == -1)
@@ -1513,7 +1520,7 @@ static int task_numa_migrate(struct task_struct *p)
 			nid = env.dst_nid;
 
 		if (node_isset(nid, p->numa_group->active_nodes))
-			sched_setnuma(p, env.dst_nid);
+			sched_setnuma(p, nid);
 	}
 
 	/* No better CPU than the current one was found. */


             reply	other threads:[~2015-06-16 19:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-16 19:54 Rik van Riel [this message]
2015-06-18 15:55 ` Srikar Dronamraju
2015-06-18 16:06   ` Rik van Riel
2015-06-18 16:41     ` Srikar Dronamraju
2015-06-18 17:00       ` Rik van Riel
2015-06-18 17:11         ` Srikar Dronamraju
2015-06-19 17:16         ` Srikar Dronamraju
2015-06-19 17:52           ` Rik van Riel
2015-06-22 16:04             ` Srikar Dronamraju
2015-06-22 16:48           ` Srikar Dronamraju
2015-06-18 16:12   ` Ingo Molnar
2015-06-18 18:16     ` Rik van Riel
2015-06-22 16:13 ` Srikar Dronamraju
2015-06-22 22:28   ` Rik van Riel

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=20150616155450.62ec234b@cuia.usersys.redhat.com \
    --to=riel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=srikar@linux.vnet.ibm.com \
    /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

all inboxes | Powered by JetHome®