From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (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 9DAA43E3164 for ; Sun, 26 Jul 2026 22:23:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104623; cv=none; b=TSWwr1SkbXd3afR1YgL9Dto88VPJ1KD/Sg0BgcTb0QV83sxHr3DWme2yookZBmbC95ju4Mex2eH+FIr1pCv7AVT4o5pPf7flTN99fZuTepTy3wvl/1pG0cii5EU7z2u3gdfQFAKa/h23cqtpa5QVSYHuPc4KrjaiqqG9AuEA/D0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104623; c=relaxed/simple; bh=WgVMt2N881d1aVYJM4upKwkNWDi/Ix4SyKVzgk7SZy8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=N6qZpRjYX/x/jowPmT/VOWtX3K0RgXcPIzj/w/bOpRQsQTzTlqbDYl8WNqliMXnXUNX+sE6UFWCNnoh1kjvITxKlQ2tNOxbpi06E+5OwWKOAeoLEZtO2VKqy/uiGKQpLm5tpd4fLE8XVQKj0AUaSkK0QNSUlYg1qDvrrmnWc62U= 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=gah77y0a; arc=none smtp.client-ip=209.85.218.69 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="gah77y0a" Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c167e032f03so188994066b.1 for ; Sun, 26 Jul 2026 15:23:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785104620; x=1785709420; 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=gJ016WzmOmjAhyGBWYX+UBcW2OEU4+qqQQA/OudZHpY=; b=gah77y0aEukbsDkluh5qlM1RoOwrKEXG422tAYxHoXCCmTc8DgGzz0y3Rw9ojn7HpQ 3cqaeK1D2tizUfQA+oNkQmFoeejflRtyzng/44G8dJZ3Bi/o10VELL+R8YpUEsDl7E3Q p97NV1Rvn2xeMstIa7wKmyZefbDpomX+QdVcgIc2AmnC2dk0fFm3MzjwC9qw7BmJ9ERX 4w3OG8DbolttGEa2DVlCb59+R4Y1S7ZtSQ/CIzw2JfRRjvpzO3mmE5GWUwkVJTxD1NUv hYrJx1f7auweo0ReUC4I9j8ULODCpq0G8bMLQv/F22qOWMAXe03cY4zqdMncxKJ7u+8D G/yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785104620; x=1785709420; 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=gJ016WzmOmjAhyGBWYX+UBcW2OEU4+qqQQA/OudZHpY=; b=rdLNxA45PSVgcqk7vMaVnd6Ke7hS44CWycnjo5061TcehpiFXxeAwzgKdmoSUbq87E SD8RYjvrzizmtK4iX3paCGlSlApxaoa1J0mDee+yT6zkJKZ4FvCdDEBe5zu096/JVzWb bfHFFBzdf2DE2n7Z8NoPHw/73hUa1X5COuNBAdjp6bNsYBqZcF6DwBzQeYnUZoR56uY6 3lWQ+q2DW9X3cX7gOnbCQxL7i7NFstecwZy8HSeeqNg/9Tu+K1vcQMEDTs3r5ouHu5QW LP3hxtsJ0UF6aoTov5QAJPI+9FkfXOAR/Mmr+J8k5zbFnG3G/IgPntD2mo0Lhr5g4O8U jQnw== X-Forwarded-Encrypted: i=1; AHgh+RokGNndBOcL9EfCDDLtbzTHxeTAlocZKB6+PZTc4WOAL+udSd9hnu9zKcragH5Awc4zzdLHT4DpOO1K8cM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywmc0pctDALTMSs4lXoQLADbjJHep419kUSTSHfQ0Z1SzQp/bV+ Zp6CWBnMj0W85jmNK3p+f6ONqgb8y1ebUAouOgMZ8rpg7VjruDt8KPpaI1SNHjFhLx68JvGA62n 4VRoGoOS5ft+AyA== X-Received: from ejbce22.prod.google.com ([2002:a17:906:b256:b0:c16:114a:da6e]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:9622:b0:c17:40e5:3d7f with SMTP id a640c23a62f3a-c1f1f4237dbmr272268266b.56.1785104619456; Sun, 26 Jul 2026 15:23:39 -0700 (PDT) Date: Sun, 26 Jul 2026 22:22:47 +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-14-6f5729aa9832@google.com> Subject: [PATCH v3 14/26] mm: move migratetype definitions to freetype.h 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" 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. Acked-by: Vlastimil Babka (SUSE) 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 b56a029de4ea4..b16dcd58e184c 100644 --- a/include/linux/freetype.h +++ b/include/linux/freetype.h @@ -3,6 +3,66 @@ #define _LINUX_FREETYPE_H #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 = 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 = MIGRATE_CMA, +#else + __MIGRATE_TYPE_END = 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) == MIGRATE_CMA) +#else +# define is_migrate_cma(migratetype) false +#endif + +static inline bool is_migrate_movable(int mt) +{ + return is_migrate_cma(mt) || mt == 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; +} /* * A freetype is the identifier for a page freelist. This consists of a @@ -42,4 +102,28 @@ static inline bool freetypes_equal(freetype_t a, freetype_t b) return a.migratetype == b.migratetype; } +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 = 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 migratetype. */ +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 9fc77c4e70267..78455285dda7c 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) -enum migratetype { - MIGRATE_UNMOVABLE, - MIGRATE_MOVABLE, - MIGRATE_RECLAIMABLE, - MIGRATE_PCPTYPES, /* the number of types on the pcp lists */ - MIGRATE_HIGHATOMIC = 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 = MIGRATE_CMA, -#else - __MIGRATE_TYPE_END = 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) == MIGRATE_CMA) # define is_migrate_cma_page(_page) (get_pageblock_migratetype(_page) == 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_TYPES]; # define is_migrate_cma_folio(folio, pfn) \ (get_pfnblock_migratetype(&folio->page, pfn) == 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 -static inline bool is_migrate_movable(int mt) -{ - return is_migrate_cma(mt) || mt == 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 = 0; order < NR_PAGE_ORDERS; order++) \ for (unsigned int __idx = 0; \ @@ -185,30 +136,6 @@ static inline bool migratetype_is_mergeable(int mt) (list = &(zone)->free_area[order].free_list[__idx], 1); \ __idx++) -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 = 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 migratetype. */ -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; freetype_t get_pfnblock_freetype(const struct page *page, unsigned long pfn); -- 2.54.0