From nobody Thu Sep 11 20:39:12 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 9300CC00528 for ; Sat, 5 Aug 2023 03:07:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229462AbjHEDHP (ORCPT ); Fri, 4 Aug 2023 23:07:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjHEDHH (ORCPT ); Fri, 4 Aug 2023 23:07:07 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73DAC4EE4 for ; Fri, 4 Aug 2023 20:07:02 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4RHnYX4D99z4f3lKg for ; Sat, 5 Aug 2023 11:06:56 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgAHvrHQvM1k6A5ePg--.23962S5; Sat, 05 Aug 2023 11:06:59 +0800 (CST) From: Kemeng Shi To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, baolin.wang@linux.alibaba.com, mgorman@techsingularity.net, david@redhat.com Cc: shikemeng@huaweicloud.com Subject: [PATCH 3/9] mm/compaction: correctly return failure with bogus compound_order in strict mode Date: Sat, 5 Aug 2023 19:07:05 +0800 Message-Id: <20230805110711.2975149-4-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230805110711.2975149-1-shikemeng@huaweicloud.com> References: <20230805110711.2975149-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted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E14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0pRPEf5UUUUU = X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In strict mode, we should return 0 if there is any hole in pageblock. If we successfully isolated pages at beginning at pageblock and then have a bogus compound_order outside pageblock in next page. We will abort search loop with blockpfn > end_pfn. Although we will limit blockpfn to end_pfn, we will treat it as a successful isolation in strict mode as blockpfn is not < end_pfn and return partial isolated pages. Then isolate_freepages_range may success unexpectly with hole in isolated range. This patch also removes unnecessary limit for blockpfn to go outside by buddy page introduced in fixed commit or by stride introduced after fixed commit. Caller could use returned blockpfn to check if full pageblock is scanned by test if blockpfn >=3D end and to get next pfn to scan inside isolate_freepages_block on demand. Fixes: 9fcd6d2e052ee ("mm, compaction: skip compound pages by order in free= scanner") Signed-off-by: Kemeng Shi --- mm/compaction.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index fa1b100b0d10..684f6e6cd8bc 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -631,6 +631,14 @@ static unsigned long isolate_freepages_block(struct co= mpact_control *cc, page +=3D (1UL << order) - 1; nr_scanned +=3D (1UL << order) - 1; } + /* + * There is a tiny chance that we have read bogus + * compound_order(), so be careful to not go outside + * of the pageblock. + */ + if (unlikely(blockpfn >=3D end_pfn)) + blockpfn =3D end_pfn - 1; + goto isolate_fail; } =20 @@ -677,17 +685,10 @@ static unsigned long isolate_freepages_block(struct c= ompact_control *cc, if (locked) spin_unlock_irqrestore(&cc->zone->lock, flags); =20 - /* - * There is a tiny chance that we have read bogus compound_order(), - * so be careful to not go outside of the pageblock. - */ - if (unlikely(blockpfn > end_pfn)) - blockpfn =3D end_pfn; - trace_mm_compaction_isolate_freepages(*start_pfn, blockpfn, nr_scanned, total_isolated); =20 - /* Record how far we have got within the block */ + /* Record how far we have got */ *start_pfn =3D blockpfn; =20 /* @@ -1443,7 +1444,7 @@ fast_isolate_around(struct compact_control *cc, unsig= ned long pfn) isolate_freepages_block(cc, &start_pfn, end_pfn, &cc->freepages, 1, false= ); =20 /* Skip this pageblock in the future as it's full or nearly full */ - if (start_pfn =3D=3D end_pfn && !cc->no_set_skip_hint) + if (start_pfn >=3D end_pfn && !cc->no_set_skip_hint) set_pageblock_skip(page); } =20 @@ -1712,7 +1713,7 @@ static void isolate_freepages(struct compact_control = *cc) block_end_pfn, freelist, stride, false); =20 /* Update the skip hint if the full pageblock was scanned */ - if (isolate_start_pfn =3D=3D block_end_pfn) + if (isolate_start_pfn >=3D block_end_pfn) update_pageblock_skip(cc, page, block_start_pfn - pageblock_nr_pages); =20 --=20 2.30.0