From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B3CE3DA7D4 for ; Wed, 25 Feb 2026 16:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037296; cv=none; b=SE3IkAj4P6495x5mHqFq6KlDINZYEv8zRhEdCJs9ZZk6FsXJOrgeOzzqYPTRgJc33uojpy8Pwxo8XVxmZSyvUDp6Bg07U/H56gBbT+qrhUYQnenDQFn0o+xq+VvlDSxc07ZXfJGdWWo5Bk42/kJWDsICqnm3LqEOJVexFP0WPrA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037296; c=relaxed/simple; bh=cGOyuZFyWr/EMwK2983XzGq7Ec2kfMwKBcWiL0Hr9TM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=hgy5DE8J9lpo8VnFgH/bWsPN21VFnj95I+mtzj+d33PxRj1cXIrXG/RXNARuMvyZnaEVlM3k8N7eNhXZUufYI2iLP5w1/SZg+6m7n92g197jRRukLT40wiveoy2SUGDy/WaKZE+YnXp3U9AWPHbCH0wscUoSMmZxUH7hEtE5xLA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gutidSd6; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gutidSd6" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-483786a09b1so73181335e9.3 for ; Wed, 25 Feb 2026 08:34:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772037293; x=1772642093; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LE2SwiqlFKC41gD5ncV0ztisIzW1QHpma9eQC/BfO8Y=; b=gutidSd6DMVyOvYVZDKNfGXBS18KlSk/CA8yiO5gxKReWfUe12IQWuf5g7rXkDpQ2U yb4D/bauO9yoDtUUbegB4tpUUxpyQnX/O+sv5jR2XB2XDKyBlVe6W4V5SgQ/MF1sk4e4 OTAZvt04iXvpu5CZ2zCb6C5nW34cdb0T0+SQhOsGj68Tp+rlg717aLpWcadpL+6Wq+xf G03doaV6G4z/fn8PVlEP/D2WOgfGwFwXHOMkHgOv5aycu5LiweRDavPlpuGIq/KPWzNk EB3FT5VlEqUbVi2P0O7GQXAM9zWSYETdWMGY92RZgQ26Vm0ApK6SbKKmTp2QkgpFba5u oxuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772037293; x=1772642093; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LE2SwiqlFKC41gD5ncV0ztisIzW1QHpma9eQC/BfO8Y=; b=rdTPzoOosScVPwqfjyMySGuKqD3cAx13QOtWxmMFqjTLE8o/LZW4zLDFopjdYYIAUr HjyI31ijjQuoRm6KbsOY43/OnnW5WbtPo3lP8LnsIQOcPYtBjgaiz4nHLBRgKhJ69ixe /+ChgWrah9TAIgY0QZm8mbmmoWx7ioNyfPb9meISASW2z42zHgImjKvSS6b2HTIpnuSo BfP9PJ3rki+iv+5DnWGzcoAKcCGn5GKSY5N2qyJIMqNmFwjPebprxxjvhQ9kENMKiArh Ti7aazD74/8Hd+cbWvpNnTEyJmezsGvdL9cNu5c1WWUI6DINuR3nFLSCo4BgOH4p1btq xm6w== X-Forwarded-Encrypted: i=1; AJvYcCWg6659sXbv7lqtpHXRbEm9dqOhqNdXWrmLa7xX22eO/8R/hf3/tNUwIXF5LOlquKGe74laVteYwUmUNI8=@vger.kernel.org X-Gm-Message-State: AOJu0YyaHzYxskD1BHGot+W7Gv+3MWs3dH7Q3zEpw5P4HK2gV3vl0fGn Ax/OEXfxOma3eDBzJgxch3/JFAAdyBJ+qtBs/u2aNiZuCeB3wF7BxlfQk/QJTbhh8mq+ecPt4se +yPC8Rno1pzy/nw== X-Received: from wmri10-n2.prod.google.com ([2002:a05:600c:8a0a:20b0:47e:e27f:e298]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600d:8450:20b0:483:b505:9db4 with SMTP id 5b1f17b1804b1-483b5059e2dmr135408765e9.31.1772037292676; Wed, 25 Feb 2026 08:34:52 -0800 (PST) Date: Wed, 25 Feb 2026 16:34:37 +0000 In-Reply-To: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> X-Mailer: b4 0.14.3 Message-ID: <20260225-page_alloc-unmapped-v1-12-e8808a03cd66@google.com> Subject: [PATCH RFC 12/19] mm: encode freetype flags in pageblock flags From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Vlastimil Babka , Wei Xu , Johannes Weiner , Zi Yan Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, rppt@kernel.org, Sumit Garg , derkling@google.com, reijiw@google.com, Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Brendan Jackman , Yosry Ahmed Content-Type: text/plain; charset="utf-8" In preparation for implementing allocation from FREETYPE_UNMAPPED lists. Since it works nicely with the existing allocator logic, and also offers a simple way to amortize TLB flushing costs, __GFP_UNMAPPED will be implemented by changing mappings at pageblock granularity. Therefore, encode the mapping state in the pageblock flags. Also add the necessary logic to record this from a freetype, and reconstruct a freetype from the pageblock flags. Signed-off-by: Brendan Jackman --- include/linux/pageblock-flags.h | 10 ++++++++++ mm/page_alloc.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/include/linux/pageblock-flags.h b/include/linux/pageblock-flags.h index 9a6c3ea17684d..b634280050071 100644 --- a/include/linux/pageblock-flags.h +++ b/include/linux/pageblock-flags.h @@ -11,6 +11,8 @@ #ifndef PAGEBLOCK_FLAGS_H #define PAGEBLOCK_FLAGS_H +#include +#include #include /* Bit indices that affect a whole block of pages */ @@ -18,6 +20,9 @@ enum pageblock_bits { PB_migrate_0, PB_migrate_1, PB_migrate_2, + PB_freetype_flags, + PB_freetype_flags_end = PB_freetype_flags + NUM_FREETYPE_FLAGS - 1, + PB_compact_skip,/* If set the block is skipped by compaction */ #ifdef CONFIG_MEMORY_ISOLATION @@ -37,6 +42,7 @@ enum pageblock_bits { #define NR_PAGEBLOCK_BITS (roundup_pow_of_two(__NR_PAGEBLOCK_BITS)) #define PAGEBLOCK_MIGRATETYPE_MASK (BIT(PB_migrate_0)|BIT(PB_migrate_1)|BIT(PB_migrate_2)) +#define PAGEBLOCK_FREETYPE_FLAGS_MASK (((1 << NUM_FREETYPE_FLAGS) - 1) << PB_freetype_flags) #ifdef CONFIG_MEMORY_ISOLATION #define PAGEBLOCK_ISO_MASK BIT(PB_migrate_isolate) @@ -44,6 +50,10 @@ enum pageblock_bits { #define PAGEBLOCK_ISO_MASK 0 #endif +#define PAGEBLOCK_FREETYPE_MASK (PAGEBLOCK_MIGRATETYPE_MASK | \ + PAGEBLOCK_ISO_MASK | \ + PAGEBLOCK_FREETYPE_FLAGS_MASK) + #if defined(CONFIG_HUGETLB_PAGE) #ifdef CONFIG_HUGETLB_PAGE_SIZE_VARIABLE diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 9635433c7d711..b79f81b64d9d7 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -392,11 +392,8 @@ get_pfnblock_bitmap_bitidx(const struct page *page, unsigned long pfn, unsigned long *bitmap; unsigned long word_bitidx; -#ifdef CONFIG_MEMORY_ISOLATION - BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 8); -#else - BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4); -#endif + /* NR_PAGEBLOCK_BITS must divide word size. */ + BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4 && NR_PAGEBLOCK_BITS != 8); BUILD_BUG_ON(__MIGRATE_TYPE_END > PAGEBLOCK_MIGRATETYPE_MASK); VM_BUG_ON_PAGE(!zone_spans_pfn(page_zone(page), pfn), page); @@ -469,9 +466,20 @@ __always_inline freetype_t __get_pfnblock_freetype(const struct page *page, unsigned long pfn, bool ignore_iso) { - int mt = get_pfnblock_migratetype(page, pfn); + unsigned long mask = PAGEBLOCK_FREETYPE_MASK; + enum migratetype migratetype; + unsigned int ft_flags; + unsigned long flags; - return migrate_to_freetype(mt, 0); + flags = __get_pfnblock_flags_mask(page, pfn, mask); + ft_flags = (flags & PAGEBLOCK_FREETYPE_FLAGS_MASK) >> PB_freetype_flags; + + migratetype = flags & PAGEBLOCK_MIGRATETYPE_MASK; +#ifdef CONFIG_MEMORY_ISOLATION + if (!ignore_iso && flags & BIT(PB_migrate_isolate)) + migratetype = MIGRATE_ISOLATE; +#endif + return migrate_to_freetype(migratetype, ft_flags); } /** @@ -605,6 +613,15 @@ static void set_pageblock_migratetype(struct page *page, PAGEBLOCK_MIGRATETYPE_MASK | PAGEBLOCK_ISO_MASK); } +static inline void set_pageblock_freetype_flags(struct page *page, + unsigned int ft_flags) +{ + unsigned int flags = ft_flags << PB_freetype_flags; + + __set_pfnblock_flags_mask(page, page_to_pfn(page), flags, + PAGEBLOCK_FREETYPE_FLAGS_MASK); +} + void __meminit init_pageblock_migratetype(struct page *page, enum migratetype migratetype, bool isolate) @@ -628,7 +645,7 @@ void __meminit init_pageblock_migratetype(struct page *page, flags |= BIT(PB_migrate_isolate); #endif __set_pfnblock_flags_mask(page, page_to_pfn(page), flags, - PAGEBLOCK_MIGRATETYPE_MASK | PAGEBLOCK_ISO_MASK); + PAGEBLOCK_FREETYPE_MASK); } #ifdef CONFIG_DEBUG_VM -- 2.51.2