From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 38FD95474F for ; Tue, 18 Aug 2026 01:01:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787014880; cv=none; b=LO3wrR8g2yrchz0kJdFEIe5llg3tFr88e51/xpZXRAIHw6gsx3Wfbelg8WYMbHE+m7iV0Wya+yknxuX2bdGaZ8S4O8uGl74tFDUz3Wt3L1Iy8ZtdES8LcVd53B64W+KhFhMFXVqX2moekbPofaCGAy5zro0VQx7UCCZONjTOEjc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787014880; c=relaxed/simple; bh=R9ZvDjlNbUgX6fat45Tp0Kas/SJXyi83RfTIlXZKtU0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pTshqoHHi8VkrUIcsS+c29Dlh8c7Udw4MTw01sCQj4aMPMtS+FT5koIkEkn4G2gCJS5w5kgnL8W8DfTX0NPCTeVU9wdw1ZcYJvUXPlulcsAyG8ht4kmj+wXR3DokbIL8xiKGpKj5KZc5ZQ61+ZdZKWGI/wU+RbiSlwSxySfxrGY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aKnLqSYG; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aKnLqSYG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D17081F000E9; Tue, 18 Aug 2026 01:01:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787014878; bh=+QD5d267PH0IMQTt0pb3tQZChKremBcVsncH9JWPYf0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=aKnLqSYGDe6Pt2Gz6AXtiX+qNyYEIoBO8XbsbQrp56ap0mXJ0rG65QGZiS3IPKo29 z8cbPpo2p045dfHPZyZ/B+2B1jc4M+iaw+MUuTNbfZuL88m6PWrpBlCpzDtxs1UGTQ +6vfDHpVVHlHWfyiMrmFVkkx3XfHvfUFGpuFwBDv0pCXRbOq1KCdCjPD5/9brfymvz ptO/glLoHVTl25cUT/Goq84B3fZsPXLtBowEIt8tGCIcMSXjaP0V7PlS4wm8U9wDfS XRFkV0O+SSNKjRSldLb77tKWlERbudVShJ4d0d48aiRCqbi39GjXC5k/RCMNGrYpuo V6daW+bEvGpDg== Date: Tue, 18 Aug 2026 01:01:16 +0000 From: Yosry Ahmed To: Brendan Jackman Cc: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Vlastimil Babka , Mike Rapoport , Wei Xu , Johannes Weiner , Zi Yan , Lorenzo Stoakes , linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, Sumit Garg , Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Patrick Bellasi , Reiji Watanabe , Sean Christopherson Subject: Re: [PATCH v3 21/26] mm/page_alloc: implement FREETYPE_UNMAPPED allocations Message-ID: References: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> <20260726-page_alloc-unmapped-v3-21-6f5729aa9832@google.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=us-ascii Content-Disposition: inline In-Reply-To: <20260726-page_alloc-unmapped-v3-21-6f5729aa9832@google.com> On Sun, Jul 26, 2026 at 10:22:54PM +0000, Brendan Jackman wrote: > Currently FREETYPE_UNMAPPED allocs will always fail because, although the > lists exist to hold them, there is no way to actually create an unmapped > page block. This commit adds one, and also the logic to map it back > again when that's needed. > > Doing this at pageblock granularity ensures that the pageblock flags can > be used to infer which freetype a page belongs to. It also provides nice > batching of TLB flushes, and also avoids creating too much unnecessary > TLB fragmentation in the physmap. > > There are some functional requirements for flipping a block: > > - Unmapping requires a TLB shootdown, meaning IRQs must be enabled. > > - Updating the pagetables might require allocating a pagetable to break > down a huge page. This would deadlock if the zone lock was held. > > This makes allocations that need to change sensitivity _somewhat_ > similar to those that need to fallback to a different migratetype. But, > the locking requirements mean that this can't just be squashed into the > existing "fallback" allocator logic, instead a new allocator path just > for this purpose is needed. > > The new path is assumed to be much cheaper than the really heavyweight > stuff like compaction and reclaim. But at present it is treated as less > desirable than the mobility-related "fallback" and "stealing" logic. > This might turn out to need revision (in particular, maybe it's a > problem that __rmqueue_steal(), which causes fragmentation, happens > before __rmqueue_direct_map()), but that should be treated as a subsequent > optimisation project. > > Adding alloc_flags to gfp_freetype() requires moving it to > mm/page_alloc.h so it can refer to ALLOC_UNMAPPED. It was already only > used in internal mm code. > > Now that unmapped pageblocks actually exist, exclude them from > migration. Migrating unmapped pages via the mermap should be possible > but that's something to be added later when needed. > > Signed-off-by: Brendan Jackman > --- > mm/Kconfig | 7 +- > mm/compaction.c | 8 ++- > mm/page_alloc.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++++------- > mm/page_alloc.h | 13 +++- > mm/page_owner.c | 6 +- > 5 files changed, 215 insertions(+), 33 deletions(-) > > diff --git a/mm/Kconfig b/mm/Kconfig > index aa5f041ce1a67..6a89cbf8e8c6e 100644 > --- a/mm/Kconfig > +++ b/mm/Kconfig > @@ -1527,9 +1527,10 @@ config MERMAP_KUNIT_TEST > > If unsure, say N. > > +config PAGE_ALLOC_UNMAPPED > + bool > + depends on !HIGHMEM > + > source "mm/damon/Kconfig" > > endmenu > - > -config PAGE_ALLOC_UNMAPPED > - bool > diff --git a/mm/compaction.c b/mm/compaction.c > index 67b01af024e17..c9eb3947ffc79 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -1393,6 +1393,9 @@ static bool suitable_migration_source(struct compact_control *cc, There is a direct compaction check above the context lines: /* * Background compaction produces blocks for the zone at * large, with no particular allocation context. Allow all * block types, including CMA. */ if (!cc->direct_compaction) return true; > block_ft = get_pageblock_freetype(page); > block_mt = free_to_migratetype(block_ft); > > + if (freetype_unmapped(get_pageblock_freetype(page))) > + return false; ..and I think this freetype_unmapped() check should be moved above it. Otherwise kcompactd (for e.g.) won't check for unmapped pages and crashes. [..] > +#ifdef CONFIG_PAGE_ALLOC_UNMAPPED > +/* Try to allocate a page by mapping/unmapping a block from the direct map. */ > +static inline struct page * > +__rmqueue_direct_map(struct zone *zone, unsigned int request_order, > + unsigned int alloc_flags, freetype_t freetype) > +{ > + unsigned int ft_flags_other = freetype_flags(freetype) ^ FREETYPE_UNMAPPED; > + freetype_t ft_other = migrate_to_freetype(free_to_migratetype(freetype), > + ft_flags_other); > + bool want_mapped = !(freetype_flags(freetype) & FREETYPE_UNMAPPED); > + enum rmqueue_mode rmqm = RMQUEUE_NORMAL; > + unsigned long irq_flags; > + int nr_pageblocks, nr_freed; > + struct page *page; > + int alloc_order; > + int err; > + > + if (freetype_idx(ft_other) < 0) > + return NULL; For a movable mapped allocation, ft_other will end up being movable unmapped, which will immediately fail this check before trying to convert a pageblock. This leads to premature OOM kills. > + > + /* > + * Might need a TLB shootdown. Even if IRQs are on this isn't > + * safe if the caller holds a lock (in case the other CPUs need that > + * lock to handle the shootdown IPI). > + */ > + if (alloc_flags & ALLOC_NOBLOCK) > + return NULL; > + > + if (!can_set_direct_map() || alloc_flags & ALLOC_NOLOCK) > + return NULL; > + > + lockdep_assert(!irqs_disabled() || unlikely(early_boot_irqs_disabled)); > + > + /* > + * Need to [un]map a whole pageblock (otherwise it might require > + * allocating pagetables). First allocate it. > + */ > + alloc_order = max(request_order, pageblock_order); > + nr_pageblocks = 1 << (alloc_order - pageblock_order); > + spin_lock_irqsave(&zone->lock, irq_flags); > + /* First try a block that already has the right migratetype. */ > + page = __rmqueue(zone, alloc_order, ft_other, alloc_flags, &rmqm); > + if (!page) { > + /* Fallback to changing a block's migratetype. */ > + rmqm = RMQUEUE_CLAIM; > + page = __rmqueue(zone, alloc_order, ft_other, alloc_flags, &rmqm); IIUC, the first call to __rmqueue() will already try RMQUEUE_CLAIM. Is this redundant?