From nobody Thu Jun 18 17:22:54 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 C7002C433EF for ; Mon, 18 Apr 2022 15:14:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345156AbiDRPRT (ORCPT ); Mon, 18 Apr 2022 11:17:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240101AbiDRPPl (ORCPT ); Mon, 18 Apr 2022 11:15:41 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD8D0B89BB for ; Mon, 18 Apr 2022 07:12:29 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KhpjL273FzFppB; Mon, 18 Apr 2022 22:09:58 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:27 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 01/12] mm: compaction: remove unneeded return value of kcompactd_run Date: Mon, 18 Apr 2022 22:12:42 +0800 Message-ID: <20220418141253.24298-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The return value of kcompactd_run() is unused now. Clean it up. Signed-off-by: Miaohe Lin --- include/linux/compaction.h | 5 ++--- mm/compaction.c | 7 ++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/linux/compaction.h b/include/linux/compaction.h index 34bce35c808d..52a9ff65faee 100644 --- a/include/linux/compaction.h +++ b/include/linux/compaction.h @@ -177,7 +177,7 @@ static inline bool compaction_withdrawn(enum compact_re= sult result) bool compaction_zonelist_suitable(struct alloc_context *ac, int order, int alloc_flags); =20 -extern int kcompactd_run(int nid); +extern void kcompactd_run(int nid); extern void kcompactd_stop(int nid); extern void wakeup_kcompactd(pg_data_t *pgdat, int order, int highest_zone= idx); =20 @@ -212,9 +212,8 @@ static inline bool compaction_withdrawn(enum compact_re= sult result) return true; } =20 -static inline int kcompactd_run(int nid) +static inline void kcompactd_run(int nid) { - return 0; } static inline void kcompactd_stop(int nid) { diff --git a/mm/compaction.c b/mm/compaction.c index baf654b5e073..2e838992b324 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -3016,21 +3016,18 @@ static int kcompactd(void *p) * This kcompactd start function will be called by init and node-hot-add. * On node-hot-add, kcompactd will moved to proper cpus if cpus are hot-ad= ded. */ -int kcompactd_run(int nid) +void kcompactd_run(int nid) { pg_data_t *pgdat =3D NODE_DATA(nid); - int ret =3D 0; =20 if (pgdat->kcompactd) - return 0; + return; =20 pgdat->kcompactd =3D kthread_run(kcompactd, pgdat, "kcompactd%d", nid); if (IS_ERR(pgdat->kcompactd)) { pr_err("Failed to start kcompactd on node %d\n", nid); - ret =3D PTR_ERR(pgdat->kcompactd); pgdat->kcompactd =3D NULL; } - return ret; } =20 /* --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 4FE35C433F5 for ; Mon, 18 Apr 2022 15:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240742AbiDRPP7 (ORCPT ); Mon, 18 Apr 2022 11:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242180AbiDRPPm (ORCPT ); Mon, 18 Apr 2022 11:15:42 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB035B9181 for ; Mon, 18 Apr 2022 07:12:29 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Khpm761BBzhXX5; Mon, 18 Apr 2022 22:12:23 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:27 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 02/12] mm: compaction: remove unneeded pfn update Date: Mon, 18 Apr 2022 22:12:43 +0800 Message-ID: <20220418141253.24298-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" pfn is unused in this do while loop. Remove the unneeded pfn update. Signed-off-by: Miaohe Lin --- mm/compaction.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 2e838992b324..f9e628a5306a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -317,7 +317,6 @@ __reset_isolation_pfn(struct zone *zone, unsigned long = pfn, bool check_source, } =20 page +=3D (1 << PAGE_ALLOC_COSTLY_ORDER); - pfn +=3D (1 << PAGE_ALLOC_COSTLY_ORDER); } while (page <=3D end_page); =20 return false; --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 4009EC433EF for ; Mon, 18 Apr 2022 15:14:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243227AbiDRPRI (ORCPT ); Mon, 18 Apr 2022 11:17:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243332AbiDRPPm (ORCPT ); Mon, 18 Apr 2022 11:15:42 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A256B918D for ; Mon, 18 Apr 2022 07:12:31 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KhplQ1Dpwz1GCSG; Mon, 18 Apr 2022 22:11:46 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:28 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 03/12] mm: compaction: remove unneeded assignment to isolate_start_pfn Date: Mon, 18 Apr 2022 22:12:44 +0800 Message-ID: <20220418141253.24298-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" isolate_start_pfn is unused when cc->nr_freepages ! =3D 0. Otherwise cc->free_pfn will overwrite it unconditionally. So we should remove this unneeded and somewhat misleading assignment. Signed-off-by: Miaohe Lin --- mm/compaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index f9e628a5306a..ee2ddf77191f 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1586,7 +1586,7 @@ static void isolate_freepages(struct compact_control = *cc) unsigned int stride; =20 /* Try a small search of the free lists for a candidate */ - isolate_start_pfn =3D fast_isolate_freepages(cc); + fast_isolate_freepages(cc); if (cc->nr_freepages) goto splitmap; =20 --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 EFBC0C433F5 for ; Mon, 18 Apr 2022 15:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239800AbiDRPRL (ORCPT ); Mon, 18 Apr 2022 11:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242390AbiDRPPm (ORCPT ); Mon, 18 Apr 2022 11:15:42 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C212BB9186 for ; Mon, 18 Apr 2022 07:12:30 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KhpjM4t6MzFplq; Mon, 18 Apr 2022 22:09:59 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:28 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 04/12] mm: compaction: clean up comment for sched contention Date: Mon, 18 Apr 2022 22:12:45 +0800 Message-ID: <20220418141253.24298-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit cf66f0700c8f ("mm, compaction: do not consider a need to reschedule as contention"), async compaction won't abort when scheduling is needed. Correct the relevant comment accordingly. Signed-off-by: Miaohe Lin --- mm/compaction.c | 11 ++++------- mm/internal.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index ee2ddf77191f..e839b26fb3d8 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -513,15 +513,12 @@ static bool compact_lock_irqsave(spinlock_t *lock, un= signed long *flags, * very heavily contended. The lock should be periodically unlocked to avo= id * having disabled IRQs for a long time, even when there is nobody waiting= on * the lock. It might also be that allowing the IRQs will result in - * need_resched() becoming true. If scheduling is needed, async compaction - * aborts. Sync compaction schedules. + * need_resched() becoming true. If scheduling is needed, compaction sched= ules. * Either compaction type will also abort if a fatal signal is pending. * In either case if the lock was locked, it is dropped and not regained. * - * Returns true if compaction should abort due to fatal signal pending, or - * async compaction due to need_resched() - * Returns false when compaction can continue (sync compaction might have - * scheduled) + * Returns true if compaction should abort due to fatal signal pending. + * Returns false when compaction can continue. */ static bool compact_unlock_should_abort(spinlock_t *lock, unsigned long flags, bool *locked, struct compact_control *cc) @@ -574,7 +571,7 @@ static unsigned long isolate_freepages_block(struct com= pact_control *cc, /* * Periodically drop the lock (if held) regardless of its * contention, to give chance to IRQs. Abort if fatal signal - * pending or async compaction detects need_resched() + * pending. */ if (!(blockpfn % SWAP_CLUSTER_MAX) && compact_unlock_should_abort(&cc->zone->lock, flags, diff --git a/mm/internal.h b/mm/internal.h index 48eb2d24fcd2..70cc61af06de 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -403,7 +403,7 @@ struct compact_control { bool direct_compaction; /* False from kcompactd or /proc/... */ bool proactive_compaction; /* kcompactd proactive compaction */ bool whole_zone; /* Whole zone should/has been scanned */ - bool contended; /* Signal lock or sched contention */ + bool contended; /* Signal lock contention */ bool rescan; /* Rescanning the same pageblock */ bool alloc_contig; /* alloc_contig_range allocation */ }; --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 F1052C433F5 for ; Mon, 18 Apr 2022 15:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343506AbiDRPRA (ORCPT ); Mon, 18 Apr 2022 11:17:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243746AbiDRPPn (ORCPT ); Mon, 18 Apr 2022 11:15:43 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C9A0B918F for ; Mon, 18 Apr 2022 07:12:31 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KhplQ4z6qzfYx6; Mon, 18 Apr 2022 22:11:46 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:29 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 05/12] mm: compaction: clean up comment about suitable migration target recheck Date: Mon, 18 Apr 2022 22:12:46 +0800 Message-ID: <20220418141253.24298-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" checked_pageblock is already removed and suitable_migration_target is not rechecked under the zone lock since commit f8224aa5a0a4 ("mm, compaction: do not recheck suitable_migration_target under lock"). Correct the comment accordingly. Signed-off-by: Miaohe Lin --- mm/compaction.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index e839b26fb3d8..97821b7d7a4f 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -599,13 +599,7 @@ static unsigned long isolate_freepages_block(struct co= mpact_control *cc, if (!PageBuddy(page)) goto isolate_fail; =20 - /* - * If we already hold the lock, we can skip some rechecking. - * Note that if we hold the lock now, checked_pageblock was - * already set in some previous iteration (or strict is true), - * so it is correct to skip the suitable migration target - * recheck as well. - */ + /* If we already hold the lock, we can skip some rechecking. */ if (!locked) { locked =3D compact_lock_irqsave(&cc->zone->lock, &flags, cc); --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 70332C433EF for ; Mon, 18 Apr 2022 15:13:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241829AbiDRPQc (ORCPT ); Mon, 18 Apr 2022 11:16:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244002AbiDRPPo (ORCPT ); Mon, 18 Apr 2022 11:15:44 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD9A5B9190 for ; Mon, 18 Apr 2022 07:12:31 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Khpm846fxzhXWx; Mon, 18 Apr 2022 22:12:24 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:29 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 06/12] mm: compaction: use COMPACT_CLUSTER_MAX in compaction.c Date: Mon, 18 Apr 2022 22:12:47 +0800 Message-ID: <20220418141253.24298-7-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Always use COMPACT_CLUSTER_MAX here as we're doing the compaction. Minor improvements in readability. Signed-off-by: Miaohe Lin --- mm/compaction.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 97821b7d7a4f..1fc912ec3a98 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -573,7 +573,7 @@ static unsigned long isolate_freepages_block(struct com= pact_control *cc, * contention, to give chance to IRQs. Abort if fatal signal * pending. */ - if (!(blockpfn % SWAP_CLUSTER_MAX) + if (!(blockpfn % COMPACT_CLUSTER_MAX) && compact_unlock_should_abort(&cc->zone->lock, flags, &locked, cc)) break; @@ -862,7 +862,7 @@ isolate_migratepages_block(struct compact_control *cc, = unsigned long low_pfn, * contention, to give chance to IRQs. Abort completely if * a fatal signal is pending. */ - if (!(low_pfn % SWAP_CLUSTER_MAX)) { + if (!(low_pfn % COMPACT_CLUSTER_MAX)) { if (locked) { unlock_page_lruvec_irqrestore(locked, flags); locked =3D NULL; @@ -1614,7 +1614,7 @@ static void isolate_freepages(struct compact_control = *cc) * This can iterate a massively long zone without finding any * suitable migration targets, so periodically check resched. */ - if (!(block_start_pfn % (SWAP_CLUSTER_MAX * pageblock_nr_pages))) + if (!(block_start_pfn % (COMPACT_CLUSTER_MAX * pageblock_nr_pages))) cond_resched(); =20 page =3D pageblock_pfn_to_page(block_start_pfn, block_end_pfn, @@ -1921,7 +1921,7 @@ static isolate_migrate_t isolate_migratepages(struct = compact_control *cc) * many pageblocks unsuitable, so periodically check if we * need to schedule. */ - if (!(low_pfn % (SWAP_CLUSTER_MAX * pageblock_nr_pages))) + if (!(low_pfn % (COMPACT_CLUSTER_MAX * pageblock_nr_pages))) cond_resched(); =20 page =3D pageblock_pfn_to_page(block_start_pfn, --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 B0973C433EF for ; Mon, 18 Apr 2022 15:14:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344717AbiDRPQm (ORCPT ); Mon, 18 Apr 2022 11:16:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243525AbiDRPPn (ORCPT ); Mon, 18 Apr 2022 11:15:43 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE5ECB919B for ; Mon, 18 Apr 2022 07:12:32 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Khpm90MWrzQv0W; Mon, 18 Apr 2022 22:12:25 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:30 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 07/12] mm: compaction: use helper compound_nr in isolate_migratepages_block Date: Mon, 18 Apr 2022 22:12:48 +0800 Message-ID: <20220418141253.24298-8-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use helper compound_nr to make use of compound_nr when CONFIG_64BIT and simplify the code a bit. Signed-off-by: Miaohe Lin --- mm/compaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 1fc912ec3a98..55013a2af817 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -908,7 +908,7 @@ isolate_migratepages_block(struct compact_control *cc, = unsigned long low_pfn, /* Do not report -EBUSY down the chain */ if (ret =3D=3D -EBUSY) ret =3D 0; - low_pfn +=3D (1UL << compound_order(page)) - 1; + low_pfn +=3D compound_nr(page) - 1; goto isolate_fail; } =20 --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 36F1DC433F5 for ; Mon, 18 Apr 2022 15:14:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241396AbiDRPRE (ORCPT ); Mon, 18 Apr 2022 11:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243492AbiDRPPn (ORCPT ); Mon, 18 Apr 2022 11:15:43 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEAC3B919C for ; Mon, 18 Apr 2022 07:12:32 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KhplS13JczfYy1; Mon, 18 Apr 2022 22:11:48 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:30 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 08/12] mm: compaction: clean up comment about async compaction in isolate_migratepages Date: Mon, 18 Apr 2022 22:12:49 +0800 Message-ID: <20220418141253.24298-9-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit 282722b0d258 ("mm, compaction: restrict async compaction to pageblocks of same migratetype"), async direct compaction is restricted to scan the pageblocks of same migratetype. Correct the comment accordingly. Signed-off-by: Miaohe Lin --- mm/compaction.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 55013a2af817..562f274b2c51 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1941,12 +1941,12 @@ static isolate_migrate_t isolate_migratepages(struc= t compact_control *cc) continue; =20 /* - * For async compaction, also only scan in MOVABLE blocks - * without huge pages. Async compaction is optimistic to see - * if the minimum amount of work satisfies the allocation. - * The cached PFN is updated as it's possible that all - * remaining blocks between source and target are unsuitable - * and the compaction scanners fail to meet. + * For async direct compaction, only scan the pageblocks of the + * same migratetype without huge pages. Async direct compaction + * is optimistic to see if the minimum amount of work satisfies + * the allocation. The cached PFN is updated as it's possible + * that all remaining blocks between source and target are + * unsuitable and the compaction scanners fail to meet. */ if (!suitable_migration_source(cc, page)) { update_cached_migrate(cc, block_end_pfn); --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 4293FC433F5 for ; Mon, 18 Apr 2022 15:13:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344096AbiDRPQ1 (ORCPT ); Mon, 18 Apr 2022 11:16:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244009AbiDRPPo (ORCPT ); Mon, 18 Apr 2022 11:15:44 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D30C381A9 for ; Mon, 18 Apr 2022 07:12:33 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KhplS4TlnzfYy5; Mon, 18 Apr 2022 22:11:48 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:30 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 09/12] mm: compaction: avoid possible NULL pointer dereference in kcompactd_cpu_online Date: Mon, 18 Apr 2022 22:12:50 +0800 Message-ID: <20220418141253.24298-10-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's possible that kcompactd_run could fail to run kcompactd for a hot added node and leave pgdat->kcompactd as NULL. So pgdat->kcompactd should be checked here to avoid possible NULL pointer dereference. Signed-off-by: Miaohe Lin --- mm/compaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 562f274b2c51..82c54d70a978 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -3052,7 +3052,8 @@ static int kcompactd_cpu_online(unsigned int cpu) =20 if (cpumask_any_and(cpu_online_mask, mask) < nr_cpu_ids) /* One of our CPUs online: restore mask */ - set_cpus_allowed_ptr(pgdat->kcompactd, mask); + if (pgdat->kcompactd) + set_cpus_allowed_ptr(pgdat->kcompactd, mask); } return 0; } --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 C1A9EC433FE for ; Mon, 18 Apr 2022 15:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245708AbiDRPQh (ORCPT ); Mon, 18 Apr 2022 11:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244169AbiDRPPo (ORCPT ); Mon, 18 Apr 2022 11:15:44 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02C4B38BDD for ; Mon, 18 Apr 2022 07:12:33 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KhpgD34p3zCr5B; Mon, 18 Apr 2022 22:08:08 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:31 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 10/12] mm: compaction: make compaction_zonelist_suitable return false when COMPACT_SUCCESS Date: Mon, 18 Apr 2022 22:12:51 +0800 Message-ID: <20220418141253.24298-11-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When compact_result indicates that the allocation should now succeed, i.e. compact_result =3D COMPACT_SUCCESS, compaction_zonelist_suitable should return false because there is no need to do compaction now. Signed-off-by: Miaohe Lin --- mm/compaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 82c54d70a978..334a573485fe 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2291,7 +2291,7 @@ bool compaction_zonelist_suitable(struct alloc_contex= t *ac, int order, available +=3D zone_page_state_snapshot(zone, NR_FREE_PAGES); compact_result =3D __compaction_suitable(zone, order, alloc_flags, ac->highest_zoneidx, available); - if (compact_result !=3D COMPACT_SKIPPED) + if (compact_result =3D=3D COMPACT_CONTINUE) return true; } =20 --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 C0508C433F5 for ; Mon, 18 Apr 2022 15:13:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244710AbiDRPQS (ORCPT ); Mon, 18 Apr 2022 11:16:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244144AbiDRPPo (ORCPT ); Mon, 18 Apr 2022 11:15:44 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 153D738BE1 for ; Mon, 18 Apr 2022 07:12:34 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KhpmB73sszhXWg; Mon, 18 Apr 2022 22:12:26 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:31 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 11/12] mm: compaction: simplify the code in __compact_finished Date: Mon, 18 Apr 2022 22:12:52 +0800 Message-ID: <20220418141253.24298-12-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit efe771c7603b ("mm, compaction: always finish scanning of a full pageblock"), compaction will always finish scanning a pageblock. And migrate_pfn is assured to align with pageblock_nr_pages when we reach here. So we will always return COMPACT_SUCCESS if a suitable fallback is found due to the below IS_ALIGNED check of migrate_pfn. Simplify the code to make this clear and improve the readability. No functional change intended. Signed-off-by: Miaohe Lin --- mm/compaction.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 334a573485fe..609a76d7e051 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2134,29 +2134,16 @@ static enum compact_result __compact_finished(struc= t compact_control *cc) * other migratetype buddy lists. */ if (find_suitable_fallback(area, order, migratetype, - true, &can_steal) !=3D -1) { - - /* movable pages are OK in any pageblock */ - if (migratetype =3D=3D MIGRATE_MOVABLE) - return COMPACT_SUCCESS; - + true, &can_steal) !=3D -1) /* - * We are stealing for a non-movable allocation. Make - * sure we finish compacting the current pageblock - * first so it is as free as possible and we won't - * have to steal another one soon. This only applies - * to sync compaction, as async compaction operates - * on pageblocks of the same migratetype. + * Movable pages are OK in any pageblock. If we are + * stealing for a non-movable allocation, make sure + * we finish compacting the current pageblock first + * (which is assured by the above migrate_pfn align + * check) so it is as free as possible and we won't + * have to steal another one soon. */ - if (cc->mode =3D=3D MIGRATE_ASYNC || - IS_ALIGNED(cc->migrate_pfn, - pageblock_nr_pages)) { - return COMPACT_SUCCESS; - } - - ret =3D COMPACT_CONTINUE; - break; - } + return COMPACT_SUCCESS; } =20 out: --=20 2.23.0 From nobody Thu Jun 18 17:22:54 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 21688C433F5 for ; Mon, 18 Apr 2022 15:13:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbiDRPQM (ORCPT ); Mon, 18 Apr 2022 11:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244207AbiDRPPo (ORCPT ); Mon, 18 Apr 2022 11:15:44 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A17D3B91A1 for ; Mon, 18 Apr 2022 07:12:34 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KhpmC3PH9zhXXX; Mon, 18 Apr 2022 22:12:27 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 18 Apr 2022 22:12:32 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 12/12] mm: compaction: make sure highest is above the min_pfn Date: Mon, 18 Apr 2022 22:12:53 +0800 Message-ID: <20220418141253.24298-13-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220418141253.24298-1-linmiaohe@huawei.com> References: <20220418141253.24298-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It's not guaranteed that highest will be above the min_pfn. If highest is below the min_pfn, migrate_pfn and free_pfn can meet prematurely and lead to some useless work. Make sure highest is above min_pfn to avoid making a futile effort. Signed-off-by: Miaohe Lin --- mm/compaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/compaction.c b/mm/compaction.c index 609a76d7e051..65970107b789 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1532,7 +1532,7 @@ fast_isolate_freepages(struct compact_control *cc) * not found, be pessimistic for direct compaction * and use the min mark. */ - if (highest) { + if (highest >=3D min_pfn) { page =3D pfn_to_page(highest); cc->free_pfn =3D highest; } else { --=20 2.23.0