Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2557495ybv; Mon, 24 Feb 2020 07:22:54 -0800 (PST) X-Google-Smtp-Source: APXvYqzEHa8TG9hw9XHqh6Q5nddfzrZDRq+DhLjnyuXE8rUJetf7AjKF7EuXNdQxRfD3hnN40odg X-Received: by 2002:a9d:7410:: with SMTP id n16mr41684896otk.23.1582557774322; Mon, 24 Feb 2020 07:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582557774; cv=none; d=google.com; s=arc-20160816; b=Vj3jopGfVU86v79/AvE/4j2MZ1ikcQHiDtU1m9byQSOX4nQ1IOJMP92X1nVP+9Wm5W 3u7v/iGLf7iCbZlegtrWIgf7mrGVEyWWiW0/YUeR85cthPEwTry/UJil5pSl/0XuRmtn uq1hjPxA+r7tbp12VYvuNDx3Eeepo/jNRX0UI5GzHKQNGiTHEEi+77bfjI5CB05c8FM7 /lfIxzi0okpbYFzdIK6WE1Gi9bddCzNb+UXSKbM/z2ZK18Tw/mPEePHkEGbV5zRFcOqo oMUwyvzIRsKPyGZ8oc7wq29HhVWqjZXeIEW95rusnBzAI6319/DDVfl8J2Ib6BSl8EU7 W/bA== 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=b+Ef71FSwu430v4dplWvYO82H9AWfc+WCQ+//O8qrIk=; b=jo9dmBUMStDnK+kTwSmBV6dsKc8Dc8wXHpxEjkn7LQx2mrLU8xSEer5xDYI9kCngZx ed9lt7+z9vQCwjkyZz7oYw4KSvQDnV1nSgMpVTpzM/slJ9sDVV+EtIMeW5tecvcOiUk4 ie5R63BsQXupNcGqFK8/UtllPucnDOf7FlH/33nrSKM2LS7pr9uNfWxC/pFuRwIYdnoT T5YBTx4AXw6G0T7epcyr8MGIt3QcFP9jfScN6m0hahpgQJenhKe4pv1mgKOAhrZLJ6dv GicUNsPFwu4r9vzP7aTGpTNEs0F8jRPz1QhE6/pqpGE8z4dFho/Ks+n1VCtv55oJNzve KjCA== 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 m9si4874140oie.148.2020.02.24.07.22.41; Mon, 24 Feb 2020 07:22:54 -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 S1728190AbgBXPVN (ORCPT + 99 others); Mon, 24 Feb 2020 10:21:13 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:50380 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727701AbgBXPVI (ORCPT ); Mon, 24 Feb 2020 10:21:08 -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 1j6FX5-0005q1-2o; Mon, 24 Feb 2020 16:20:31 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id B65971C213E; Mon, 24 Feb 2020 16:20:30 +0100 (CET) Date: Mon, 24 Feb 2020 15:20:30 -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: Find an alternative idle CPU if the CPU is part of an active NUMA balance 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-12-mgorman@techsingularity.net> References: <20200224095223.13361-12-mgorman@techsingularity.net> MIME-Version: 1.0 Message-ID: <158255763050.28353.15038756479892807074.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: 5fb52dd93a2fe9a738f730de9da108bd1f6c30d0 Gitweb: https://git.kernel.org/tip/5fb52dd93a2fe9a738f730de9da108bd1f6c30d0 Author: Mel Gorman AuthorDate: Mon, 24 Feb 2020 09:52:21 Committer: Ingo Molnar CommitterDate: Mon, 24 Feb 2020 11:36:39 +01:00 sched/numa: Find an alternative idle CPU if the CPU is part of an active NUMA balance Multiple tasks can attempt to select and idle CPU but fail because numa_migrate_on is already set and the migration fails. Instead of failing, scan for an alternative idle CPU. select_idle_sibling is not used because it requires IRQs to be disabled and it ignores numa_migrate_on allowing multiple tasks to stack. This scan may still fail if there are idle candidate CPUs due to races but if this occurs, it's best that a task stay on an available CPU that move to a contended one. 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-12-mgorman@techsingularity.net --- kernel/sched/fair.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 2da21f4..050c1b1 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1624,15 +1624,34 @@ static void task_numa_assign(struct task_numa_env *env, { struct rq *rq = cpu_rq(env->dst_cpu); - /* Bail out if run-queue part of active NUMA balance. */ - if (env->best_cpu != env->dst_cpu && xchg(&rq->numa_migrate_on, 1)) + /* Check if run-queue part of active NUMA balance. */ + if (env->best_cpu != env->dst_cpu && xchg(&rq->numa_migrate_on, 1)) { + int cpu; + int start = env->dst_cpu; + + /* Find alternative idle CPU. */ + for_each_cpu_wrap(cpu, cpumask_of_node(env->dst_nid), start) { + if (cpu == env->best_cpu || !idle_cpu(cpu) || + !cpumask_test_cpu(cpu, env->p->cpus_ptr)) { + continue; + } + + env->dst_cpu = cpu; + rq = cpu_rq(env->dst_cpu); + if (!xchg(&rq->numa_migrate_on, 1)) + goto assign; + } + + /* Failed to find an alternative idle CPU */ return; + } +assign: /* * Clear previous best_cpu/rq numa-migrate flag, since task now * found a better CPU to move/swap. */ - if (env->best_cpu != -1) { + if (env->best_cpu != -1 && env->best_cpu != env->dst_cpu) { rq = cpu_rq(env->best_cpu); WRITE_ONCE(rq->numa_migrate_on, 0); } @@ -1806,21 +1825,6 @@ assign: cpu = env->best_cpu; } - /* - * Use select_idle_sibling if the previously found idle CPU is - * not idle any more. - */ - if (!idle_cpu(cpu)) { - /* - * select_idle_siblings() uses an per-CPU cpumask that - * can be used from IRQ context. - */ - local_irq_disable(); - cpu = select_idle_sibling(env->p, env->src_cpu, - env->dst_cpu); - local_irq_enable(); - } - env->dst_cpu = cpu; }