Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6031451rdb; Thu, 14 Dec 2023 06:42:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAv00c6mRjHAej2sYzTBb/cg2eaQHQvnHNw3+drhxYGVVnt9C2/RuGOMNfDzbEnuJcatzO X-Received: by 2002:a17:90a:458c:b0:286:6cc1:780c with SMTP id v12-20020a17090a458c00b002866cc1780cmr8069716pjg.79.1702564960188; Thu, 14 Dec 2023 06:42:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702564960; cv=none; d=google.com; s=arc-20160816; b=awBqXwCPB39ukeEOQlOlNKbLOvEmhJH26GbUbge/AqkPiCADiM/j/vawr+T7AZFIlp eZvgYGt2BG/lg7Mum22cTzf+CJUoRHXVRBITwX4T5EYD7F7svYHcUmaLlUrmbwoGe4ha +np+zBUBBKGQp/MqLEgh6gxAPGjJsvMqQFTRg+1t0qAckjDsaNcU3TnqFw+l0dk2dLzn gS9VVaQrUkn/COYeeSS/plgKbWiIKLhAhkKR2GIX182fpuKVMr0li2jCymO1ynWOeivb K0RyEwuB6lteAIVaj+6jJ3IU2X+lHoBpKpg3rqR9BMQIqsESvyDicOk1MB/Ud8dEMsqm I/mQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=jqR1PdpxUe277eWAS5cvqpQThpJfFkZiLbIzwxpvjek=; fh=5MqlMEhjfWsRY+67Qa9qp9GJc44OSuTbY2bEzSYcTxM=; b=vrso0Entnh9tqswEM4Is7OrkWp+3Y0nCmvmlqiALxgNifCDt7QCcbkeh4H3PwCWwUc IJpgBh0g7hy8WCCx6sUjH0KXOkoWfFejpU/IDOWAR1D2rmZXk1zXVhjLIRWjIa6ndo0k YFUQEITljzwFaUDVMXG7Tp/M30rpxre4G/O1AlVonkfySCc831IZFMajYGgItpGNJNWK 03gRMRWvID8tBXcy/U3nHPh5Na/Ml4bmI1uod8Q7qf1QrAtj/RIRm9APsM7riG5x6yQa VXUtFhk5YYJ69W3Y8YBZ6ZwvGR37pyAKVzboHfDKIN61NJPx/ikG+FWQdwHX0f+CRd4Q j5cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=NXTQcpri; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id i6-20020a17090ad34600b0028a281c4e9esi11124186pjx.129.2023.12.14.06.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 06:42:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=NXTQcpri; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 84249801B49D; Thu, 14 Dec 2023 06:42:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573497AbjLNOmW (ORCPT + 99 others); Thu, 14 Dec 2023 09:42:22 -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: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 14 Dec 2023 06:42:37 -0800 (PST) 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 *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); more_balance: rq_lock_irqsave(busiest, &rf); -- 2.39.3