From nobody Sat Apr 4 06:08:14 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 3957E3ED5CE for ; Fri, 20 Mar 2026 18:24:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774031045; cv=none; b=EV4gJftBLX+02pJQdIDrl4OVUoFxvRbeQImSYKjcBczBRrBIWJ1IC73/js1e9vMzkRGgfR0eKQbz+tBiO3M8g0pUtVIOQPB96Uwl88u0Ad2yTcscN0uclRg422eBKgycs4mLe6Vzc2TqpemPxOkpv/FA2jdKjVF1zHWT+mgUfqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774031045; c=relaxed/simple; bh=z9LVwuLmWEPIvYoVw+iLbj2TtpW0/0v2lLIyNHFoEgY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=S5xfG76JnSBWW0AAIfDzQ3NG2bzeqtfHNkrLGB8nnvIOdaNV/jFJt5ghvBa8bwb2cU5+slyaysAH5KP1IX1FQz9/m+HfU9eZTxwj7sI/C653cQEEPIobKzRGmEMdJGW1GFVhZXm9t9Whx4fU7vZcvCd6n6uzWwjEf7XKWfIdouU= 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=EoDVT1M1; arc=none smtp.client-ip=209.85.221.74 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="EoDVT1M1" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-439bab2d095so1319211f8f.3 for ; Fri, 20 Mar 2026 11:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774031042; x=1774635842; 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=LYutBkNzGTjSKKTNrswnBU+hV/hIHGIX2yw2puv+rhw=; b=EoDVT1M1hE8JHQdO6clVjxU9enLAFLezBMplkMpoNWZLqk5u14VgfwbBAkQylpa8d0 Al6lWhn+lme+5vUKHpRsw7A8jBx267r2w6GtSk4ckjAeRpQJdv9tXW0lOhPstqIWmPG4 whcBw/ZhAcLTxI37Ah0ixJSeR182rEPn6isImjPfqvpeBbwuU6RzeltfWI7ykoLuBCMO FqM2xlMLZVkZBgef37ArTYNvFTGikX+RyVHrdTUzVnlc8lsAhW4pswh89jXRlrh2Xrw0 +UTPaDu//sKQCsYqPlwUg106o8afO5QkCQGeKdGr+snWED2og1hN5XSti+FF82/5Zio4 3zkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774031042; x=1774635842; 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=LYutBkNzGTjSKKTNrswnBU+hV/hIHGIX2yw2puv+rhw=; b=P6XJvQkuEEqt4zZAYHEqURmb8jNj+eHTPDxzDkM6BRsRMcm+a+wo++pp8IhRp4qmeu PjEATAnMVlmhQYHFm7NQXYpoviAF7Qi1MYQV03s2ULNiP9ucFzmjy3/mxVDJznLU7jOp Pio/s0XJo6gxoND9jvrcX+UN7vqCjsFOEmrhDPxdgs1r541tAnXrjD1UyZcKC+FZzpyZ 3H+h6Kz3cHFfTEtB+j5BGecl1MYuTo7lsBtfJfTzm1DpGBNsE1XoDL7C7AemLVD5vOkg +uLe8Un7V5OI5rM6ydqa9nLOrVIpDy48iEgTRp2x0DCtFVFLi5/r+TXt9M9YhWP5dJYm kusg== X-Forwarded-Encrypted: i=1; AJvYcCXqjGI6s3qRfsYf/TCm0CbNPHnQLWFSAyNvKnchJ+26vauAPKeQLxNbOkOCOWVrE6LJt/078o5vfftbLkg=@vger.kernel.org X-Gm-Message-State: AOJu0YwgCu42xTX44jKj45Krj1ljjcCLGiisbiNiWR7eRDqsgT9xkhBd TnUZ7g+oyqM9vF7PbMnYWZSO5xidqK0bJAoQeiv1qmECBgQibWrvqF5VJyGol5TP4iioPeUZAt5 VnHKvfRsBWzySbw== X-Received: from wrsy7.prod.google.com ([2002:a5d:4ac7:0:b0:43b:4eb4:e4ea]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:4203:b0:43b:47ee:4586 with SMTP id ffacd0b85a97d-43b642755e8mr6997133f8f.29.1774031042331; Fri, 20 Mar 2026 11:24:02 -0700 (PDT) Date: Fri, 20 Mar 2026 18:23:40 +0000 In-Reply-To: <20260320-page_alloc-unmapped-v2-0-28bf1bd54f41@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260320-page_alloc-unmapped-v2-0-28bf1bd54f41@google.com> X-Mailer: b4 0.14.3 Message-ID: <20260320-page_alloc-unmapped-v2-16-28bf1bd54f41@google.com> Subject: [PATCH v2 16/22] mm/page_alloc: separate pcplists by freetype flags From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Vlastimil Babka , 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 , 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" Content-Transfer-Encoding: quoted-printable The normal freelists are already separated by this flag, so now update the pcplists accordingly. This follows the most "obvious" design where __GFP_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. Signed-off-by: Brendan Jackman --- include/linux/mmzone.h | 11 ++++++++++- mm/page_alloc.c | 44 +++++++++++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index af662e4912591..65efc08152b0c 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -778,8 +778,17 @@ enum zone_watermarks { #else #define NR_PCP_THP 0 #endif +/* + * FREETYPE_UNMAPPED can currently only be used with MIGRATE_UNMOVABLE, no= 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) =20 /* * Flags used in pcp->flags field. diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f125eae790f73..53848312a0c21 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -694,18 +694,30 @@ static void bad_page(struct page *page, const char *r= eason) add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); } =20 -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 =3D free_to_migratetype(freetype); + + VM_BUG_ON(migratetype >=3D MIGRATE_PCPTYPES); + VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER && + (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) || order !=3D HPAGE_PMD_ORDER)= ); + + /* FREETYPE_UNMAPPED currently always means MIGRATE_UNMOVABLE. */ + if (freetype_flags(freetype) & FREETYPE_UNMAPPED) { + int order_offset =3D order; + + VM_BUG_ON(migratetype !=3D MIGRATE_UNMOVABLE); + if (order > PAGE_ALLOC_COSTLY_ORDER) + order_offset =3D PAGE_ALLOC_COSTLY_ORDER + 1; + + return NR_LOWORDER_PCP_LISTS + NR_PCP_THP + order_offset; + } + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { bool movable =3D migratetype =3D=3D MIGRATE_MOVABLE; =20 - if (order > PAGE_ALLOC_COSTLY_ORDER) { - VM_BUG_ON(!is_pmd_order(order)); - + if (order > PAGE_ALLOC_COSTLY_ORDER) return NR_LOWORDER_PCP_LISTS + movable; - } - } else { - VM_BUG_ON(order > PAGE_ALLOC_COSTLY_ORDER); } =20 return (MIGRATE_PCPTYPES * order) + migratetype; @@ -713,8 +725,18 @@ static inline unsigned int order_to_pindex(int migrate= type, int order) =20 static inline int pindex_to_order(unsigned int pindex) { - int order =3D pindex / MIGRATE_PCPTYPES; + unsigned int unmapped_base =3D NR_LOWORDER_PCP_LISTS + NR_PCP_THP; + int order; =20 + if (pindex >=3D unmapped_base) { + order =3D pindex - unmapped_base; + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && + order > PAGE_ALLOC_COSTLY_ORDER) + return HPAGE_PMD_ORDER; + return order; + } + + order =3D pindex / MIGRATE_PCPTYPES; if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) { if (pindex >=3D NR_LOWORDER_PCP_LISTS) order =3D HPAGE_PMD_ORDER; @@ -2935,7 +2957,7 @@ static bool free_frozen_page_commit(struct zone *zone, */ pcp->alloc_factor >>=3D 1; __count_vm_events(PGFREE, 1 << order); - pindex =3D order_to_pindex(free_to_migratetype(freetype), order); + pindex =3D order_to_pindex(freetype, order); list_add(&page->pcp_list, &pcp->lists[pindex]); pcp->count +=3D 1 << order; =20 @@ -3452,7 +3474,7 @@ static struct page *rmqueue_pcplist(struct zone *pref= erred_zone, * frees. */ pcp->free_count >>=3D 1; - list =3D &pcp->lists[order_to_pindex(free_to_migratetype(freetype), order= )]; + list =3D &pcp->lists[order_to_pindex(freetype, order)]; page =3D __rmqueue_pcplist(zone, order, freetype, alloc_flags, pcp, list); pcp_spin_unlock(pcp); if (page) { @@ -5236,7 +5258,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int = preferred_nid, goto failed; =20 /* Attempt the batch allocation */ - pcp_list =3D &pcp->lists[order_to_pindex(free_to_migratetype(ac.freetype)= , 0)]; + pcp_list =3D &pcp->lists[order_to_pindex(ac.freetype, 0)]; while (nr_populated < nr_pages) { =20 /* Skip existing pages */ --=20 2.51.2