From nobody Mon Sep 15 19:18:43 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 A691EC54EBC for ; Tue, 10 Jan 2023 13:37:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238614AbjAJNgu (ORCPT ); Tue, 10 Jan 2023 08:36:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232833AbjAJNgf (ORCPT ); Tue, 10 Jan 2023 08:36:35 -0500 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CFD8BA3 for ; Tue, 10 Jan 2023 05:36:32 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VZJNeww_1673357787; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VZJNeww_1673357787) by smtp.aliyun-inc.com; Tue, 10 Jan 2023 21:36:27 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] mm: compaction: Remove redundant VM_BUG_ON() in compact_zone() Date: Tue, 10 Jan 2023 21:36:18 +0800 Message-Id: <740a2396d9b98154dba76e326cba5e798b640ead.1673342761.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: 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" The compaction_suitable() will never return values other than COMPACT_SUCCE= SS, COMPACT_SKIPPED and COMPACT_CONTINUE, so after validation of COMPACT_SUCCESS and COMPACT_SKIPPED, we will never hit other unexpected case. Thus remove the redundant VM_BUG_ON() validation for the return values of compaction_su= itable(). Signed-off-by: Baolin Wang --- mm/compaction.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 62a61de44658..5e6f5e35748d 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2313,9 +2313,6 @@ compact_zone(struct compact_control *cc, struct captu= re_control *capc) if (ret =3D=3D COMPACT_SUCCESS || ret =3D=3D COMPACT_SKIPPED) return ret; =20 - /* huh, compaction_suitable is returning something unexpected */ - VM_BUG_ON(ret !=3D COMPACT_CONTINUE); - /* * Clear pageblock skip if there were failures recently and compaction * is about to be retried after being deferred. --=20 2.27.0 From nobody Mon Sep 15 19:18:43 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 6DC37C678D5 for ; Tue, 10 Jan 2023 13:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238727AbjAJNg6 (ORCPT ); Tue, 10 Jan 2023 08:36:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233543AbjAJNgg (ORCPT ); Tue, 10 Jan 2023 08:36:36 -0500 Received: from out30-8.freemail.mail.aliyun.com (out30-8.freemail.mail.aliyun.com [115.124.30.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD1EDBC8 for ; Tue, 10 Jan 2023 05:36:33 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R501e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VZJUhj7_1673357788; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VZJUhj7_1673357788) by smtp.aliyun-inc.com; Tue, 10 Jan 2023 21:36:28 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] mm: compaction: Move list validation into compact_zone() Date: Tue, 10 Jan 2023 21:36:19 +0800 Message-Id: <15cf54f7d762e87b04ac3cc74536f7d1ebbcd8cd.1673342761.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: 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" Move the cc.freepages and cc.migratepages list validation into compact_zone= () to remove some duplicate code. Signed-off-by: Baolin Wang --- mm/compaction.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 5e6f5e35748d..f8e8addc8664 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2488,6 +2488,9 @@ compact_zone(struct compact_control *cc, struct captu= re_control *capc) =20 trace_mm_compaction_end(cc, start_pfn, end_pfn, sync, ret); =20 + VM_BUG_ON(!list_empty(&cc->freepages)); + VM_BUG_ON(!list_empty(&cc->migratepages)); + return ret; } =20 @@ -2526,9 +2529,6 @@ static enum compact_result compact_zone_order(struct = zone *zone, int order, =20 ret =3D compact_zone(&cc, &capc); =20 - VM_BUG_ON(!list_empty(&cc.freepages)); - VM_BUG_ON(!list_empty(&cc.migratepages)); - /* * Make sure we hide capture control first before we read the captured * page pointer, otherwise an interrupt could free and capture a page @@ -2659,9 +2659,6 @@ static void proactive_compact_node(pg_data_t *pgdat) cc.zone =3D zone; =20 compact_zone(&cc, NULL); - - VM_BUG_ON(!list_empty(&cc.freepages)); - VM_BUG_ON(!list_empty(&cc.migratepages)); } } =20 @@ -2689,9 +2686,6 @@ static void compact_node(int nid) cc.zone =3D zone; =20 compact_zone(&cc, NULL); - - VM_BUG_ON(!list_empty(&cc.freepages)); - VM_BUG_ON(!list_empty(&cc.migratepages)); } } =20 @@ -2868,9 +2862,6 @@ static void kcompactd_do_work(pg_data_t *pgdat) cc.total_migrate_scanned); count_compact_events(KCOMPACTD_FREE_SCANNED, cc.total_free_scanned); - - VM_BUG_ON(!list_empty(&cc.freepages)); - VM_BUG_ON(!list_empty(&cc.migratepages)); } =20 /* --=20 2.27.0 From nobody Mon Sep 15 19:18:43 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 4CB5AC63797 for ; Tue, 10 Jan 2023 13:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238710AbjAJNg4 (ORCPT ); Tue, 10 Jan 2023 08:36:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231409AbjAJNgh (ORCPT ); Tue, 10 Jan 2023 08:36:37 -0500 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD776C41 for ; Tue, 10 Jan 2023 05:36:33 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R291e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VZJNexH_1673357788; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VZJNexH_1673357788) by smtp.aliyun-inc.com; Tue, 10 Jan 2023 21:36:29 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] mm: compaction: Count the migration scanned pages events for proactive compaction Date: Tue, 10 Jan 2023 21:36:20 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: 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" The proactive compaction will reuse per-node kcompactd threads, so we should also count the KCOMPACTD_MIGRATE_SCANNED and KCOMPACTD_FREE_SCANNED events for proactive compaction. Signed-off-by: Baolin Wang --- mm/compaction.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index f8e8addc8664..62f6bb68c9cb 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2659,6 +2659,11 @@ static void proactive_compact_node(pg_data_t *pgdat) cc.zone =3D zone; =20 compact_zone(&cc, NULL); + + count_compact_events(KCOMPACTD_MIGRATE_SCANNED, + cc.total_migrate_scanned); + count_compact_events(KCOMPACTD_FREE_SCANNED, + cc.total_free_scanned); } } =20 --=20 2.27.0 From nobody Mon Sep 15 19:18:43 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 0C57CC54EBE for ; Tue, 10 Jan 2023 13:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238667AbjAJNgw (ORCPT ); Tue, 10 Jan 2023 08:36:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232931AbjAJNgf (ORCPT ); Tue, 10 Jan 2023 08:36:35 -0500 Received: from out30-7.freemail.mail.aliyun.com (out30-7.freemail.mail.aliyun.com [115.124.30.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD545BDB for ; Tue, 10 Jan 2023 05:36:33 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VZJNexU_1673357789; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VZJNexU_1673357789) by smtp.aliyun-inc.com; Tue, 10 Jan 2023 21:36:30 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] mm: compaction: Add missing kcompactd wakeup trace event Date: Tue, 10 Jan 2023 21:36:21 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: 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" Add missing kcompactd wakeup trace event for proactive compaction, meanwhile use order =3D -1 and the highest zone index of the pgdat for the kcompactd = wakeup trace event by proactive compaction. Signed-off-by: Baolin Wang --- mm/compaction.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 62f6bb68c9cb..0fd6c81a7809 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2730,6 +2730,8 @@ int compaction_proactiveness_sysctl_handler(struct ct= l_table *table, int write, continue; =20 pgdat->proactive_compact_trigger =3D true; + trace_mm_compaction_wakeup_kcompactd(pgdat->node_id, -1, + pgdat->nr_zones - 1); wake_up_interruptible(&pgdat->kcompactd_wait); } } --=20 2.27.0 From nobody Mon Sep 15 19:18:43 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 4F750C46467 for ; Tue, 10 Jan 2023 13:37:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238503AbjAJNgq (ORCPT ); Tue, 10 Jan 2023 08:36:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232932AbjAJNgf (ORCPT ); Tue, 10 Jan 2023 08:36:35 -0500 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B2ECBA4 for ; Tue, 10 Jan 2023 05:36:33 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VZJUhjw_1673357790; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VZJUhjw_1673357790) by smtp.aliyun-inc.com; Tue, 10 Jan 2023 21:36:30 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] mm: compaction: Avoid fragmentation score calculation for empty zones Date: Tue, 10 Jan 2023 21:36:22 +0800 Message-Id: <100331ad9d274a9725e687b00d85d75d7e4a17c7.1673342761.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: 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" There is no need to calculate the fragmentation score for empty zones. Signed-off-by: Baolin Wang --- mm/compaction.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 0fd6c81a7809..b758b00a4885 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -2025,6 +2025,8 @@ static unsigned int fragmentation_score_node(pg_data_= t *pgdat) struct zone *zone; =20 zone =3D &pgdat->node_zones[zoneid]; + if (!populated_zone(zone)) + continue; score +=3D fragmentation_score_zone_weighted(zone); } =20 --=20 2.27.0