From nobody Sun Feb 8 13:10:56 2026 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 BCCD9EB64DA for ; Wed, 14 Jun 2023 10:26:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243679AbjFNK05 (ORCPT ); Wed, 14 Jun 2023 06:26:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244128AbjFNKZD (ORCPT ); Wed, 14 Jun 2023 06:25:03 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2072.outbound.protection.outlook.com [40.107.237.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 120062953 for ; Wed, 14 Jun 2023 03:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UCYijIeafbeuKTFhe7499lsrg1jhf1v8Xt4sD2ijv2WA5xxiaXwGXsRq2iMTvfGtxj7n2JC9YwpcE/6KBb55CxiIWq2IzjAY+ZVOQ0RsqE61ol3ig6+ysJUfnImOVjki9VzwNBM8oTWeT0JAZS0xiVCYOjNI/FJHaNtQ/tVJjnlDDrg1Olb862uXi5JRr4Nm5nsiBBGqqHZiKrxElmhkFqUic4n9eXMPL/yilyUIUwUj7qvmx4O1KfwVYIExDGqLjpRjPThLQ9lFareSnN6QJE5LfnNL3goURKrVySqmEagM0dcE8mMvwMDqAHlnuGXzxDlRZzSyIJG84XgbfWRhmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Dgt0QWMx5bd0v4vd0jbJgZA6l9c/8LIhFFS9l8EzmUw=; b=ZE8ge1OOts4TzM8CPRCvU2h+2Q4xh14FA0AtRkn8zJ+0EkXEHpoHo73sWdUbPlArLFGuBenQkxe88f9wsEikvhn4GcVVxqvylTdU9nuiqkCmoeQwfNjPn+FFmZBJx5rFDT7+acQpmijC1lg+YTyt2c4vyIr4CJ83Jba1AynwvL0oYfhFcp8mrZwwg4KqLGqzUGvnG8ue9Nq/CbuFqqWVLRjvCi/g8eniyKIADgbTcx2YzCzxsqU1MbQpKjf7hzSU7++IWzawshBPbJCkzJxlfwaeraz1o9vz4EJl9i1FekkgSDI6aNldUcMMJjpnKLgfjsAmbJoy/8nHsd2Ei1KiGA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Dgt0QWMx5bd0v4vd0jbJgZA6l9c/8LIhFFS9l8EzmUw=; b=2ED10C8JXwOYKSJnPWfUD6aqI52gdexif4n74d/V6Y5IkDn2KshSRxYmNeVrSYvgHKx7ek/BDwTOH+zkMixix0OZ8zDozGN5QCKpLM44u8tHwgDrvXThTF7J5dxhKJI5aqUCQNqCMoyIPJHAbj4J+UDtISBsSPM8jiHnudVMZzE= Received: from DS7PR05CA0089.namprd05.prod.outlook.com (2603:10b6:8:56::6) by SA3PR12MB9106.namprd12.prod.outlook.com (2603:10b6:806:37e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.41; Wed, 14 Jun 2023 10:23:18 +0000 Received: from CY4PEPF0000EE3F.namprd03.prod.outlook.com (2603:10b6:8:56:cafe::d2) by DS7PR05CA0089.outlook.office365.com (2603:10b6:8:56::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.23 via Frontend Transport; Wed, 14 Jun 2023 10:23:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE3F.mail.protection.outlook.com (10.167.242.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.25 via Frontend Transport; Wed, 14 Jun 2023 10:23:18 +0000 Received: from ethanolxb491host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 14 Jun 2023 05:23:16 -0500 From: Swapnil Sapkal To: , , , CC: , , , , , , , , , , , Swapnil Sapkal Subject: [PATCH 1/2] sched/fair: Fix value reported by hot tasks pulled in /proc/schedstat Date: Wed, 14 Jun 2023 10:22:23 +0000 Message-ID: <20230614102224.12555-2-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230614102224.12555-1-swapnil.sapkal@amd.com> References: <20230614102224.12555-1-swapnil.sapkal@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3F:EE_|SA3PR12MB9106:EE_ X-MS-Office365-Filtering-Correlation-Id: d35ed990-bf44-456a-38e2-08db6cc15f0c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FtLUoLG0trDqSRv0z+Z2sxxxIedH+vLkDc0gAd5hW24h5Wig3YboCRutc4mualdqZuDqGGg65DnSQBxid2IfaId1QNqEL5TUPatX/XcwzxaFqLlFEutA8R68KnTSCRhrxeghCQlpXFLpEJdWYUsddhyxbcTdXfa3RBQIC1O4bjFsaVpQahUiVqTvh4sYgBCDLTJLKhxc3ugmNsYn61BB9IeaNPoJcd/vv2Xk7PYnRwYpoArYC4j24ekdGrMLxeiojF+oj96gPY+Qb85ILOKk5O+i0kFC/EhUs1Un4GCZv3MVzDoVWOohJfxMGA5EeEhuMaLewvsItRDEIvFZPk0MHApzQLIBFkduqs2lDB5lLM41ycFsVsxY54zrFJJkLnyxbGyUNm7Iq81efsLZcevylylDo/Uf8GJLZMjYqXU9DM7lBftQgo1fwqOQYcUSRMlloKdqv97WB7/VTdZgp4Ps/iq647m566cBipBBXjLd6vLYU9u4J6RbMvC0FYhHPLEERbk9S9zZC92zNboo8zybr9ncm0EaNJlhgT4696x3QIs6GYNP4CGNi8m3SvEy04wBcfOEeLFxIXURAKFGzzPBfzRx7GVuM8O3a46XMX50yA0YKDNQ3HQGN2kBo+ywn6xeefdc5PeFvQDg5zxnUwaZbtrwZ6HLU5sLmtJdOSnbJU5676ndm0powZIrSZcLc0nYLGxG4n12S/gRYjV/VKQs050bXZlvQhCWoac0qrxuWB9sRNwn9JBqQelOLAicvT8f X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(346002)(136003)(396003)(39860400002)(451199021)(46966006)(40470700004)(36840700001)(26005)(478600001)(16526019)(36756003)(1076003)(186003)(40480700001)(6666004)(40460700003)(7696005)(2906002)(316002)(41300700001)(44832011)(86362001)(356005)(81166007)(82310400005)(8676002)(5660300002)(82740400003)(8936002)(7416002)(110136005)(426003)(336012)(54906003)(47076005)(83380400001)(2616005)(70586007)(70206006)(4326008)(36860700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jun 2023 10:23:18.1087 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d35ed990-bf44-456a-38e2-08db6cc15f0c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB9106 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In /proc/schedstat, lb_hot_gained reports the number hot tasks pulled during load balance. This value is incremented in can_migrate_task() if the task is migratable and hot. After incrementing the value, load balancer can still decide not to migrate this task leading to wrong accounting. Fix this by incrementing stats when hot tasks are detached. This issue only exits in detach_tasks() where we can decide to not migrate hot task even if it is migratable. However, in detach_one_task(), we migrate it unconditionally. Fixes: d31980846f96 ("sched: Move up affinity check to mitigate useless red= oing overhead") Reported-by: Gautham R. Shenoy Signed-off-by: Swapnil Sapkal --- kernel/sched/fair.c | 47 +++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 373ff5f55884..9a8e5dcbe7e6 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8507,9 +8507,9 @@ static inline int migrate_degrades_locality(struct ta= sk_struct *p, * can_migrate_task - may task p from runqueue rq be migrated to this_cpu? */ static -int can_migrate_task(struct task_struct *p, struct lb_env *env) +int can_migrate_task(struct task_struct *p, struct lb_env *env, int *tsk_c= ache_hot) { - int tsk_cache_hot; + int degrades_locality; =20 lockdep_assert_rq_held(env->src_rq); =20 @@ -8578,18 +8578,19 @@ int can_migrate_task(struct task_struct *p, struct = lb_env *env) if (env->flags & LBF_ACTIVE_LB) return 1; =20 - tsk_cache_hot =3D migrate_degrades_locality(p, env); - if (tsk_cache_hot =3D=3D -1) - tsk_cache_hot =3D task_hot(p, env); + degrades_locality =3D migrate_degrades_locality(p, env); + if (degrades_locality =3D=3D -1) + *tsk_cache_hot =3D task_hot(p, env); + else + *tsk_cache_hot =3D degrades_locality; =20 - if (tsk_cache_hot <=3D 0 || - env->sd->nr_balance_failed > env->sd->cache_nice_tries) { - if (tsk_cache_hot =3D=3D 1) { - schedstat_inc(env->sd->lb_hot_gained[env->idle]); - schedstat_inc(p->stats.nr_forced_migrations); - } + /* + * Can migrate a hot task only after the attempts to reach balance + * without the task have exceeded the cache_nice_tries threshold. + */ + if (!(*tsk_cache_hot) || + env->sd->nr_balance_failed > env->sd->cache_nice_tries) return 1; - } =20 schedstat_inc(p->stats.nr_failed_migrations_hot); return 0; @@ -8598,10 +8599,15 @@ int can_migrate_task(struct task_struct *p, struct = lb_env *env) /* * detach_task() -- detach the task for the migration specified in env */ -static void detach_task(struct task_struct *p, struct lb_env *env) +static void detach_task(struct task_struct *p, struct lb_env *env, int tsk= _cache_hot) { lockdep_assert_rq_held(env->src_rq); =20 + if (tsk_cache_hot =3D=3D 1) { + schedstat_inc(env->sd->lb_hot_gained[env->idle]); + schedstat_inc(p->stats.nr_forced_migrations); + } + deactivate_task(env->src_rq, p, DEQUEUE_NOCLOCK); set_task_cpu(p, env->dst_cpu); } @@ -8620,10 +8626,12 @@ static struct task_struct *detach_one_task(struct l= b_env *env) =20 list_for_each_entry_reverse(p, &env->src_rq->cfs_tasks, se.group_node) { - if (!can_migrate_task(p, env)) + int tsk_cache_hot =3D 0; + + if (!can_migrate_task(p, env, &tsk_cache_hot)) continue; =20 - detach_task(p, env); + detach_task(p, env, tsk_cache_hot); =20 /* * Right now, this is only the second place where @@ -8665,6 +8673,8 @@ static int detach_tasks(struct lb_env *env) return 0; =20 while (!list_empty(tasks)) { + int tsk_cache_hot =3D 0; + /* * We don't want to steal all, otherwise we may be treated likewise, * which could at worst lead to a livelock crash. @@ -8690,7 +8700,7 @@ static int detach_tasks(struct lb_env *env) =20 p =3D list_last_entry(tasks, struct task_struct, se.group_node); =20 - if (!can_migrate_task(p, env)) + if (!can_migrate_task(p, env, &tsk_cache_hot)) goto next; =20 switch (env->migration_type) { @@ -8742,7 +8752,7 @@ static int detach_tasks(struct lb_env *env) break; } =20 - detach_task(p, env); + detach_task(p, env, tsk_cache_hot); list_add(&p->se.group_node, &env->tasks); =20 detached++; @@ -8766,6 +8776,9 @@ static int detach_tasks(struct lb_env *env) =20 continue; next: + if (tsk_cache_hot =3D=3D 1) + schedstat_inc(p->stats.nr_failed_migrations_hot); + list_move(&p->se.group_node, tasks); } =20 --=20 2.34.1 From nobody Sun Feb 8 13:10:56 2026 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 8A03EEB64D9 for ; Wed, 14 Jun 2023 10:26:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243885AbjFNK0O (ORCPT ); Wed, 14 Jun 2023 06:26:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234992AbjFNKZp (ORCPT ); Wed, 14 Jun 2023 06:25:45 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2082.outbound.protection.outlook.com [40.107.243.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F27EC30C7 for ; Wed, 14 Jun 2023 03:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lOkkZP9BBtbOvwqX95RpbLoMuV9bmaqPNnKyzoAYY35uwvcP0hhsDr3t6lRG8NqoqtA8yTPK/bQ6ljh4pfhW7EJFiJnI8w5ZQv8PeNq1RhQcwb6fRMfa9qLFTn+JVFMliwWXAWBXJZsLjuau9PIX21HgvIuhLv0kyVlFr74EmRRCq4h81dEt3vS4Dhr3XqA16sKWZOh5hMY2Cy4TMbo0Zw4qkXt/5u4I2Og0RNg79a/3cYR4hE+wGnmaro/2he73W5Bafk2eOTm39v0WcNRqp1ypUaIXHZ5g3udRQaQoTuA4wDVthJ4bhCrcWzJrys4trWqnPrswDgp6SooJINAOng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=X8mttvNWRRqTk0Hs51ICDxomDvHYjjGsk7ns2B6R/Wo=; b=PdTy7v2xKIEzBB6aGt5rFTpZEgfQ7pKsU9fZCxZEKHYQx2iQP7sY+3giC0GPE7x1vFZnfUQeDMUutxZQF+f7K04vPQZOE17MsFE5/RczysH12+vWEoryjPursvDce6m8Zmo6bduAPVxHutThQ4+pP8MypjHfZEHJ/87pF0McZ0FqZiuQXrQEfnobuIuSwyrAQcpROkn82x1rYTKZGMhf77FNYzJMAy7kmpfmiDpO7JFksZoyQeVccqJZ0GWykrbNxI2AukotKnm8taFEA2bUtsb7wxR0lwT8JiD1H02gZ6kVtvmElnACfUC9cTdQbiomze/VbCPX7xv/IXJzslsg+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X8mttvNWRRqTk0Hs51ICDxomDvHYjjGsk7ns2B6R/Wo=; b=1VrFIZxyHCzWzok0wfGwKDxO8PgfBpG1faMS/3BtQg3UmBv/g04/mFqXRzpE+fThUh3gasldlM8saVeVCYOUQnZCVcx4j1xkt537bhPbxe7OjzjEetPD7bk89Wk6d+qV/2TfxCdc/yRgXTwG3q9LkfDeZLqJ2rTEnEKRyaaqGF8= Received: from CYZPR12CA0003.namprd12.prod.outlook.com (2603:10b6:930:8b::16) by SJ2PR12MB8739.namprd12.prod.outlook.com (2603:10b6:a03:549::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Wed, 14 Jun 2023 10:23:41 +0000 Received: from CY4PEPF0000EE3A.namprd03.prod.outlook.com (2603:10b6:930:8b:cafe::60) by CYZPR12CA0003.outlook.office365.com (2603:10b6:930:8b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.37 via Frontend Transport; Wed, 14 Jun 2023 10:23:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000EE3A.mail.protection.outlook.com (10.167.242.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.25 via Frontend Transport; Wed, 14 Jun 2023 10:23:40 +0000 Received: from ethanolxb491host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 14 Jun 2023 05:23:39 -0500 From: Swapnil Sapkal To: , , , CC: , , , , , , , , , , , Swapnil Sapkal Subject: [PATCH 2/2] sched/fair: Cleanup in migrate_degrades_locality() to improve readability Date: Wed, 14 Jun 2023 10:22:24 +0000 Message-ID: <20230614102224.12555-3-swapnil.sapkal@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230614102224.12555-1-swapnil.sapkal@amd.com> References: <20230614102224.12555-1-swapnil.sapkal@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3A:EE_|SJ2PR12MB8739:EE_ X-MS-Office365-Filtering-Correlation-Id: 41445e9b-1dd1-4537-a9a6-08db6cc16c83 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZQfDphimZybfZn5DoNzsJKTnLIYrPWWaglVlBHg3mslpmOf7lyJAVDCZbc90fK0Z0xGqd4RiEHwDx7rJHz98vO8+57IbxOPZeLgsM1J+NGVHtSjlEiV+tRdYO/krtkNbQo6fF97ZMX4vl4TH3qniwqs2qnpMMzUvblW4vYKiP7QYf6+yX9YxeFFm59NPgNlQdJcKchGGZJSv3q/E1yljoNmEqlSO6BI+Jlux+Q5AjOKCnPkVyxRjbdIimoUFP2idbPHZBhP2vBsZcjczuho8Pxh+3Io1TO6sZFcmdufw77Kw3p6Ha/pmA5RF580VzpZhoULCtEImoO1jpdGMxO50pgugukeZ1TjMvc2UBGAmDCno+fDbQ2aQbCiaw2qAm7siGwnJ29gWmx2ygdjsfBLl7hkqPIvJ0IYKlqMnvRTXym6B2coiGaV/ieD+Spz7c/Za8ZUSC+b3vFfoWUTzbMgs5EHViVUuCtlVl3cAFwVV9jJu/j3xIzfohJFGTAvq2oB8DHulp1zjK5QANGqri5zsuWahqkexEQ5BDW0Q3h4IOwZC6e+Joi/QZvGFjIEgWYoFzZ7G1Fe87pWnuBTrRD8JZAW+c5Kbx4id5lw2+mTiE785b9T34zKDebrJCrVrw/WBGUh0egHGDdW//lK+CbjFK/at5kAV8Zu4V5b8WzF/yw4lj/3dYc8Eyhbj6ovJcEMrIupZGPmv3R2aUGls6QXS9TRRKe1pU9KmrW9OVf6yAK40cbFaC0hElM5j6yqN7EhpQCwSvAoGQWyFfFCTYemjxQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(376002)(346002)(136003)(451199021)(46966006)(36840700001)(40470700004)(336012)(40460700003)(2906002)(478600001)(426003)(2616005)(82310400005)(1076003)(26005)(36860700001)(47076005)(81166007)(86362001)(356005)(83380400001)(16526019)(82740400003)(186003)(7696005)(6666004)(70206006)(40480700001)(110136005)(7416002)(36756003)(4326008)(70586007)(5660300002)(44832011)(8676002)(8936002)(316002)(54906003)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jun 2023 10:23:40.7175 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41445e9b-1dd1-4537-a9a6-08db6cc16c83 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3A.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB8739 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The migrate_degrades_locality() returns tristate value whether the migration will improve locality, degrades locality or no impact. Handle this return values with enum to improve the readability. Signed-off-by: Swapnil Sapkal --- kernel/sched/fair.c | 69 +++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9a8e5dcbe7e6..06813ce5356e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8443,45 +8443,52 @@ static int task_hot(struct task_struct *p, struct l= b_env *env) return delta < (s64)sysctl_sched_migration_cost; } =20 +enum migration_impact { + /* if task migration is not affected by locality */ + no_change =3D -1, + + /* if task migration improves locality i.e migration preferred */ + improves_locality =3D 0, + + /* if task migration degrades locality */ + degrades_locality =3D 1 +}; + #ifdef CONFIG_NUMA_BALANCING -/* - * Returns 1, if task migration degrades locality - * Returns 0, if task migration improves locality i.e migration preferred. - * Returns -1, if task migration is not affected by locality. - */ -static int migrate_degrades_locality(struct task_struct *p, struct lb_env = *env) +static enum migration_impact +migrate_degrades_locality(struct task_struct *p, struct lb_env *env) { struct numa_group *numa_group =3D rcu_dereference(p->numa_group); unsigned long src_weight, dst_weight; int src_nid, dst_nid, dist; =20 if (!static_branch_likely(&sched_numa_balancing)) - return -1; + return no_change; =20 if (!p->numa_faults || !(env->sd->flags & SD_NUMA)) - return -1; + return no_change; =20 src_nid =3D cpu_to_node(env->src_cpu); dst_nid =3D cpu_to_node(env->dst_cpu); =20 if (src_nid =3D=3D dst_nid) - return -1; + return no_change; =20 /* Migrating away from the preferred node is always bad. */ if (src_nid =3D=3D p->numa_preferred_nid) { if (env->src_rq->nr_running > env->src_rq->nr_preferred_running) - return 1; + return degrades_locality; else - return -1; + return no_change; } =20 /* Encourage migration to the preferred node. */ if (dst_nid =3D=3D p->numa_preferred_nid) - return 0; + return improves_locality; =20 /* Leaving a core idle is often worse than degrading locality. */ if (env->idle =3D=3D CPU_IDLE) - return -1; + return no_change; =20 dist =3D node_distance(src_nid, dst_nid); if (numa_group) { @@ -8492,14 +8499,14 @@ static int migrate_degrades_locality(struct task_st= ruct *p, struct lb_env *env) dst_weight =3D task_weight(p, dst_nid, dist); } =20 - return dst_weight < src_weight; + return (dst_weight < src_weight) ? degrades_locality : improves_locality; } =20 #else -static inline int migrate_degrades_locality(struct task_struct *p, - struct lb_env *env) +static inline enum migration_impact +migrate_degrades_locality(struct task_struct *p, struct lb_env *env) { - return -1; + return no_change; } #endif =20 @@ -8509,7 +8516,7 @@ static inline int migrate_degrades_locality(struct ta= sk_struct *p, static int can_migrate_task(struct task_struct *p, struct lb_env *env, int *tsk_c= ache_hot) { - int degrades_locality; + enum migration_impact migration_impact; =20 lockdep_assert_rq_held(env->src_rq); =20 @@ -8578,18 +8585,30 @@ int can_migrate_task(struct task_struct *p, struct = lb_env *env, int *tsk_cache_h if (env->flags & LBF_ACTIVE_LB) return 1; =20 - degrades_locality =3D migrate_degrades_locality(p, env); - if (degrades_locality =3D=3D -1) + migration_impact =3D migrate_degrades_locality(p, env); + + switch (migration_impact) { + case no_change: *tsk_cache_hot =3D task_hot(p, env); - else - *tsk_cache_hot =3D degrades_locality; + break; + + case degrades_locality: + *tsk_cache_hot =3D 1; + break; + + case improves_locality: + *tsk_cache_hot =3D 0; + break; + } + + if (!(*tsk_cache_hot)) + return 1; =20 /* - * Can migrate a hot task only after the attempts to reach balance + * Can migrate a task only after the attempts to reach balance * without the task have exceeded the cache_nice_tries threshold. */ - if (!(*tsk_cache_hot) || - env->sd->nr_balance_failed > env->sd->cache_nice_tries) + if (env->sd->nr_balance_failed > env->sd->cache_nice_tries) return 1; =20 schedstat_inc(p->stats.nr_failed_migrations_hot); --=20 2.34.1