Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2249155ybv; Mon, 24 Feb 2020 01:56:24 -0800 (PST) X-Google-Smtp-Source: APXvYqzh1c8BpBnwkgTH3qDyMC7LKJjRrfpm+sp9IErS7jyVtwHlmpC3a7sn+cXgW8D9TYzwHFc1 X-Received: by 2002:aca:f40a:: with SMTP id s10mr12087691oih.61.1582538184253; Mon, 24 Feb 2020 01:56:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582538184; cv=none; d=google.com; s=arc-20160816; b=YFb/H0ZicX6ZT70BDluA6+NkF+ylxzAJ3CXhgQDc9dPP/nHctmPHcRKN1e1d+0UjdC q2FRrX52GpIBBo9dHRrN3xfnwRE17XVO9T3nAwC/tpc0oqQDfzGj7CZw/4wGQfqClZyl +VHahhNusghaHerGZ8BrHYI/rDEGMr4mXGRg1bSR77OIvvqiOmxct+ra7VOdUHQp6S12 dCXKmd9ka0V/k4AnL2a5sXwk+zxratqcTLi9O6L0XInXHEjcaSvGGs63DIhPqt5iCeZq ReFld8Z4mGewsF2papNb6/s3+ZGftaFfEJHc2/1Ag42zrKzfpSsR+5S+0E4v+EtWKiMH eCQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=J5tBu0x8T9K2YvT/aIS9kvX7pVI8bA13QlvZ3PwNdN4=; b=hs8BygT+9Lm+6EK6G8O6g16D5kbQc7DJnLsyxskGj12mxPRv1uIGjuABg37ZaooLj2 kaJc6l/Gv2fCH136nq2rTQLb2x9TssR1ctDgXMIgQTPsgz/Y3wsWar3nK5mhc/LE7uC0 M8a84YDwmW8V0k4BVDcMhdMKq2uM/IhnZJIHYAwyzv8V0tnXLkoYFdyVcmrjOkgTDRuf cqxaEu3TDPbPJE0XVGFUvulJV9GSKCgrr5qfIMbCUhmro6PXIcj/dSy9ksIr2Vja1IRS 9DFZj10uQENwifeGg91UVdWjA+dmK+A6QNOlcYiQ8qk92qZOgZ4fGkTkG1XjUdTjZvum cXTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z4si5122207oix.48.2020.02.24.01.56.12; Mon, 24 Feb 2020 01:56:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727740AbgBXJyk (ORCPT + 99 others); Mon, 24 Feb 2020 04:54:40 -0500 Received: from outbound-smtp22.blacknight.com ([81.17.249.190]:49069 "EHLO outbound-smtp22.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726838AbgBXJyj (ORCPT ); Mon, 24 Feb 2020 04:54:39 -0500 Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp22.blacknight.com (Postfix) with ESMTPS id 05B74148004 for ; Mon, 24 Feb 2020 09:54:38 +0000 (GMT) Received: (qmail 27537 invoked from network); 24 Feb 2020 09:54:37 -0000 Received: from unknown (HELO stampy.112glenside.lan) (mgorman@techsingularity.net@[84.203.18.57]) by 81.17.254.9 with ESMTPA; 24 Feb 2020 09:54:37 -0000 From: Mel Gorman To: Peter Zijlstra Cc: Ingo Molnar , Vincent Guittot , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Valentin Schneider , Phil Auld , Hillf Danton , LKML , Mel Gorman Subject: [PATCH 12/13] sched/numa: Bias swapping tasks based on their preferred node Date: Mon, 24 Feb 2020 09:52:22 +0000 Message-Id: <20200224095223.13361-13-mgorman@techsingularity.net> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200224095223.13361-1-mgorman@techsingularity.net> References: <20200224095223.13361-1-mgorman@techsingularity.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When swapping tasks for NUMA balancing, it is preferred that tasks move to or remain on their preferred node. When considering an imbalance, encourage tasks to move to their preferred node and discourage tasks from moving away from their preferred node. Signed-off-by: Mel Gorman --- kernel/sched/fair.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index ee14cd9815ec..63f22b1a5f0b 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1741,18 +1741,27 @@ static void task_numa_compare(struct task_numa_env *env, goto unlock; } + /* Skip this swap candidate if cannot move to the source cpu. */ + if (!cpumask_test_cpu(env->src_cpu, cur->cpus_ptr)) + goto unlock; + + /* + * Skip this swap candidate if it is not moving to its preferred + * node and the best task is. + */ + if (env->best_task && + env->best_task->numa_preferred_nid == env->src_nid && + cur->numa_preferred_nid != env->src_nid) { + goto unlock; + } + /* * "imp" is the fault differential for the source task between the * source and destination node. Calculate the total differential for * the source task and potential destination task. The more negative * the value is, the more remote accesses that would be expected to * be incurred if the tasks were swapped. - */ - /* Skip this swap candidate if cannot move to the source cpu */ - if (!cpumask_test_cpu(env->src_cpu, cur->cpus_ptr)) - goto unlock; - - /* + * * If dst and source tasks are in the same NUMA group, or not * in any group then look only at task weights. */ @@ -1779,12 +1788,34 @@ static void task_numa_compare(struct task_numa_env *env, task_weight(cur, env->dst_nid, dist); } + /* Discourage picking a task already on its preferred node */ + if (cur->numa_preferred_nid == env->dst_nid) + imp -= imp / 16; + + /* + * Encourage picking a task that moves to its preferred node. + * This potentially makes imp larger than it's maximum of + * 1998 (see SMALLIMP and task_weight for why) but in this + * case, it does not matter. + */ + if (cur->numa_preferred_nid == env->src_nid) + imp += imp / 8; + if (maymove && moveimp > imp && moveimp > env->best_imp) { imp = moveimp; cur = NULL; goto assign; } + /* + * Prefer swapping with a task moving to its preferred node over a + * task that is not. + */ + if (env->best_task && cur->numa_preferred_nid == env->src_nid && + env->best_task->numa_preferred_nid != env->src_nid) { + goto assign; + } + /* * If the NUMA importance is less than SMALLIMP, * task migration might only result in ping pong -- 2.16.4