From nobody Sat Dec 27 22:51:35 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 162E4C4332F for ; Thu, 14 Dec 2023 14:42:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573540AbjLNOmX (ORCPT ); Thu, 14 Dec 2023 09:42:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230293AbjLNOmU (ORCPT ); Thu, 14 Dec 2023 09:42:20 -0500 Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C7B410F for ; Thu, 14 Dec 2023 06:42:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-Id:Date:Subject:From: Content-Type; bh=jqR1PdpxUe277eWAS5cvqpQThpJfFkZiLbIzwxpvjek=; b=NXTQcpriBuGC aIOUskXuamralQFLA9YtboOEW736Fgcj65KZgLC/l33D9ZjAih+o7ZqQZqMNOswWPwKNJ7oEaQs8x H1v4XpnQ6ytCy7eCzwTwKXYR9Wtpxqw9AoXn/UI6FVxGIwwpXPdAQOq6CyY+TdHN8BLQY+kKtMAmc Qb6I5p0K61MLq0oQY8yCH/AqmPqTCVtpeoJPMgg+ZRh7gheCI1l+xS1KnvmYGsiNY1U/+hr79iBrv 6syD4DhJkcguuckWtt7Ti8xYcK0+oDFrPxFAS5dc7upJFmQPit0BHFHD2Ljae1k0x3ppY57WpdSaj vr1XTkdMLpOqvS9JTsQ+VA==; Received: from [130.117.225.1] (helo=finist-alma9.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1rDmsh-001CPb-0g; Thu, 14 Dec 2023 15:42:04 +0100 From: Konstantin Khorenko To: Vincent Guittot , Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider Cc: Alexander Atanasov , linux-kernel@vger.kernel.org Subject: [PATCH] sched/fair: Do not scan non-movable tasks several times Date: Thu, 14 Dec 2023 17:42:04 +0300 Message-Id: <20231214144204.2179345-1-khorenko@virtuozzo.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 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. 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 *th= is_rq, .dst_rq =3D this_rq, .dst_grpmask =3D group_balance_mask(sd->groups), .idle =3D idle, - .loop_break =3D SCHED_NR_MIGRATE_BREAK, .cpus =3D cpus, .fbq_type =3D all, .tasks =3D LIST_HEAD_INIT(env.tasks), @@ -11265,6 +11264,12 @@ static int load_balance(int this_cpu, struct rq *t= his_rq, * correctly treated as an imbalance. */ env.loop_max =3D 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 =3D min(SCHED_NR_MIGRATE_BREAK, busiest->nr_running); =20 more_balance: rq_lock_irqsave(busiest, &rf); --=20 2.39.3