Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2248575ybv; Mon, 24 Feb 2020 01:55:39 -0800 (PST) X-Google-Smtp-Source: APXvYqzIwkyA5DDvcYm/g+DlKlX8pOo8W21S4Y1wgG3hlumTPbEB14RCx0K8Xf5BMuivPzFi22a3 X-Received: by 2002:aca:37c3:: with SMTP id e186mr12280267oia.155.1582538139239; Mon, 24 Feb 2020 01:55:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582538139; cv=none; d=google.com; s=arc-20160816; b=MZ/EjLt8OwhV35n9Ssrj6GUGD9L2Q0BYbMZDCijg1gDTQaHjTtNKRxp+x8rfiwry2+ p5zc+W6l8MoonooRQb4qqNoGfee3hNBAqSvdRMWemerodZwHruF9rEW2NcxKo/2UZdZT BQhMhBhJvEVb58c4eIKSd4WVpF4E2L7ko3dCnSvwPNd2Z7ltfr3rvUXrbCXppWg8WD8U yQ3eEKSjspbUFbWVAfCVS4m+mBggEuGXg0rBsyCoA2SGe4qYnfqAZEPuf47SlALszXD3 iekLgjF5Nk7kNutdhGVROTjR+O2et/UIPyS/rElpBK/ntac0Ftb+wfAIdrALx9Ua72+4 RSlQ== 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=ioAVBfF0IUUP27oRGaav2zfxYJ9t3IesQNy/SfqfU30=; b=KkIMDSwAghTulT3VvYT4U59j4RDhPKsD+e3bS+w9Ikl93FrHoH4bvd+sOYzWipxlQp RYcjSkaaIHKpEHv5+TuitAoCa442PtISvgRLBNNzih2X+HPFYv97IV4YLSjPkFyFEemw 6PXgWpbOhJwNU5TaVQfLI+Ug+SvVLApBvSRLjlk8nmr0LUdPO8rXDnfEzcxRHx52Z06T wEvXBGN1Fk7cuK+ZmgxHfr6svBjUDTo/lzt51NhbDf8JUYMYMaRv2A/I69mZe+GbOWIZ 9Pljg1hOC1OgjXUqA5GrBgmF02TtJB56i2TkaywdTftTmQNEI6Loo6QWahjqxTCwCgfg c/mA== 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 o25si6626261otk.28.2020.02.24.01.55.27; Mon, 24 Feb 2020 01:55:39 -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 S1727758AbgBXJyu (ORCPT + 99 others); Mon, 24 Feb 2020 04:54:50 -0500 Received: from outbound-smtp29.blacknight.com ([81.17.249.32]:50969 "EHLO outbound-smtp29.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726765AbgBXJyu (ORCPT ); Mon, 24 Feb 2020 04:54:50 -0500 Received: from mail.blacknight.com (pemlinmail04.blacknight.ie [81.17.254.17]) by outbound-smtp29.blacknight.com (Postfix) with ESMTPS id 3BBD3BED4B for ; Mon, 24 Feb 2020 09:54:48 +0000 (GMT) Received: (qmail 28280 invoked from network); 24 Feb 2020 09:54:47 -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:47 -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 13/13] sched/numa: Stop an exhastive search if a reasonable swap candidate or idle CPU is found Date: Mon, 24 Feb 2020 09:52:23 +0000 Message-Id: <20200224095223.13361-14-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 domains are imbalanced or overloaded a search of all CPUs on the target domain is searched and compared with task_numa_compare. In some circumstances, a candidate is found that is an obvious win. o A task can move to an idle CPU and an idle CPU is found o A swap candidate is found that would move to its preferred domain This patch terminates the search when either condition is met. Signed-off-by: Mel Gorman --- kernel/sched/fair.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 63f22b1a5f0b..3f51586365f3 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1707,7 +1707,7 @@ static bool load_too_imbalanced(long src_load, long dst_load, * into account that it might be best if task running on the dst_cpu should * be exchanged with the source task */ -static void task_numa_compare(struct task_numa_env *env, +static bool task_numa_compare(struct task_numa_env *env, long taskimp, long groupimp, bool maymove) { struct numa_group *cur_ng, *p_ng = deref_curr_numa_group(env->p); @@ -1718,9 +1718,10 @@ static void task_numa_compare(struct task_numa_env *env, int dist = env->dist; long moveimp = imp; long load; + bool stopsearch = false; if (READ_ONCE(dst_rq->numa_migrate_on)) - return; + return false; rcu_read_lock(); cur = rcu_dereference(dst_rq->curr); @@ -1731,8 +1732,10 @@ static void task_numa_compare(struct task_numa_env *env, * Because we have preemption enabled we can get migrated around and * end try selecting ourselves (current == env->p) as a swap candidate. */ - if (cur == env->p) + if (cur == env->p) { + stopsearch = true; goto unlock; + } if (!cur) { if (maymove && moveimp >= env->best_imp) @@ -1860,8 +1863,27 @@ static void task_numa_compare(struct task_numa_env *env, } task_numa_assign(env, cur, imp); + + /* + * If a move to idle is allowed because there is capacity or load + * balance improves then stop the search. While a better swap + * candidate may exist, a search is not free. + */ + if (maymove && !cur && env->best_cpu >= 0 && idle_cpu(env->best_cpu)) + stopsearch = true; + + /* + * If a swap candidate must be identified and the current best task + * moves its preferred node then stop the search. + */ + if (!maymove && env->best_task && + env->best_task->numa_preferred_nid == env->src_nid) { + stopsearch = true; + } unlock: rcu_read_unlock(); + + return stopsearch; } static void task_numa_find_cpu(struct task_numa_env *env, @@ -1916,7 +1938,8 @@ static void task_numa_find_cpu(struct task_numa_env *env, continue; env->dst_cpu = cpu; - task_numa_compare(env, taskimp, groupimp, maymove); + if (task_numa_compare(env, taskimp, groupimp, maymove)) + break; } } -- 2.16.4