Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8421425rwi; Tue, 25 Oct 2022 06:34:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Ub647SFvMExxoqx7xpHGjdKYgjVjrI2PEFOAhkpAfrJdLe1H4TWC1FX353DHkhtyQ8ms6 X-Received: by 2002:a63:5266:0:b0:439:920b:fc65 with SMTP id s38-20020a635266000000b00439920bfc65mr32335004pgl.417.1666704860132; Tue, 25 Oct 2022 06:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666704860; cv=none; d=google.com; s=arc-20160816; b=yb8eXfqaavkuhkOSK659lVeEH6SzeMieFTL3nl/ayGECPFLNaFzkCv2m2eofCTQOJn cMqzLFKGhIopTkTiIxz6T9tCRld/yJQz6tdj7CpurO9pw5JPN2+2/bXfRfdRlHq/2vt9 o9MqWRf6+Bl0KB1mjNw07Q2LrnxnCKKwJEk6UQvYRaKwhyD3UkyC09DLKNeSAONy9zmI k9UhhGf8Z9hMGqym3WCcvGAP3Tf7MAXjA9aLuFZv2apOvDXrDBUg8IfKdOOMCF83QvA5 TSeRDPYsK2/UmH+BPer92WE4KFhcrfRac5PRtdZQlZx534hQEmZ2dxJ/kJ8wLnuHTMVY 0izg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=aw7BTwBAK9j7bNXL3GU5GR0xCIdsDDRJFGYrAEfGX/w=; b=JFuXEwZZ97iO2IWfZ2MiBnKofJN8sD8GB29xaHscNvilzTpTmzflhVCzVPVVOBftAt yytoyCw7y52VKgKfCe/nKRhHHd8sW9vAomSYQtTo0a4XDWnALOOT+eEa6xwLZ/Y8MESq KZfU8m8nsemCzW+I9pX+JsysgXFf5X5oRfabSkAHF7ihAadUX1/DCaegIZS9qNF9sfDh /KQtknto1XWFDVjupkexkQO/WES4J2gWhTyOePeB5tDnTD/XvMaZih5PEhELbPSUkYSl OhPQn12B7z2QG2IQ/saII8ySOiBe7OBFIbPPxgZVjZr+ZiGuQSs0ZYf9PNOlGpfyCidk 07lA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a17090a974600b00200b5c30f73si3035342pjw.106.2022.10.25.06.34.05; Tue, 25 Oct 2022 06:34:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232842AbiJYNce (ORCPT + 99 others); Tue, 25 Oct 2022 09:32:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232786AbiJYNcd (ORCPT ); Tue, 25 Oct 2022 09:32:33 -0400 Received: from outbound-smtp31.blacknight.com (outbound-smtp31.blacknight.com [81.17.249.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7201118B0A2 for ; Tue, 25 Oct 2022 06:32:32 -0700 (PDT) Received: from mail.blacknight.com (pemlinmail01.blacknight.ie [81.17.254.10]) by outbound-smtp31.blacknight.com (Postfix) with ESMTPS id A3875C0EA9 for ; Tue, 25 Oct 2022 14:32:30 +0100 (IST) Received: (qmail 3467 invoked from network); 25 Oct 2022 13:32:30 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.198.246]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 25 Oct 2022 13:32:30 -0000 Date: Tue, 25 Oct 2022 14:32:26 +0100 From: Mel Gorman To: Hao Jia Cc: Mel Gorman , mingo@redhat.com, peterz@infradead.org, mingo@kernel.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [External] Re: [PATCH 1/2] sched/numa: Stop an exhastive search if an idle core is found Message-ID: <20221025133226.ap6zeidoyea6jher@techsingularity.net> References: <20221021061558.34767-1-jiahao.os@bytedance.com> <20221021061558.34767-2-jiahao.os@bytedance.com> <20221024133435.e2kajx5k7jzznp25@suse.de> <20221025093226.dm4sjvdq2tofkwvc@suse.de> <71589225-a4fd-b3eb-14d5-81c9a19419a7@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <71589225-a4fd-b3eb-14d5-81c9a19419a7@bytedance.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 25, 2022 at 07:10:22PM +0800, Hao Jia wrote: > On 2022/10/25 Mel Gorman wrote: > > On Tue, Oct 25, 2022 at 11:16:29AM +0800, Hao Jia wrote: > > > > Remove the change in the first hunk and call break in the second hunk > > > > after updating ns->idle_cpu. > > > > > > > > > > Yes, thanks for your review. > > > If I understand correctly, some things might look like this. > > > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > > index e4a0b8bd941c..dfcb620bfe50 100644 > > > --- a/kernel/sched/fair.c > > > +++ b/kernel/sched/fair.c > > > @@ -1792,7 +1792,7 @@ static void update_numa_stats(struct task_numa_env > > > *env, > > > ns->nr_running += rq->cfs.h_nr_running; > > > ns->compute_capacity += capacity_of(cpu); > > > > > > - if (find_idle && !rq->nr_running && idle_cpu(cpu)) { > > > + if (find_idle && idle_core < 0 && !rq->nr_running && > > > idle_cpu(cpu)) { > > > if (READ_ONCE(rq->numa_migrate_on) || > > > !cpumask_test_cpu(cpu, env->p->cpus_ptr)) > > > continue; > > > > > > > I meant more like the below but today I wondered why did I not do this in > > the first place? The answer is because it's wrong and broken in concept. > > > > The full loop is needed to calculate approximate NUMA stats at a > > point in time. For example, the src and dst nr_running is needed by > > task_numa_find_cpu. The search for an idle CPU or core in update_numa_stats > > is simply taking advantage of the fact we are scanning anyway to keep > > track of an idle CPU or core to avoid a second search as per ff7db0bf24db > > ("sched/numa: Prefer using an idle CPU as a migration target instead of > > comparing tasks") > > > > The patch I had in mind is below but that said, for both your version and > > my initial suggestion > > > > Naked-by: Mel Gorman > > > > For the record, this is what I was suggesting initially because it's more > > efficient but it's wrong, don't do it. > > > > Thanks for the detailed explanation, maybe my commit message misled you. > Yes, I did end up confusing myself. The title and changelog referred to stopping a search which made me think of terms of "this whole loop can terminate early" which it can't but it *can* stop checking for a new idle core. If an idle core has been found, it follows that an idle CPU has also been found. While numa_idle_core checks this explicitly, your patch avoids an unnecessary cpumask_test_cpu so it has value. > Yes, we can't stop the whole loop of scanning the CPU because we have a lot > of NUMA information to count. > > But we can stop looking for the next idle core or idle cpu after finding an > idle core. > > So, please review the previous code. > You're right and sorry for the noise. Acked-by: Mel Gorman -- Mel Gorman SUSE Labs