Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp749869pxf; Thu, 1 Apr 2021 12:32:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjuJ9ME3D2gQhHCpp+3CdiciS2BnurXEnzLN8t0AbimOSXWCw43zv1Nl15f1z768ATs8Ea X-Received: by 2002:a50:fd15:: with SMTP id i21mr11438295eds.384.1617305560349; Thu, 01 Apr 2021 12:32:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617305560; cv=none; d=google.com; s=arc-20160816; b=RAgvfjJEmhu6aKGvfpDXKIqsACaZLdfRpxsdJN+vFXHeLpo/uxCki7eq9vNCt4N05H PeAYWmNz80CcfGfv+dyWUazQa0OoT9g5VjLg9G8AS7p+EoYyLnLIhXpTNprmxj0P1YOj Axf/g+X50r2795l6wdSxTQh5OlO/9VJAR0KCR9AxqRTSiw2aummOGyuSUie+dxSYpOdG XfX4VLjmtOkiGZTRBZstJb+nscjAnsQ0nPOnTxxLYr8q4CAP9XYH9VzHbVDsha+VFrmb H644L9du2dWIGmdhVWxqr+UPkhhhPpgRWgg/mGPQYBma1JpB7+QP/L3ai/YG3q1k9Eml mRKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=bhr3Hi6njyDPjqtGClQ5zm00YksrXeVF5VezRzLG2VI=; b=niMmEJmc54Qv3DFHOj8BNU8m8SJX4fEMcO87orAiey9IY8G6yVSk6tOPjjQO4UyPsj UGNlIkAypfF0gmymJZch0N/UquZooi7g96lpEbSTRxyyElaclED9ILkqLDubHKUx9Zwx HRX8tZJCqZ+6orXi46EVfLaCGd9NcHpSnukqGSGC7/Uw+xI4GJBQrz2ENOoUQ+TktL4X EisOrTMoR3KnVil9lnFrJY89p8pIa6QXyjUFe5zST2wmWIqDdbLQ9GiFYMt+ZSevWHFf p9J3ttCjKuQfGKzfpl57Kby3YChilxsFGMuv3LnIacU9XBhDk32MlW06ygYgDcAQNr96 hhmA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lb23si4813371ejc.226.2021.04.01.12.32.17; Thu, 01 Apr 2021 12:32:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235014AbhDATaf (ORCPT + 99 others); Thu, 1 Apr 2021 15:30:35 -0400 Received: from foss.arm.com ([217.140.110.172]:48180 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234239AbhDATa1 (ORCPT ); Thu, 1 Apr 2021 15:30:27 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8945211B3; Thu, 1 Apr 2021 12:30:26 -0700 (PDT) Received: from e113632-lin.cambridge.arm.com (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 022B73F719; Thu, 1 Apr 2021 12:30:24 -0700 (PDT) From: Valentin Schneider To: linux-kernel@vger.kernel.org Cc: Lingutla Chandrasekhar , Peter Zijlstra , Ingo Molnar , Vincent Guittot , Dietmar Eggemann , Morten Rasmussen , Qais Yousef , Quentin Perret , Pavan Kondeti , Rik van Riel Subject: [PATCH v4 1/3] sched/fair: Ignore percpu threads for imbalance pulls Date: Thu, 1 Apr 2021 20:30:04 +0100 Message-Id: <20210401193006.3392788-2-valentin.schneider@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210401193006.3392788-1-valentin.schneider@arm.com> References: <20210401193006.3392788-1-valentin.schneider@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lingutla Chandrasekhar During load balance, LBF_SOME_PINNED will bet set if any candidate task cannot be detached due to CPU affinity constraints. This can result in setting env->sd->parent->sgc->group_imbalance, which can lead to a group being classified as group_imbalanced (rather than any of the other, lower group_type) when balancing at a higher level. In workloads involving a single task per CPU, LBF_SOME_PINNED can often be set due to per-CPU kthreads being the only other runnable tasks on any given rq. This results in changing the group classification during load-balance at higher levels when in reality there is nothing that can be done for this affinity constraint: per-CPU kthreads, as the name implies, don't get to move around (modulo hotplug shenanigans). It's not as clear for userspace tasks - a task could be in an N-CPU cpuset with N-1 offline CPUs, making it an "accidental" per-CPU task rather than an intended one. KTHREAD_IS_PER_CPU gives us an indisputable signal which we can leverage here to not set LBF_SOME_PINNED. Note that the aforementioned classification to group_imbalance (when nothing can be done) is especially problematic on big.LITTLE systems, which have a topology the likes of: DIE [ ] MC [ ][ ] 0 1 2 3 L L B B arch_scale_cpu_capacity(L) < arch_scale_cpu_capacity(B) Here, setting LBF_SOME_PINNED due to a per-CPU kthread when balancing at MC level on CPUs [0-1] will subsequently prevent CPUs [2-3] from classifying the [0-1] group as group_misfit_task when balancing at DIE level. Thus, if CPUs [0-1] are running CPU-bound (misfit) tasks, ill-timed per-CPU kthreads can significantly delay the upgmigration of said misfit tasks. Systems relying on ASYM_PACKING are likely to face similar issues. Signed-off-by: Lingutla Chandrasekhar [Use kthread_is_per_cpu() rather than p->nr_cpus_allowed] [Reword changelog] Signed-off-by: Valentin Schneider --- kernel/sched/fair.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 6d73bdbb2d40..04d5e14fa261 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7567,6 +7567,10 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env) if (throttled_lb_pair(task_group(p), env->src_cpu, env->dst_cpu)) return 0; + /* Disregard pcpu kthreads; they are where they need to be. */ + if ((p->flags & PF_KTHREAD) && kthread_is_per_cpu(p)) + return 0; + if (!cpumask_test_cpu(env->dst_cpu, p->cpus_ptr)) { int cpu; -- 2.25.1