Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2556336ybv; Mon, 24 Feb 2020 07:21:36 -0800 (PST) X-Google-Smtp-Source: APXvYqw4yjA/C1L5FGPWLTq+0AlKL96+EqLa9VA/dvJs3war8Hkda67NnyG8mdKiXzxJ3L5cRdpI X-Received: by 2002:aca:1a05:: with SMTP id a5mr12812796oia.97.1582557695871; Mon, 24 Feb 2020 07:21:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582557695; cv=none; d=google.com; s=arc-20160816; b=wOzfo2LRyqHGI200W37ZgHNThr3GdqGXQ9AlVNLOvQne5ZZpyVxjHJqJtCA2uYOC00 PG7FxlvJkN37Q8v5b43DAu0jz8fCokDesWusloqiypjsVCnc0dIZrWvxgz+hN4eTIs/b OAYHNa4a9J2cO+9lFd3i3yYSz2jI6hvBz0Jg+jpa7iVyejmEezRrtWisuiWCNOzd61lL 8WHon704Uw4jEtGpeqoCuPbxb1w/GyDVsZsJi6rwNqyreWLNtWBSO3Nx7ZOObLudBtpW Hr7bZ+8oE9gOYig68OamKkpJj7TTB/bQ2oNoVl4Uui++sRK+9CK17MBXOj1X1y1GdW7P ATCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=1cX8H8G9IE6Kv972KPOkgXgx91hRSN/wx+azJbjN+Wk=; b=IdX+LoHkvv64WuQ2hb1i8wdzcOiJEUnDRa/CcxZUCf/LY2X/0am2x8TGRLzIboik8s gwbj4rnB+E1AOZc1UZ2wfw/N0mlzCTXAkAu82QHkHoQBbx+Jga5E9s9QVubvvX19Mtml baWxtmZ4PUEgk9ufh2K9q6rEEk2wGXfpgUaPx7nqHhQxp6IzJPMUK52geenSt+Rzy8Q5 cjFMX7DXW5/M5uzLKcoIeVFRQqi2WN7rUNL93yPs/Z29IWVJ6TcDgV9fQYK4fn6Ca54T 5y8JhZp/Fm8lUlceZ58Mu8AVgbmv2LIFsrU5QduVbfX/34RC5N/A2PK3L8/rrJpCk2m8 82Hg== 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 s17si6490526otd.76.2020.02.24.07.21.23; Mon, 24 Feb 2020 07:21:35 -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 S1728105AbgBXPVD (ORCPT + 99 others); Mon, 24 Feb 2020 10:21:03 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:50363 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727701AbgBXPU6 (ORCPT ); Mon, 24 Feb 2020 10:20:58 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1j6FX4-0005py-P3; Mon, 24 Feb 2020 16:20:30 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 0CC001C213A; Mon, 24 Feb 2020 16:20:30 +0100 (CET) Date: Mon, 24 Feb 2020 15:20:29 -0000 From: "tip-bot2 for Mel Gorman" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/numa: Stop an exhastive search if a reasonable swap candidate or idle CPU is found Cc: Mel Gorman , Ingo Molnar , Peter Zijlstra , Vincent Guittot , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Valentin Schneider , Phil Auld , Hillf Danton , x86 , LKML In-Reply-To: <20200224095223.13361-14-mgorman@techsingularity.net> References: <20200224095223.13361-14-mgorman@techsingularity.net> MIME-Version: 1.0 Message-ID: <158255762967.28353.14025771290351307714.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: a0f03b617c3b2644d3d47bf7d9e60aed01bd5b10 Gitweb: https://git.kernel.org/tip/a0f03b617c3b2644d3d47bf7d9e60aed01bd5b10 Author: Mel Gorman AuthorDate: Mon, 24 Feb 2020 09:52:23 Committer: Ingo Molnar CommitterDate: Mon, 24 Feb 2020 11:36:40 +01:00 sched/numa: Stop an exhastive search if a reasonable swap candidate or idle CPU is found 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 Signed-off-by: Ingo Molnar Acked-by: Peter Zijlstra Cc: Vincent Guittot Cc: Juri Lelli Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Valentin Schneider Cc: Phil Auld Cc: Hillf Danton Link: https://lore.kernel.org/r/20200224095223.13361-14-mgorman@techsingularity.net --- 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 8c1ac01..fcc9686 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 @@ assign: } 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; } }