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 136033F44F0 for ; Wed, 20 May 2026 15:00:51 +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=1779289256; cv=none; b=PcB0tDZpZ5y4ffriHODtDjQ2BapdAwQmP0zMSdsQ3Ylmhacp2Snqgx6C5V5uReuqY8SzpraL5s2n8qdEAe1MvmGa74J1q+GQtOOIkimX9dhYf/WrJy2D/zkoxMh12xr01DdkguViE0f+Iwda7vbCfeVqP8iIjDjT2JqSkl+O24g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779289256; c=relaxed/simple; bh=1MfIrcRrUVJPvpWutLd4EUqFR1xFf2rn4QP9FHwunrk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UTqnnZa1Y/fasqdQ5CZT3A/lzUyPAwSv2omQTCaPhnklySp1Iqm8fN91TpSVJe7jBO5QRv9OiDA1y+wjoroByBBoWJTafMebzCCvxDOOJHTzaMj010LJ5WWVQaejORavLled5XF5zz9WLJZtd4/Ru3ujto9p+PjHndNw42oCRyo= 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=iFzmLLq7; 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="iFzmLLq7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=surriel.com ; s=mail; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=QW4fFEcF7RsWKk8iCSpAqzPzouHeAUq+juaYAvjgTXo=; b=iFzmLLq7qnngkcCaltwJB4Tthr T8mODk7BlOY+POMVK0yzvJA+nnYXDdCvUyNuuhzrg6sAp8wP8JwwotdRbYcF6XSiuB9/hkfE2QWGP jBAw0chcYeP2GehQJSA18owqSf2zRdecb8xpTnEb/P1bzPjvL+12C2Z+BU5WALcZKz0/ttjEgy5b1 ZLmc/luYOkJaOyBqMs0bf3mizTPsw2InvuC4FEguf28LlxRq0hRdaUEZhgdra2grumCAvidfKhbpY IS0pYR432j1AjwDeNT2P5AQkpsA1fCjc1OO4sJHDw0tuAcjaGXh0RQHptDtL0uG6FNhMSjl6Q0NKl Ac820/ZA==; 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 1wPiPN-0000000024Q-0ShO; Wed, 20 May 2026 11:00:29 -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 37/40] mm: page_alloc: move spb_get_category and spb_tainted_reserve to mmzone.h Date: Wed, 20 May 2026 10:59:43 -0400 Message-ID: <20260520150018.2491267-38-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-Transfer-Encoding: 8bit Pure move with no semantic change. Both helpers will be needed in mm/compaction.c by upcoming SPB-skip predicates; keep a single source of truth for them in alongside pfn_to_superpageblock(). Signed-off-by: Rik van Riel Assisted-by: Claude:claude-opus-4.7 syzkaller --- include/linux/mmzone.h | 30 ++++++++++++++++++++++++++++++ mm/page_alloc.c | 27 +++++---------------------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index c9c248d5b14e..d51dbca59656 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -1296,6 +1296,36 @@ static inline struct superpageblock *pfn_to_superpageblock(struct zone *zone, return &zone->superpageblocks[idx]; } +/** + * spb_get_category - Determine if a superpageblock is clean or tainted + * @sb: superpageblock to classify + * + * A superpageblock is clean if it contains only free and movable pageblocks. + * Any unmovable, reclaimable, or reserved pageblocks make it tainted. + */ +static inline enum sb_category spb_get_category(struct superpageblock *sb) +{ + if (sb->nr_unmovable || sb->nr_reclaimable || sb->nr_reserved) + return SB_TAINTED; + return SB_CLEAN; +} + +/* + * Minimum free-pageblock reserve a tainted SPB tries to maintain so the + * allocator can satisfy non-movable allocations without tainting fresh + * clean SPBs. Used by spb_tainted_reserve() as a floor for the per-SPB + * reserve; the page allocator and compaction both consult + * spb_tainted_reserve() to decide when a tainted SPB has so few free + * pageblocks left that movable allocations should look elsewhere. + * Scale with SPB size: reserve ~3% of pageblocks (minimum 4). + */ +#define SPB_TAINTED_RESERVE_MIN 4 + +static inline u16 spb_tainted_reserve(const struct superpageblock *sb) +{ + return max_t(u16, SPB_TAINTED_RESERVE_MIN, sb->total_pageblocks / 32); +} + enum pgdat_flags { PGDAT_WRITEBACK, /* reclaim scanning has recently found * many pages under writeback diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 4e45fac14622..62edbdf0c3f3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -673,22 +673,8 @@ void superpageblock_set_has_movable(struct zone *zone, struct page *page) } #endif /* CONFIG_COMPACTION */ -/** - * spb_get_category - Determine if a superpageblock is clean or tainted - * @sb: superpageblock to classify - * - * A superpageblock is clean if it contains only free and movable pageblocks. - * Any unmovable, reclaimable, or reserved pageblocks make it tainted. - * Reserved pageblocks (memory holes) taint the superpageblock because it - * can never be used for 1GB hugepages, making it a better home for - * unmovable/reclaimable allocations. - */ -static inline enum sb_category spb_get_category(struct superpageblock *sb) -{ - if (sb->nr_unmovable || sb->nr_reclaimable || sb->nr_reserved) - return SB_TAINTED; - return SB_CLEAN; -} +/* spb_get_category() lives in for shared use with + * mm/compaction.c. */ /** * sb_get_fullness - Determine the fullness bucket for a superpageblock @@ -2700,13 +2686,10 @@ static void prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags * * Scale with SPB size: reserve ~3% of pageblocks (minimum 4). * For a 512-pageblock SPB this gives 16 reserved pageblocks. + * + * SPB_TAINTED_RESERVE_MIN and spb_tainted_reserve() live in + * for shared use with mm/compaction.c. */ -#define SPB_TAINTED_RESERVE_MIN 4 - -static inline u16 spb_tainted_reserve(const struct superpageblock *sb) -{ - return max_t(u16, SPB_TAINTED_RESERVE_MIN, sb->total_pageblocks / 32); -} /* * spb_tainted_can_serve_smaller - could a smaller-order @migratetype alloc -- 2.54.0