From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55CC13F4DFC for ; Wed, 20 May 2026 15:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=96.67.55.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779289260; cv=none; b=XpySJZPcBm72P0M2fc5Kk6RJLYNLT2oePnc41wuFFMlHKknFmR5kUW4kGeGTvcmUR4doIWWTL5MRp+56jZ0a3A9o5OzA2aP+VPUyemk0oZMGPJlRWSeTQeH8d131ol8aDMp2X290v8RyxBLZf9gVIJwcA/9KqC5ME1deAhsPQ2k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779289260; c=relaxed/simple; bh=Xj05axZhYV43D169CjNm9cnx8/uJVX6muICix8QKwTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZGjEmcHjV1Y5JuHBtZ+/hyTlVeakVdEA/sB2xB7E4RZXB4APD2XDmqcyINrasmEyu9AoWLkidgi7Zd1lA7uIwUzi460rwj3NE59sE15SRVp/Lk4+Dvz/SyBmn05I5sWA7VV5WsqD2ICDqprz6oXOL/TD+c22W6zo/dWHG3Ng3ck= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com; spf=pass smtp.mailfrom=surriel.com; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b=daREX2O7; arc=none smtp.client-ip=96.67.55.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=surriel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=surriel.com header.i=@surriel.com header.b="daREX2O7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=surriel.com ; s=mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=hC1C9EftDdYJ0I9PlrjUJ9mOTwszjXtUqK9pcRRvRfI=; b=daREX2O7uq6uprF4Y/3TP/EAyE og/GcXVHMlrQDaIh32Df3Fo/KfstIHCi7DICOvLEtNk5DBqHosBdHHuEHiaqAjQkS7IRpEY678lmw vZIFGM45rQFlugo4EgGpfOL8/bWpXCQWWGaiRvcSpr4V18e71SdTQTw7nPpnf79AoSDz3JaapTtQS VuG3KQqPSalACFp/KcVMdGQvXG6NW9DsJdqzb2VplxFlfHrcnxxbzRH/Caz3/I3z8ugkbJoUL1CyF Sk9OiPA22JZwUYXqbV6BIseTEIgUFoMbQt6OjfVmuIAPAcXPAXzhMpsKabW3Bo3SkWBdjg7Ua7hEz FqhAiC1w==; Received: from fangorn.home.surriel.com ([10.0.13.7]) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1wPiPM-0000000024Q-1XXJ; Wed, 20 May 2026 11:00:28 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@meta.com, linux-mm@kvack.org, david@kernel.org, willy@infradead.org, surenb@google.com, hannes@cmpxchg.org, ljs@kernel.org, ziy@nvidia.com, usama.arif@linux.dev, fvdl@google.com, Rik van Riel Subject: [RFC PATCH 13/40] mm: page_alloc: extract claim_whole_block from try_to_claim_block Date: Wed, 20 May 2026 10:59:19 -0400 Message-ID: <20260520150018.2491267-14-riel@surriel.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520150018.2491267-1-riel@surriel.com> References: <20260520150018.2491267-1-riel@surriel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract the whole-pageblock claiming logic from try_to_claim_block() into a standalone claim_whole_block() function. This handles the PB_all_free → used transition, pageblock migratetype change, and block splitting for orders >= pageblock_order. Pure refactoring, no functional change. Prepares for reuse of this logic in the per-superpageblock free lists patch. Signed-off-by: Rik van Riel Assisted-by: Claude:claude-opus-4.7 syzkaller --- mm/page_alloc.c | 89 ++++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9dc65bf93e71..1b619304864a 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2750,6 +2750,57 @@ int find_suitable_fallback(struct free_area *area, unsigned int order, return -1; } +/* + * claim_whole_block - claim a free block (>= pageblock_order) for a new type + * @zone: zone containing the page + * @page: free page to claim + * @current_order: order of the free page + * @order: requested allocation order + * @new_type: migratetype to assign + * @old_type: current migratetype of the block (for free list removal) + * + * Handle the PB_all_free → used transition, change the pageblock + * migratetype, split the block down to @order, and return the page. + */ +static struct page * +claim_whole_block(struct zone *zone, struct page *page, + int current_order, int order, int new_type, int old_type) +{ + struct superpageblock *sb; + unsigned int nr_added; + unsigned long pb_pfn; + + VM_WARN_ON_ONCE(current_order < order); + + /* + * Clear PB_all_free for pageblocks being claimed. + * This path bypasses page_del_and_expand(), so we + * must handle the free→used transition here. + */ + for (pb_pfn = page_to_pfn(page); + pb_pfn < page_to_pfn(page) + (1 << current_order); + pb_pfn += pageblock_nr_pages) { + struct page *pb_page = pfn_to_page(pb_pfn); + + if (get_pfnblock_bit(pb_page, pb_pfn, PB_all_free)) { + clear_pfnblock_bit(pb_page, pb_pfn, PB_all_free); + superpageblock_pb_now_used(pb_page); + } + __spb_set_has_type(pb_page, new_type); + } + + del_page_from_free_list(page, zone, current_order, old_type); + change_pageblock_range(page, current_order, new_type); + nr_added = expand(zone, page, order, current_order, new_type); + account_freepages(zone, nr_added, new_type); + + /* Single list update after all pageblocks processed */ + sb = pfn_to_superpageblock(zone, page_to_pfn(page)); + if (sb) + spb_update_list(sb); + return page; +} + /* * This function implements actual block claiming behaviour. If order is large * enough, we can claim the whole pageblock for the requested migratetype. If @@ -2764,9 +2815,9 @@ try_to_claim_block(struct zone *zone, struct page *page, { int free_pages, movable_pages, alike_pages; unsigned long start_pfn; - struct superpageblock *sb; #ifdef CONFIG_COMPACTION struct page *start_page; + struct superpageblock *sb; #endif /* @@ -2777,39 +2828,9 @@ try_to_claim_block(struct zone *zone, struct page *page, return NULL; /* Take ownership for orders >= pageblock_order */ - if (current_order >= pageblock_order) { - unsigned int nr_added; - unsigned long pb_pfn; - - /* - * Clear PB_all_free for pageblocks being claimed. - * This path bypasses page_del_and_expand(), so we - * must handle the free→used transition here. - * Use block_type (the original migratetype) because - * that's what was decremented when PB_all_free was set. - */ - for (pb_pfn = page_to_pfn(page); - pb_pfn < page_to_pfn(page) + (1 << current_order); - pb_pfn += pageblock_nr_pages) { - struct page *pb_page = pfn_to_page(pb_pfn); - - if (get_pfnblock_bit(pb_page, pb_pfn, PB_all_free)) { - clear_pfnblock_bit(pb_page, pb_pfn, PB_all_free); - superpageblock_pb_now_used(pb_page); - } - __spb_set_has_type(pb_page, start_type); - } - /* Single list update after all pageblocks processed */ - sb = pfn_to_superpageblock(zone, page_to_pfn(page)); - if (sb) - spb_update_list(sb); - - del_page_from_free_list(page, zone, current_order, block_type); - change_pageblock_range(page, current_order, start_type); - nr_added = expand(zone, page, order, current_order, start_type); - account_freepages(zone, nr_added, start_type); - return page; - } + if (current_order >= pageblock_order) + return claim_whole_block(zone, page, current_order, order, + start_type, block_type); /* moving whole block can fail due to zone boundary conditions */ if (!prep_move_freepages_block(zone, page, &start_pfn, &free_pages, -- 2.54.0