Received: by 2002:a05:7412:8d06:b0:f9:332d:97f1 with SMTP id bj6csp58399rdb; Mon, 18 Dec 2023 08:52:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZ/NLwCZmY12JKVqWiM+6SiqTxijtW3xkeTPSH8gTnEB+wyZukrB8PyeJC4ZgJE/tLKopV X-Received: by 2002:a05:6402:2227:b0:54d:8cc9:83e4 with SMTP id cr7-20020a056402222700b0054d8cc983e4mr5559129edb.67.1702918321089; Mon, 18 Dec 2023 08:52:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702918321; cv=none; d=google.com; s=arc-20160816; b=VWKy4B+dlpyO3g0YaXFNsIDLA6tWC55v9nZ5OY+V19WS76zAaHzBdrR4x30TI6u7K9 QI3A1+mvhk3KbCw/fqVQrM86TK/MpnwDAtvJxP9Kii9tbLDihxK2uhbB5veMM2Lgsw3r x/9vsldXgnUEMTXvrFZnNSf1bUmMKAxt5hjyVEGFH+D7h6WTeqnigSa+2cyWgiXti4J5 6A3PXu53hQ2LYodcaENKXKJDgrywMrmJ8hw5yDHVS3WQqpRvhlMoHoqoQSMUay6FDW91 80exHzi31bG4rCNmJoEYmOoGhw0nA4geYE87ndIBSh6EnTaTGJhsP/GlWK70R1EcmP/r mJTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=jMaYOj60MeA1wo8ZfKzowtN5dTe49uBMZepjxPs8KMA=; fh=Wy7+XHGtqFRLkY+fLMgiHyxcgVbVxArFUwNhSd5kz5U=; b=W2x8/LFWzPBTWvemQyesXf1PiQfJAcZJDMsQBSxYDZzsr6VOO24RRmzJiJjNglVUCA 5cgvgmu3isBnZFTX7a1Rc6KiNPmdvn3wXqFRd6G/Mf9uCUrWB60V3XOXtrcvVGA5LMqQ Uf2F8cc4os3EjzlglzgTDsTcEcsgCjQkT/gA7BlNhaAu6r6gyxVCMlDqFyeNX3S5d65F hcn4M8rHafbBK7kK4JKqd8vstL+iXPUpGHH0bZ1Z7vfr2u+7VPCTQ45HG4eKJdO0FZWN YCW+HyWEPoR7T8K2bZiDAn+hZtu/vfanpD5DifdY2sYzgXbhQG2hTFtngsr9QpFD68l8 qZ8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Dyym2sDt; spf=pass (google.com: domain of linux-kernel+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r24-20020a50c018000000b0054cdd0ecab8si9834376edb.589.2023.12.18.08.52.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 08:52:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Dyym2sDt; spf=pass (google.com: domain of linux-kernel+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0EB871F258FA for ; Mon, 18 Dec 2023 16:49:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D02A49895; Mon, 18 Dec 2023 16:48:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Dyym2sDt" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 808524FF66 for ; Mon, 18 Dec 2023 16:48:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d32c5ce32eso31538295ad.0 for ; Mon, 18 Dec 2023 08:48:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702918131; x=1703522931; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jMaYOj60MeA1wo8ZfKzowtN5dTe49uBMZepjxPs8KMA=; b=Dyym2sDteFnWUXd8OrDZDuaCrPPWMK6SFcTFQ9hT0S546nsI/R73g1U1j5wVgKUNSq lryO73tPsAhNOt8D9Sfu7983Mx0uMrw9Uz0Jxg9M9JXofmr9SiMp1tYXDxd/7Yvb7dAV 9V/+eAZ9PlxUW8ncCaniYoaQnULCz7xLF1DrkJzLM6oJap3NM3FJUMqxZYu2eQJ9jHk+ lE/Um5TLqAMr0L9Q8XIzxPwdEZVzjcmTiDtlr20hHb+ftiVsb+21iPGL2Viq23LxUpFn X2Y0K6VhrH5UxQx5HBcT9jnmnoxkHU4IGEaM1o1FoIDaJ3xQklgKpv0rA/cySxYvg7ik 7D0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702918131; x=1703522931; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jMaYOj60MeA1wo8ZfKzowtN5dTe49uBMZepjxPs8KMA=; b=IX6jwwNS7ahpSmAA8kvAIqTML0qbkoy6668NE3NPZDzJOh7hacc6kj/XRi26PuuEIe 7Hoq6KHKE7vIOCYjAxh6k+Wk266kVfTLCk5eNZgBVJzXbzA1cULdnNa/jp137seJqWyP 9csGKMOrk2oDH4R0aI4iJddFMYKuADIXhqHkUMZ3Gt2hkR4XEjFY7R+rKx7alAZQv2wk EL2eQhqXrEONKypkjjezA/ei2V2/u0/cDrVevwZIGA9GHbs5ojZ3yZlwhRuS4JL/cBWs jxEjVHBEAAuPl6iOZaI61fYHhzSD45WZaAEaGmr8n0BKq3X7uyvsdUt+iVl7CUk6hX9l pqhw== X-Gm-Message-State: AOJu0Yxp7g1bZzDghfkfaOpY/lbkJiisbwsgZkdXE60s6JnNWhj7WOGk 8BNb91V5a7oBMDjEmXS+VY7Sg2LOBHPj70/Yoxv2ew== X-Received: by 2002:a17:90a:d143:b0:286:6cd8:ef04 with SMTP id t3-20020a17090ad14300b002866cd8ef04mr21128337pjw.28.1702918130794; Mon, 18 Dec 2023 08:48:50 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231214144204.2179345-1-khorenko@virtuozzo.com> In-Reply-To: <20231214144204.2179345-1-khorenko@virtuozzo.com> From: Vincent Guittot Date: Mon, 18 Dec 2023 17:48:39 +0100 Message-ID: Subject: Re: [PATCH] sched/fair: Do not scan non-movable tasks several times To: Konstantin Khorenko Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Alexander Atanasov , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Thu, 14 Dec 2023 at 15:42, Konstantin Khorenko wrote: > > If busiest rq is small, nr_running < SCHED_NR_MIGRATE_BREAK and all > tasks are not movable, detach_tasks() should not iterate more than tasks > available in the busiest rq. > > Previously the (env->loop > env->loop_max) condition prevented us from It's usually better to give the commit directly when we know it : Before commit : b0defa7ae03e ("sched/fair: Make sure to try to detach at least one movable task"), the (env->loop > env->loop_max) condition prevented us from ... > scanning non-movable tasks more than rq size times, but after we start > checking the LBF_ALL_PINNED flag, the "all tasks are not movable" case > is under threat. > Fixes: b0defa7ae03e ("sched/fair: Make sure to try to detach at least one movable task") > Signed-off-by: Konstantin Khorenko > --- > kernel/sched/fair.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index d7a3c63a2171..faa2a765e899 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -11219,7 +11219,6 @@ static int load_balance(int this_cpu, struct rq *this_rq, > .dst_rq = this_rq, > .dst_grpmask = group_balance_mask(sd->groups), > .idle = idle, > - .loop_break = SCHED_NR_MIGRATE_BREAK, > .cpus = cpus, > .fbq_type = all, > .tasks = LIST_HEAD_INIT(env.tasks), > @@ -11265,6 +11264,12 @@ static int load_balance(int this_cpu, struct rq *this_rq, > * correctly treated as an imbalance. > */ > env.loop_max = min(sysctl_sched_nr_migrate, busiest->nr_running); > + /* > + * If busiest rq is small, nr_running < SCHED_NR_MIGRATE_BREAK > + * and all tasks are not movable, detach_tasks() should not > + * iterate more than tasks available in rq. > + */ > + env.loop_break = min(SCHED_NR_MIGRATE_BREAK, busiest->nr_running); Should it be after more_balance: ? In case we do "more_balance:" on a new_dst_cpu and it ends up that finally there is no more movable task as we released the lock of busiest rq in the meantime ? Also you can remove one more superfluous init of loop_break: --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -11361,7 +11361,6 @@ static int load_balance(int this_cpu, struct rq *this_rq, */ if (!cpumask_subset(cpus, env.dst_grpmask)) { env.loop = 0; - env.loop_break = SCHED_NR_MIGRATE_BREAK; goto redo; } goto out_all_pinned; > > more_balance: > rq_lock_irqsave(busiest, &rf); > -- > 2.39.3 >