From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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 266393E3C5A for ; Sun, 26 Jul 2026 22:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104635; cv=none; b=M42FWy2Zs6eroxIL3StxPAJsFkYcIeyJwQiyNWnEzjgDyluKTIajjlCz6wvAAFyjc4fIUA05GHgPXkGgqLbzz645DhZeo+quTu0vZLseMN+SDIdhjOCbARrXr8I11jW2pGcV3zDxr20JrCfJf6KemYYR/37mN95LBboGmyoQvB8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104635; c=relaxed/simple; bh=KluIx9n+QQH281rwvQw2hd6ydWFJ9k6lCjNOc2FPeFQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mm+MNaj2fXkuqh2Lz87RbCmNLSXyEPfUb2lLOy19IeVGBUbWUzqTUKgIeS9zbhahydBQQbM9w9JlVWJsoacg6wA4U04lGQILCZgnrK22Vg8qnDCxI5cdHoO4tJLuIlHhMp5AybHQKj9VAl7FIIW7j3AVKsGFRZ2+rybG1h9Id24= 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=FljhODmD; arc=none smtp.client-ip=209.85.128.71 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="FljhODmD" Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-490a767b782so15251825e9.2 for ; Sun, 26 Jul 2026 15:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785104628; x=1785709428; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=WXPhImrBERPbppuQB021OFH7MVznckDFLoOQIpa5uHc=; b=FljhODmD2xOPMkfim5HRAOfIPEwNRQ/Ovq4EpSMeALQ5vQ3k1pLt9TwBW4kJywLgXD +3yZ/8NEtf+qu9zGRFefTv2sEV+0FeHF1vZvd3JGdInb2aqxzO8aAPXoMcXFECoLw3jM KyUGFF6+98xLL0XQyzohI0UNVEjUTyZJPmfs330HtPTCAgTVCqzVVL5N2t6RIvCWGYwI n04z8MKsTP6cuHMLoXpDvrH4WyAP8O+HLriPdIsMW0MlDOs14V/4U2jTy/s2T7MhFMur o2M2GnBEJyfOL8/f+PdRaT58SWILsG9Ex+20IAvB72sb3Z0T52rI5z7cX1VBus9Y4a4m iVGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785104628; x=1785709428; h=content-type: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:content-type; bh=WXPhImrBERPbppuQB021OFH7MVznckDFLoOQIpa5uHc=; b=Ly0DWLLnkcjIDQMOV/SXDhETyzRvCUcDeNkVWhfaKjksEyhsPyx2kjzlSJ9A3m2sEi L9SMBdylSqBIPm0KJxbQYAH/4iTdUL2uetGq/1G9CEPA69AWinixN10ceGMqc981GPDk fDfasW9qaDf6anlXzM85ZAOeWeZIZCKp+wfl8X7jBQVTGvHhppyoDZsANF78oRuqnoYP O4raClMM0xYqc6ep1jL+heY7ATl5zwDH0doakrIQrQPsw/afeoZAMzv50+r4t0JkQATq 3EuTwzfpPHfTX8/LGjrO7cMvi99QYzoElAf3EhtqPB69nzXThCNQriVyq/PcxCyEd0b6 doug== X-Forwarded-Encrypted: i=1; AHgh+Rob+Nk+TSCvNAPOTGasNIqXM91bBbo8rfq4uBUl0uHpApkS4uOpCn4N9J6CA1Y/QEwi/6gb66x/ka/sjGA=@vger.kernel.org X-Gm-Message-State: AOJu0YyIuFNIwBdVPJTW090x65M3SL/XAbHp00gQhqvhphFjkwjoOSgP bvlvHmaMITmL+N8/+kDEr93x8AkLBoojJcoZpmviyhM85B8/8krbLV75kSa8syAnMmhaao4Dovb IrxskjukSNZA9TA== X-Received: from wmdd24.prod.google.com ([2002:a05:600c:a218:b0:495:46dc:fbb2]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1382:b0:492:7142:f46e with SMTP id 5b1f17b1804b1-496b56f0f59mr68861155e9.2.1785104628082; Sun, 26 Jul 2026 15:23:48 -0700 (PDT) Date: Sun, 26 Jul 2026 22:22:51 +0000 In-Reply-To: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> X-Mailer: b4 0.16-dev Message-ID: <20260726-page_alloc-unmapped-v3-18-6f5729aa9832@google.com> Subject: [PATCH v3 18/26] mm/page_alloc: separate pcplists by freetype flags From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Vlastimil Babka , Mike Rapoport , Wei Xu , Johannes Weiner , Zi Yan , Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, rppt@kernel.org, Sumit Garg , Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Yosry Ahmed , Patrick Bellasi , Reiji Watanabe , Sean Christopherson , Brendan Jackman Content-Type: text/plain; charset="utf-8" The normal freelists are already separated by this flag, so now update the pcplists accordingly. This follows the most "obvious" design where ALLOC_UNMAPPED is supported at arbitrary orders. If necessary, it would be possible to avoid the proliferation of pcplists by restricting orders that can be allocated from them with this FREETYPE_UNMAPPED. On the other hand, there's currently no usecase for movable/reclaimable unmapped memory, and constraining the migratetype doesn't have any tricky plumbing implications. So, take advantage of that and assume that FREETYPE_UNMAPPED implies MIGRATE_UNMOVABLE. Overall, this just takes the existing space of pindices and tacks another bank on the end. For !THP this is just 4 more lists, with THP there is a single additional list for hugepages. Reviewed-by: Vlastimil Babka (SUSE) Signed-off-by: Brendan Jackman --- include/linux/mmzone.h | 11 ++++++++++- mm/page_alloc.c | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 78455285dda7c..2533a228f71fd 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -789,8 +789,17 @@ enum zone_watermarks { #else #define NR_PCP_THP 0 #endif +/* + * FREETYPE_UNMAPPED can currently only be used with MIGRATE_UNMOVABLE, so for + * those there's no need to encode the migratetype in the pindex. + */ +#ifdef CONFIG_PAGE_ALLOC_UNMAPPED +#define NR_UNMAPPED_PCP_LISTS (PAGE_ALLOC_COSTLY_ORDER + 1 + !!NR_PCP_THP) +#else +#define NR_UNMAPPED_PCP_LISTS 0 +#endif #define NR_LOWORDER_PCP_LISTS (MIGRATE_PCPTYPES * (PAGE_ALLOC_COSTLY_ORDER + 1)) -#define NR_PCP_LISTS (NR_LOWORDER_PCP_LISTS + NR_PCP_THP) +#define NR_PCP_LISTS (NR_LOWORDER_PCP_LISTS + NR_PCP_THP + NR_UNMAPPED_PCP_LISTS) /* * Flags used in pcp->flags field. diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 33b7d354e1e03..30ba61c20209c 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -690,8 +690,25 @@ static void bad_page(struct page *page, const char *reason) add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); } -static inline unsigned int order_to_pindex(int migratetype, int order) +static inline unsigned int order_to_pindex(freetype_t freetype, int order) { + int migratetype = free_to_migratetype(freetype); + + VM_BUG_ON(migratetype >= MIGRATE_PCPTYPES); + VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER && + (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) || order != HPAGE_PMD_ORDER)); + + /* FREETYPE_UNMAPPED currently always means MIGRATE_UNMOVABLE. */ + if (freetype_flags(freetype) & FREETYPE_UNMAPPED) { + int order_offset = order; + + VM_BUG_ON(migratetype != MIGRATE_UNMOVABLE); + if (order > PAGE_ALLOC_COSTLY_ORDER) + order_offset = PAGE_ALLOC_COSTLY_ORDER + 1; + + return NR_LOWORDER_PCP_LISTS + NR_PCP_THP + order_offset; + } + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { bool movable = migratetype == MIGRATE_MOVABLE; @@ -704,8 +721,18 @@ static inline unsigned int order_to_pindex(int migratetype, int order) static inline int pindex_to_order(unsigned int pindex) { - int order = pindex / MIGRATE_PCPTYPES; + unsigned int unmapped_base = NR_LOWORDER_PCP_LISTS + NR_PCP_THP; + int order; + if (pindex >= unmapped_base) { + order = pindex - unmapped_base; + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && + order > PAGE_ALLOC_COSTLY_ORDER) + return HPAGE_PMD_ORDER; + return order; + } + + order = pindex / MIGRATE_PCPTYPES; if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { if (pindex >= NR_LOWORDER_PCP_LISTS) order = HPAGE_PMD_ORDER; @@ -3007,7 +3034,7 @@ static bool free_frozen_page_commit(struct zone *zone, */ pcp->alloc_factor >>= 1; __count_vm_events(PGFREE, 1 << order); - pindex = order_to_pindex(free_to_migratetype(freetype), order); + pindex = order_to_pindex(freetype, order); list_add(&page->pcp_list, &pcp->lists[pindex]); pcp->count += 1 << order; @@ -3545,7 +3572,7 @@ static struct page *rmqueue_pcplist(struct zone *preferred_zone, * frees. */ pcp->free_count >>= 1; - list = &pcp->lists[order_to_pindex(free_to_migratetype(freetype), order)]; + list = &pcp->lists[order_to_pindex(freetype, order)]; page = __rmqueue_pcplist(zone, order, freetype, alloc_flags, pcp, list); pcp_spin_unlock(pcp); if (page) { @@ -5428,7 +5455,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid, goto failed; /* Attempt the batch allocation */ - pcp_list = &pcp->lists[order_to_pindex(free_to_migratetype(ac.freetype), 0)]; + pcp_list = &pcp->lists[order_to_pindex(ac.freetype, 0)]; while (nr_populated < nr_pages) { /* Skip existing pages */ -- 2.54.0