From nobody Sat Apr 4 06:09:10 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 ACB983EB7E7 for ; Fri, 20 Mar 2026 18:23:55 +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=1774031037; cv=none; b=Q6atP+LtY+DTmqNZW6mk8fg+Af4AFTLvq+QKggSpxtFG6PSngvMZ9jHaDp+p2QZ6c3nreAGkAdqmfqm464ElwV1bwJtxzM4RPkCtV6jrksCuZnsgjaKp1yvmYyQeL3sDeBpO3t68yifeiwBvni00Qed7Bhdyv3C+hTPX/gsy9+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774031037; c=relaxed/simple; bh=Hg4ZzwJAr8P6UV4LMZZqqWhIYeVlIeLXkLCQaw+4zZs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gGy6QgPwyHggsg61z8l+QTtoY1CgQvzYlztppFJw4YMNzcSvUsPLykXZy6RzlH9xPOWtIczMYylKHOs9LI2iy6CpCBADNJ/0h6mSHf2D8vA1wfuDMyeD65yRQ/xqUm9UrSc0smOd3GYT3xGbzuGwM2fizHnulq7IzN7PIsJ48Ik= 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=WHm0JaJQ; 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="WHm0JaJQ" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-439c54e0f6aso1593340f8f.0 for ; Fri, 20 Mar 2026 11:23:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1774031034; x=1774635834; 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=14rGLwIJsIU7kDdMmmS+f3PtwDgFodk3F7eGnVzIexI=; b=WHm0JaJQXRvb/tPWt6QDlu0WW5T0Sq/pZWhnNMnJ/H86PKRsHNCeSqz/ptx4souKVT 7lNxtGrSXBolN848y91O5DPqHCerjlnQeriklWPzxToxdR7MdXWQ8m8LnNmmb5M45C5d ot+WWLXsUzSh+WlF6rEqn/ZZ/aawYRY68syvQ5GPqSnVixSCeVb9yJKlCVRJ4wrIBaTp nxL5VLFlFYNJxrPMGfnVCoy+dENXApfisDmrO7H1XBuo9aJLlm7p5gJQJvb79funEGLu Gg7Dd2VaRkWJHWgpw2hVjWa8XpzTBFL85RKJF5bqr8h7PG7ynzAW/MT8XkhgUgyxbokC 36YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774031034; x=1774635834; 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=14rGLwIJsIU7kDdMmmS+f3PtwDgFodk3F7eGnVzIexI=; b=Q2Br4zuZLPUUSqChjtJuIehKnGxE+OIHBUzClCqw5Ydl9cdN9vrKOri6BFOhQwXcby c9pn9eKgfIAdn2qse2mUv0M2SLEsuzAIAjjLFIPFV5i1YC7+PeA+eriaYYIOi6jNGHxV HBoxPCJmjubUbTcRZzAamrMnr5F5U/V2tgV80eINMM1PfB+wzgBsjQZEbnhn8Zm4x8Nv MyOrYBqEWDGE9QIbrRWCRI7tzpLIzAqEvq3gXfUBQzhJKiLT5LlomspaCHqDVFMjp0ik Ax4eHj1fs59Hnj/33DwvVvbpsFx1F/CN9Gyq8juBRwDGtyv+Hk3XmfkeMfjHwhmKghLr M+uA== X-Forwarded-Encrypted: i=1; AJvYcCXjnShom1NtfOvFhKbV2dWMjM/jfYfosSR0jDv9vdOCmJratqBH+I1JoS3mMfnU47i03vOPSRbRBwrPqPQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxKVT9wIjyRBXKANZop3M0D51dmpVzBMEenpN42sGu/lRTf8mNk Y0YyJkgamjq1X4rgVUSjbnf3suUU9kVWiY3YUiMAUHRfNTxu6rNgbW2xhxrMksIwDj7Zz2WIroH KFMl2pDqUHC7uiQ== X-Received: from wrpr5.prod.google.com ([2002:adf:f705:0:b0:43b:4410:e055]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2d86:b0:43b:5557:ed9d with SMTP id ffacd0b85a97d-43b5772991dmr9595848f8f.25.1774031033776; Fri, 20 Mar 2026 11:23:53 -0700 (PDT) Date: Fri, 20 Mar 2026 18:23:35 +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-11-28bf1bd54f41@google.com> Subject: [PATCH v2 11/22] mm: move migratetype definitions to freetype.h 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 Since migratetypes are a sub-element of freetype, move the pure definitions into the new freetype.h. This will enable referring to these raw types from pageblock-flags.h. Signed-off-by: Brendan Jackman --- include/linux/freetype.h | 84 ++++++++++++++++++++++++++++++++++++++++++++= ++++ include/linux/mmzone.h | 73 ----------------------------------------- 2 files changed, 84 insertions(+), 73 deletions(-) diff --git a/include/linux/freetype.h b/include/linux/freetype.h index 9f857d10bb5db..11bd6d2b94349 100644 --- a/include/linux/freetype.h +++ b/include/linux/freetype.h @@ -3,6 +3,66 @@ #define _LINUX_FREETYPE_H =20 #include +#include + +/* + * A migratetype is the part of a freetype that encodes the mobility + * requirements for the allocations the freelist is intended to serve. + * + * It's also currently overloaded to encode page isolation state. + */ +enum migratetype { + MIGRATE_UNMOVABLE, + MIGRATE_MOVABLE, + MIGRATE_RECLAIMABLE, + MIGRATE_PCPTYPES, /* the number of types on the pcp lists */ + MIGRATE_HIGHATOMIC =3D MIGRATE_PCPTYPES, +#ifdef CONFIG_CMA + /* + * MIGRATE_CMA migration type is designed to mimic the way + * ZONE_MOVABLE works. Only movable pages can be allocated + * from MIGRATE_CMA pageblocks and page allocator never + * implicitly change migration type of MIGRATE_CMA pageblock. + * + * The way to use it is to change migratetype of a range of + * pageblocks to MIGRATE_CMA which can be done by + * __free_pageblock_cma() function. + */ + MIGRATE_CMA, + __MIGRATE_TYPE_END =3D MIGRATE_CMA, +#else + __MIGRATE_TYPE_END =3D MIGRATE_HIGHATOMIC, +#endif +#ifdef CONFIG_MEMORY_ISOLATION + MIGRATE_ISOLATE, /* can't allocate from here */ +#endif + MIGRATE_TYPES +}; + +/* In mm/page_alloc.c; keep in sync also with show_migration_types() there= */ +extern const char * const migratetype_names[MIGRATE_TYPES]; + +#ifdef CONFIG_CMA +# define is_migrate_cma(migratetype) unlikely((migratetype) =3D=3D MIGRAT= E_CMA) +#else +# define is_migrate_cma(migratetype) false +#endif + +static inline bool is_migrate_movable(int mt) +{ + return is_migrate_cma(mt) || mt =3D=3D MIGRATE_MOVABLE; +} + +/* + * Check whether a migratetype can be merged with another migratetype. + * + * It is only mergeable when it can fall back to other migratetypes for + * allocation. See fallbacks[MIGRATE_TYPES][3] in page_alloc.c. + */ +static inline bool migratetype_is_mergeable(int mt) +{ + return mt < MIGRATE_PCPTYPES; +} =20 /* * A freetype is the index used to identify free lists. This consists of a @@ -35,4 +95,28 @@ static inline bool freetypes_equal(freetype_t a, freetyp= e_t b) return a.migratetype =3D=3D b.migratetype; } =20 +static inline freetype_t migrate_to_freetype(enum migratetype mt, + unsigned int flags) +{ + freetype_t freetype; + + /* No flags supported yet. */ + VM_WARN_ON_ONCE(flags); + + freetype.migratetype =3D mt; + return freetype; +} + +static inline enum migratetype free_to_migratetype(freetype_t freetype) +{ + return freetype.migratetype; +} + +/* Convenience helper, return the freetype modified to have the migratetyp= e. */ +static inline freetype_t freetype_with_migrate(freetype_t freetype, + enum migratetype migratetype) +{ + return migrate_to_freetype(migratetype, freetype_flags(freetype)); +} + #endif /* _LINUX_FREETYPE_H */ diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index c456ddd1f5979..af662e4912591 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -116,39 +116,7 @@ #define __NR_VMEMMAP_TAILS (MAX_FOLIO_ORDER - VMEMMAP_TAIL_MIN_ORDER + 1) #define NR_VMEMMAP_TAILS (__NR_VMEMMAP_TAILS > 0 ? __NR_VMEMMAP_TAILS : 0) =20 -enum migratetype { - MIGRATE_UNMOVABLE, - MIGRATE_MOVABLE, - MIGRATE_RECLAIMABLE, - MIGRATE_PCPTYPES, /* the number of types on the pcp lists */ - MIGRATE_HIGHATOMIC =3D MIGRATE_PCPTYPES, #ifdef CONFIG_CMA - /* - * MIGRATE_CMA migration type is designed to mimic the way - * ZONE_MOVABLE works. Only movable pages can be allocated - * from MIGRATE_CMA pageblocks and page allocator never - * implicitly change migration type of MIGRATE_CMA pageblock. - * - * The way to use it is to change migratetype of a range of - * pageblocks to MIGRATE_CMA which can be done by - * __free_pageblock_cma() function. - */ - MIGRATE_CMA, - __MIGRATE_TYPE_END =3D MIGRATE_CMA, -#else - __MIGRATE_TYPE_END =3D MIGRATE_HIGHATOMIC, -#endif -#ifdef CONFIG_MEMORY_ISOLATION - MIGRATE_ISOLATE, /* can't allocate from here */ -#endif - MIGRATE_TYPES -}; - -/* In mm/page_alloc.c; keep in sync also with show_migration_types() there= */ -extern const char * const migratetype_names[MIGRATE_TYPES]; - -#ifdef CONFIG_CMA -# define is_migrate_cma(migratetype) unlikely((migratetype) =3D=3D MIGRAT= E_CMA) # define is_migrate_cma_page(_page) (get_pageblock_migratetype(_page) =3D= =3D MIGRATE_CMA) /* * __dump_folio() in mm/debug.c passes a folio pointer to on-stack struct = folio, @@ -157,27 +125,10 @@ extern const char * const migratetype_names[MIGRATE_T= YPES]; # define is_migrate_cma_folio(folio, pfn) \ (get_pfnblock_migratetype(&folio->page, pfn) =3D=3D MIGRATE_CMA) #else -# define is_migrate_cma(migratetype) false # define is_migrate_cma_page(_page) false # define is_migrate_cma_folio(folio, pfn) false #endif =20 -static inline bool is_migrate_movable(int mt) -{ - return is_migrate_cma(mt) || mt =3D=3D MIGRATE_MOVABLE; -} - -/* - * Check whether a migratetype can be merged with another migratetype. - * - * It is only mergeable when it can fall back to other migratetypes for - * allocation. See fallbacks[MIGRATE_TYPES][3] in page_alloc.c. - */ -static inline bool migratetype_is_mergeable(int mt) -{ - return mt < MIGRATE_PCPTYPES; -} - #define for_each_free_list(list, zone, order) \ for (order =3D 0; order < NR_PAGE_ORDERS; order++) \ for (unsigned int idx =3D 0; \ @@ -185,30 +136,6 @@ static inline bool migratetype_is_mergeable(int mt) idx < NR_FREETYPE_IDXS; \ idx++) =20 -static inline freetype_t migrate_to_freetype(enum migratetype mt, - unsigned int flags) -{ - freetype_t freetype; - - /* No flags supported yet. */ - VM_WARN_ON_ONCE(flags); - - freetype.migratetype =3D mt; - return freetype; -} - -static inline enum migratetype free_to_migratetype(freetype_t freetype) -{ - return freetype.migratetype; -} - -/* Convenience helper, return the freetype modified to have the migratetyp= e. */ -static inline freetype_t freetype_with_migrate(freetype_t freetype, - enum migratetype migratetype) -{ - return migrate_to_freetype(migratetype, freetype_flags(freetype)); -} - extern int page_group_by_mobility_disabled; =20 freetype_t get_pfnblock_freetype(const struct page *page, unsigned long pf= n); --=20 2.51.2