mm: Some cleanups for page allocator APIs
Subsystems (21)
v2 cover mm: Some cleanups for page allocator APIs
Some tweaks and cleanups for page allocator entrypoint and flags. This is motivated by preparation for __GFP_UNMAPPED [1] (which will probably become ALLOC_UNMAPPED in its next iteration), but all this is supposed to be an improvement to the codebase in its own right: unifying code paths, reducing API surface, and removing GFP flags.
[1] https://lore.kernel.org/all/[email protected]/
This started with unifying __alloc_frozen_pages[_nolock]_noprof() and expanded from there.
Unifying the nolock allocator entrypoint with the normal allocator entrypoint means adding an alloc_flags argument to the later (only exposed within mm/). This presents an opportunity to take advantage of that arg to remove some GFP flags, if we add that alloc_flags arg a bit more broadly to allocator entrypoints.
To distinguish between mm-internal and "public" allocator entrypoints, it makes sense to use the __ prefix. There are already some public APIs with that prefix. For *alloc_pages*, just removing those variants seems like a nice cleanup anyway, so do that. For get_free_pages, the "__" variant is the _only_ variant and it's very widely used, so it doesn't seem worthwhile to modify that. Therefore, scope this "__" change specifically to the *alloc_pages* API, which means we leave the *folio_alloc* API untouched too, even though that could probably be cleaned up if so desired.
Tested:
- KVM, mm, and BPF selftests in a QEMU VM
- kunit.py on x86_64
- For the ALLOC_NO_CODETAG bits I just booted a VM and read /proc/allocinfo. I confirmed that if I remove ALLOC_NO_CODETAG, the kernel crashes in early boot, so I was at least booting code that depends on this logic.
I used Google's internal version of Antigravity (AI coding harness) to do the repetitive bits, those commits are marked with Assisted-by, the rest is manual.
---
Changes in v2:
- Fixed up whitespace in nolock unification patch
- Introduced ALLOC_DEFAULT to replace literal 0 for alloc_flags
- All other patches are new
- Link to v1: https://patch.msgid.link/[email protected]
---
Brendan Jackman (13):
mm/page_alloc: rename ALLOC_TRYLOCK -> ALLOC_NOLOCK mm/page_alloc: some renames to clarify alloc_flags scopes mm/page_alloc: unify __alloc_frozen_pages[_nolock]_noprof() mm/page_alloc: relax GFP WARN in nolock allocs perf/x86/intel: Use higher-level allocator
KVM: VMX: Use higher-level allocator
x86/virt: Use higher-level allocator
sgi-xp: Use higher-level allocator
net/funeth: Switch to higher-level allocator
mm: Remove __alloc_pages_node()
alloc_tag: Move to mm/
mm: Move __alloc_pages() to mm/internal.h
mm: remove __GFP_NO_CODETAG
Documentation/admin-guide/cgroup-v1/cpusets.rst | 2 +-
Documentation/admin-guide/mm/transhuge.rst | 2 +-
MAINTAINERS | 2 +-
arch/x86/events/intel/ds.c | 6 +-
arch/x86/kvm/vmx/vmx.c | 2 +-
arch/x86/virt/hw.c | 2 +-
drivers/misc/sgi-xp/xpc_uv.c | 2 +-
drivers/net/ethernet/fungible/funeth/funeth_rx.c | 2 +-
include/linux/gfp.h | 28 +--
lib/Makefile | 1 -
mm/Makefile | 1 +
{lib => mm}/alloc_tag.c | 18 +-
mm/compaction.c | 4 +-
mm/hugetlb.c | 3 +-
mm/internal.h | 20 +-
mm/mempolicy.c | 10 +-
mm/page_alloc.c | 254 +++++++++++++----------
mm/page_frag_cache.c | 4 +-
mm/slub.c | 6 +-
19 files changed, 193 insertions(+), 176 deletions(-)---
base-commit: cbe5256a15fc26f592efb037e528da54b2139ee5
change-id: 20260617-alloc-trylock-14ad37dab337
Best regards,
Signature · 1 line
Brendan Jackman <[email protected]>
PATCH v2 1/13 mm/page_alloc: rename ALLOC_TRYLOCK -> ALLOC_NOLOCK
It's confusing that the function is called "nolock" but the flag is called "trylock", align them.
The function's terminology is more visible and has more mindshare so use that.
--- mm/internal.h | 2 +- mm/page_alloc.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)
mm/internal.h +1 -1
@@ -1475,7 +1475,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,#define ALLOC_NOFRAGMENT 0x0#endif #define ALLOC_HIGHATOMIC 0x200/* Allows access to MIGRATE_HIGHATOMIC */ -#define ALLOC_TRYLOCK 0x400/* Only use spin_trylock in allocation path */ +#define ALLOC_NOLOCK 0x400/* Only use spin_trylock in allocation path */ #define ALLOC_KSWAPD 0x800/* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */ /* Flags that allow allocations below the min watermark. */
mm/page_alloc.c +5 -5
@@ -2528,7 +2528,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,unsigned long flags;int i; -if (unlikely (alloc_flags &ALLOC_TRYLOCK )) { +if (unlikely (alloc_flags &ALLOC_NOLOCK )) {if (!spin_trylock_irqsave (&zone->lock, flags))return 0 ; }else {
@@ -3216,7 +3216,7 @@ struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone, do { page = NULL; - if (unlikely(alloc_flags & ALLOC_TRYLOCK)) { + if (unlikely(alloc_flags & ALLOC_NOLOCK)) { if (!spin_trylock_irqsave(&zone->lock, flags)) return NULL; } else {
@@ -5042,7 +5042,7 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,* Don't invoke should_fail logic, since it may call * get_random_u32() and printk() which need to spin_lock. */ -if (!(*alloc_flags &ALLOC_TRYLOCK ) && +if (!(*alloc_flags &ALLOC_NOLOCK ) &&should_fail_alloc_page (gfp_mask, order))return false;
@@ -7786,7 +7786,7 @@ static bool cond_accept_memory(struct zone *zone, unsigned int order,return false;/* Bailout, since try_to_accept_memory_one() needs to take a lock */ -if (alloc_flags &ALLOC_TRYLOCK ) +if (alloc_flags &ALLOC_NOLOCK )return false; wmark =promo_wmark_pages (zone);
@@ -7878,7 +7878,7 @@ struct page *alloc_frozen_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned*/ gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC | __GFP_COMP | gfp_flags; -unsigned int alloc_flags =ALLOC_TRYLOCK ; +unsigned int alloc_flags =ALLOC_NOLOCK ;struct alloc_context ac = { };struct page *page;
Signature · 1 line
2.54.0
Re: [PATCH v2 01/13] mm/page_alloc: rename ALLOC_TRYLOCK -> ALLOC_NOLOCK
Quoted 9 lines · Brendan Jackman
It's confusing that the function is called "nolock" but the flag is called "trylock", align them.
The function's terminology is more visible and has more mindshare so use that.
That comment for ALLOC_NOLOCK about only using spin_trylock in the allocation path could be rewritten to say that no locking or spinning is allowed but it's a minor detail.
Quoted 71 lines
--- mm/internal.h | 2 +- mm/page_alloc.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-)mm/internal.h +1
-1@@ -1475,7 +1475,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,#define ALLOC_NOFRAGMENT 0x0#endif #define ALLOC_HIGHATOMIC 0x200/* Allows access to MIGRATE_HIGHATOMIC */ -#define ALLOC_TRYLOCK 0x400/* Only use spin_trylock in allocation path */ +#define ALLOC_NOLOCK 0x400/* Only use spin_trylock in allocation path */ #define ALLOC_KSWAPD 0x800/* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */ /* Flags that allow allocations below the min watermark. */ mm/page_alloc.c +5
-6@@ -2528,7 +2528,7 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order,unsigned long flags;int i; -if (unlikely (alloc_flags &ALLOC_TRYLOCK )) { +if (unlikely (alloc_flags &ALLOC_NOLOCK )) {if (!spin_trylock_irqsave (&zone->lock, flags))return 0 ; }else {@@ -3216,7 +3216,7 @@ struct page *rmqueue_buddy(struct zone *preferred_zone, struct zone *zone, do { page = NULL; - if (unlikely(alloc_flags & ALLOC_TRYLOCK)) { + if (unlikely(alloc_flags & ALLOC_NOLOCK)) { if (!spin_trylock_irqsave(&zone->lock, flags)) return NULL; } else {@@ -5042,7 +5042,7 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,* Don't invoke should_fail logic, since it may call * get_random_u32() and printk() which need to spin_lock. */ -if (!(*alloc_flags &ALLOC_TRYLOCK ) && +if (!(*alloc_flags &ALLOC_NOLOCK ) &&should_fail_alloc_page (gfp_mask, order))return false;@@ -7786,7 +7786,7 @@ static bool cond_accept_memory(struct zone *zone, unsigned int order,return false;/* Bailout, since try_to_accept_memory_one() needs to take a lock */ -if (alloc_flags &ALLOC_TRYLOCK ) +if (alloc_flags &ALLOC_NOLOCK )return false; wmark =promo_wmark_pages (zone);@@ -7878,7 +7878,7 @@ struct page *alloc_frozen_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned*/ gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC | __GFP_COMP | gfp_flags; -unsigned int alloc_flags =ALLOC_TRYLOCK ; +unsigned int alloc_flags =ALLOC_NOLOCK ;struct alloc_context ac = { };struct page *page; --2.54.0
Re: [PATCH v2 01/13] mm/page_alloc: rename ALLOC_TRYLOCK -> ALLOC_NOLOCK
In reply to Brendan JackmanQuoted 9 lines · Brendan Jackman
It's confusing that the function is called "nolock" but the flag is called "trylock", align them.
The function's terminology is more visible and has more mindshare so use that.
Suggested-by "Vlastimil Babka (SUSE)" <[email protected]>Signed-off-by Brendan Jackman <[email protected]>---
Signature · 2 lines
Cheers, Harry / Hyeonggon
PATCH v2 2/13 mm/page_alloc: some renames to clarify alloc_flags scopes
In reply to Brendan JackmanIt's pretty confusing that:
- The slowpath and fastpath have a totally distinct set of alloc_flags.
- gfp_to_alloc_flags() sounds generic but it only influences the slowpath.
- prepare_alloc_pages() is generic in that it sets up the alloc_context, but the alloc_flags it generates are only used for the fastpath.
Rename some variables to highlight which alloc_flags are fastpath-specific. Rename gfp_to_alloc_flags() to highlight that it's slowpath-specific.
gfp_to_alloc_flags_cma()'s current name is actually fine, but rename it anyway, just for consistency.
--- mm/page_alloc.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
mm/page_alloc.c +14 -14
@@ -3771,8 +3771,8 @@ alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask) }/* Must be called after current_gfp_context() which can change gfp_mask */ -static inline unsigned int gfp_to_alloc_flags_cma (gfp_t gfp_mask, -unsigned int alloc_flags) +static inline unsigned int cma_alloc_flags (gfp_t gfp_mask, +unsigned int alloc_flags) {#ifdef CONFIG_CMA if (gfp_migratetype (gfp_mask) ==MIGRATE_MOVABLE )
@@ -4471,7 +4471,7 @@ static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask, }static inline unsigned int -gfp_to_alloc_flags (gfp_t gfp_mask,unsigned int order) +slowpath_alloc_flags (gfp_t gfp_mask,unsigned int order) {unsigned int alloc_flags =ALLOC_WMARK_MIN |ALLOC_CPUSET ;
@@ -4508,7 +4508,7 @@ gfp_to_alloc_flags(gfp_t gfp_mask, unsigned int order) }else if (unlikely (rt_or_dl_task (current)) &&in_task ()) alloc_flags |=ALLOC_MIN_RESERVE ; - alloc_flags =gfp_to_alloc_flags_cma (gfp_mask, alloc_flags); + alloc_flags =cma_alloc_flags (gfp_mask, alloc_flags);if (defrag_mode) alloc_flags |=ALLOC_NOFRAGMENT ;
@@ -4774,7 +4774,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,* kswapd needs to be woken up, and to avoid the cost of setting up * alloc_flags precisely. So we do that now. */ - alloc_flags =gfp_to_alloc_flags (gfp_mask, order); + alloc_flags =slowpath_alloc_flags (gfp_mask, order);/* * We need to recalculate the starting point for the zonelist iterator
@@ -4815,7 +4815,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, reserve_flags =__gfp_pfmemalloc_flags (gfp_mask);if (reserve_flags) - alloc_flags =gfp_to_alloc_flags_cma (gfp_mask, reserve_flags) | + alloc_flags =cma_alloc_flags (gfp_mask, reserve_flags) | (alloc_flags &ALLOC_KSWAPD );/*
@@ -5017,7 +5017,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,static inline bool prepare_alloc_pages (gfp_t gfp_mask,unsigned int order,int preferred_nid,nodemask_t *nodemask,struct alloc_context *ac,gfp_t *alloc_gfp, -unsigned int *alloc_flags) +unsigned int *fastpath_alloc_flags) { ac->highest_zoneidx =gfp_zone (gfp_mask); ac->zonelist =node_zonelist (preferred_nid, gfp_mask);
@@ -5033,7 +5033,7 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,if (in_task () && !ac->nodemask) ac->nodemask = &cpuset_current_mems_allowed;else - *alloc_flags |=ALLOC_CPUSET ; + *fastpath_alloc_flags |=ALLOC_CPUSET ; }might_alloc (gfp_mask);
@@ -5042,11 +5042,11 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,* Don't invoke should_fail logic, since it may call * get_random_u32() and printk() which need to spin_lock. */ -if (!(*alloc_flags &ALLOC_NOLOCK ) && +if (!(*fastpath_alloc_flags &ALLOC_NOLOCK ) &&should_fail_alloc_page (gfp_mask, order))return false; - *alloc_flags =gfp_to_alloc_flags_cma (gfp_mask, *alloc_flags); + *fastpath_alloc_flags =cma_alloc_flags (gfp_mask, *fastpath_alloc_flags);/* Dirty zone balancing only done in the fast path */ ac->spread_dirty_pages = (gfp_mask & __GFP_WRITE);
@@ -5260,7 +5260,7 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, int preferred_nid, nodemask_t *nodemask) { struct page *page; -unsigned int alloc_flags =ALLOC_WMARK_LOW ; +unsigned int fastpath_alloc_flags =ALLOC_WMARK_LOW ;gfp_t alloc_gfp;/* The gfp_t that was actually used for allocation */ struct alloc_context ac = { };
@@ -5282,17 +5282,17 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, gfp =current_gfp_context (gfp); alloc_gfp = gfp;if (!prepare_alloc_pages (gfp, order, preferred_nid, nodemask, &ac, - &alloc_gfp, &alloc_flags)) + &alloc_gfp, &fastpath_alloc_flags))return NULL ;/* * Forbid the first pass from falling back to types that fragment * memory until all local zones are considered. */ - alloc_flags |=alloc_flags_nofragment (zonelist_zone (ac.preferred_zoneref), gfp); + fastpath_alloc_flags |=alloc_flags_nofragment (zonelist_zone (ac.preferred_zoneref), gfp);/* First allocation attempt */ - page =get_page_from_freelist (alloc_gfp, order, alloc_flags, &ac); + page =get_page_from_freelist (alloc_gfp, order, fastpath_alloc_flags, &ac);if (likely (page)) goto out;
Signature · 1 line
2.54.0
Suren Baghdasaryan
maintainerRe: [PATCH v2 02/13] mm/page_alloc: some renames to clarify alloc_flags scopes
Quoted 11 lines · Brendan Jackman
It's pretty confusing that:
- The slowpath and fastpath have a totally distinct set of
alloc_flags.-
gfp_to_alloc_flags()sounds generic but it only influences the slowpath.-
prepare_alloc_pages()is generic in that it sets up thealloc_context, but thealloc_flagsit generates are only used for the fastpath.
I understand you want to clarify the usage but this particular point seems to be an implementation detail. IOW, if tomorrow __alloc_frozen_pages_noprof() is changed to use alloc_flags when calling __alloc_pages_slowpath(), would we be renaming it back? So, I would suggest keeping alloc_flags as is in prepare_alloc_pages() and its callers. The rest LGTM.
Quoted 130 lines
Rename some variables to highlight which
alloc_flagsare fastpath-specific. Renamegfp_to_alloc_flags()to highlight that it's slowpath-specific.gfp_to_alloc_flags_cma()'s current name is actually fine, but rename it anyway, just for consistency.
Signed-off-by Brendan Jackman <[email protected]>--- mm/page_alloc.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)mm/page_alloc.c +14
-15@@ -3771,8 +3771,8 @@ alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask) }/* Must be called after current_gfp_context() which can change gfp_mask */ -static inline unsigned int gfp_to_alloc_flags_cma (gfp_t gfp_mask, -unsigned int alloc_flags) +static inline unsigned int cma_alloc_flags (gfp_t gfp_mask, +unsigned int alloc_flags) {#ifdef CONFIG_CMA if (gfp_migratetype (gfp_mask) ==MIGRATE_MOVABLE )@@ -4471,7 +4471,7 @@ static void wake_all_kswapds(unsigned int order, gfp_t gfp_mask, }static inline unsigned int -gfp_to_alloc_flags (gfp_t gfp_mask,unsigned int order) +slowpath_alloc_flags (gfp_t gfp_mask,unsigned int order) {unsigned int alloc_flags =ALLOC_WMARK_MIN |ALLOC_CPUSET ;@@ -4508,7 +4508,7 @@ gfp_to_alloc_flags(gfp_t gfp_mask, unsigned int order) }else if (unlikely (rt_or_dl_task (current)) &&in_task ()) alloc_flags |=ALLOC_MIN_RESERVE ; - alloc_flags =gfp_to_alloc_flags_cma (gfp_mask, alloc_flags); + alloc_flags =cma_alloc_flags (gfp_mask, alloc_flags);if (defrag_mode) alloc_flags |=ALLOC_NOFRAGMENT ;@@ -4774,7 +4774,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,* kswapd needs to be woken up, and to avoid the cost of setting up * alloc_flags precisely. So we do that now. */ - alloc_flags =gfp_to_alloc_flags (gfp_mask, order); + alloc_flags =slowpath_alloc_flags (gfp_mask, order);/* * We need to recalculate the starting point for the zonelist iterator @@ -4815,7 +4815,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, reserve_flags =__gfp_pfmemalloc_flags (gfp_mask);if (reserve_flags) - alloc_flags =gfp_to_alloc_flags_cma (gfp_mask, reserve_flags) | + alloc_flags =cma_alloc_flags (gfp_mask, reserve_flags) | (alloc_flags &ALLOC_KSWAPD );/* @@ -5017,7 +5017,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,static inline bool prepare_alloc_pages (gfp_t gfp_mask,unsigned int order,int preferred_nid,nodemask_t *nodemask,struct alloc_context *ac,gfp_t *alloc_gfp, -unsigned int *alloc_flags) +unsigned int *fastpath_alloc_flags) { ac->highest_zoneidx =gfp_zone (gfp_mask); ac->zonelist =node_zonelist (preferred_nid, gfp_mask);@@ -5033,7 +5033,7 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,if (in_task () && !ac->nodemask) ac->nodemask = &cpuset_current_mems_allowed;else - *alloc_flags |=ALLOC_CPUSET ; + *fastpath_alloc_flags |=ALLOC_CPUSET ; }might_alloc (gfp_mask);@@ -5042,11 +5042,11 @@ static inline bool prepare_alloc_pages(gfp_t gfp_mask, unsigned int order,* Don't invoke should_fail logic, since it may call * get_random_u32() and printk() which need to spin_lock. */ -if (!(*alloc_flags &ALLOC_NOLOCK ) && +if (!(*fastpath_alloc_flags &ALLOC_NOLOCK ) &&should_fail_alloc_page (gfp_mask, order))return false; - *alloc_flags =gfp_to_alloc_flags_cma (gfp_mask, *alloc_flags); + *fastpath_alloc_flags =cma_alloc_flags (gfp_mask, *fastpath_alloc_flags);/* Dirty zone balancing only done in the fast path */ ac->spread_dirty_pages = (gfp_mask & __GFP_WRITE);@@ -5260,7 +5260,7 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, int preferred_nid, nodemask_t *nodemask) { struct page *page; -unsigned int alloc_flags =ALLOC_WMARK_LOW ; +unsigned int fastpath_alloc_flags =ALLOC_WMARK_LOW ;gfp_t alloc_gfp;/* The gfp_t that was actually used for allocation */ struct alloc_context ac = { };@@ -5282,17 +5282,17 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, gfp =current_gfp_context (gfp); alloc_gfp = gfp;if (!prepare_alloc_pages (gfp, order, preferred_nid, nodemask, &ac, - &alloc_gfp, &alloc_flags)) + &alloc_gfp, &fastpath_alloc_flags))return NULL ;/* * Forbid the first pass from falling back to types that fragment * memory until all local zones are considered. */ - alloc_flags |=alloc_flags_nofragment (zonelist_zone (ac.preferred_zoneref), gfp); + fastpath_alloc_flags |=alloc_flags_nofragment (zonelist_zone (ac.preferred_zoneref), gfp);/* First allocation attempt */ - page =get_page_from_freelist (alloc_gfp, order, alloc_flags, &ac); + page =get_page_from_freelist (alloc_gfp, order, fastpath_alloc_flags, &ac);if (likely (page)) goto out; --2.54.0
Brendan Jackman
reviewerRe: [PATCH v2 02/13] mm/page_alloc: some renames to clarify alloc_flags scopes
Quoted 13 lines · Suren Baghdasaryan
Quoted 11 lines · Brendan Jackman
It's pretty confusing that:
- The slowpath and fastpath have a totally distinct set of
alloc_flags.-
gfp_to_alloc_flags()sounds generic but it only influences the slowpath.-
prepare_alloc_pages()is generic in that it sets up thealloc_context, but thealloc_flagsit generates are only used for the fastpath.
Quoted 5 lines
I understand you want to clarify the usage but this particular point seems to be an implementation detail. IOW, if tomorrow
__alloc_frozen_pages_noprof()is changed to usealloc_flagswhen calling__alloc_pages_slowpath(), would we be renaming it back? So, I would suggest keepingalloc_flagsas is inprepare_alloc_pages()
I would say yes, we should rename it even though it might mean having to rename it back later. IMO it's very useful to make it clear to the reader that they also need to look elsewhere to find the slowpath flag logic, without them having to notice this rather odd detail of __alloc_frozen_pages_noprof().
But, yeah I guess prepare_alloc_pages() doesn't really care that its caller is only using the result for the fastpath so I could see the rationale for keeping the arg as alloc_flags...
Quoted 1 line
and its callers.
... but for it's caller I really do think the rename is necessary and doesn't really have any downside? Especially once alloc_context gets an alloc_flags field as it does later in the series.
Quoted 1 line
The rest LGTM.
Thanks as always, I appreciate the review.
Vlastimil Babka (SUSE)
maintainerRe: [PATCH v2 02/13] mm/page_alloc: some renames to clarify alloc_flags scopes
Quoted 30 lines · Brendan Jackman
Quoted 13 lines · Suren Baghdasaryan
Quoted 11 lines · Brendan Jackman
It's pretty confusing that:
- The slowpath and fastpath have a totally distinct set of
alloc_flags.-
gfp_to_alloc_flags()sounds generic but it only influences the slowpath.-
prepare_alloc_pages()is generic in that it sets up thealloc_context, but thealloc_flagsit generates are only used for the fastpath.Quoted 5 lines
I understand you want to clarify the usage but this particular point seems to be an implementation detail. IOW, if tomorrow
__alloc_frozen_pages_noprof()is changed to usealloc_flagswhen calling__alloc_pages_slowpath(), would we be renaming it back? So, I would suggest keepingalloc_flagsas is inprepare_alloc_pages()I would say yes, we should rename it even though it might mean having to rename it back later. IMO it's very useful to make it clear to the reader that they also need to look elsewhere to find the slowpath flag logic, without them having to notice this rather odd detail of
__alloc_frozen_pages_noprof().But, yeah I guess
prepare_alloc_pages()doesn't really care that its caller is only using the result for the fastpath so I could see the rationale for keeping the arg asalloc_flags...
Quoted 5 lines
Quoted 1 line
and its callers.
... but for it's caller I really do think the rename is necessary and doesn't really have any downside? Especially once
alloc_contextgets analloc_flagsfield as it does later in the series.
I don't mind either of the renames. It's all page_alloc.c internal anyway.
Quoted 3 lines
Quoted 1 line
The rest LGTM.
Thanks as always, I appreciate the review.
PATCH v2 3/13 mm/page_alloc: unify __alloc_frozen_pages[_nolock]_noprof()
In reply to Brendan JackmanCurrently the core allocator code is controlled by ALLOC_NOLOCK, but the main entry point function is significantly different from the normal __alloc_frozen_pages_nolock(), this is tiring when reading the code.
Plumb the ALLOC_NOLOCK control one layer up in the call stack: create an alloc_flags argument to __alloc_frozen_pages_nolock() (which is only exposed to mm/) and then turn the nolock variant into a thin wrapper that just sets that flag (as well as handling NUMA_NO_NODE, similar to how some of the wrappers in gfp.h do).
Rationale that this doesn't change anything:
1. Simple bits: A bunch of the nolock-specific handling is just moved to the new alloc_order_allowed(), alloc_trylock_allowed() and gfp_trylock.
2. __alloc_frozen_pages_noprof() has some extra logic that wasn't previously in the nolock variant:
a. Application of gfp_allowed_mask; this only affects early boot, and
only flags that affect the slowpath get changed here.
b. Application of current_gfp_context() - also only affects the
slowpath
3. The slowpath itself: this is now just explicitly skipped under !ALLOC_TRYLOCK.
Ulterior motive: adding an alloc_flags arg to the allocator's mm-internal entrypoint can later be used to do more allocation customisation without needing to create new GFP flags.
While adding this flag to a bunch of places, create ALLOC_DEFAULT to avoid a mysterious literal 0 in most places. alloc_frozen_pages_noprof() is defined above the alloc flags so just leave that as a slightly messy exception instead of trying to fully reorder mm/internal.h for that one case.
No functional change intended.
--- mm/hugetlb.c | 3 +- mm/internal.h | 8 ++- mm/mempolicy.c | 10 ++-- mm/page_alloc.c | 178 +++++++++++++++++++++++++++++--------------------------- mm/slub.c | 6 +- 5 files changed, 110 insertions(+), 95 deletions(-)
mm/hugetlb.c +2 -1
@@ -1806,7 +1806,8 @@ static struct folio *alloc_buddy_frozen_folio(int order, gfp_t gfp_mask,if (alloc_try_hard) gfp_mask |= __GFP_RETRY_MAYFAIL; - folio = (struct folio *)__alloc_frozen_pages (gfp_mask, order, nid, nmask); + folio = (struct folio *)__alloc_frozen_pages (gfp_mask, order, nid, nmask, +ALLOC_DEFAULT );/* * If we did not specify __GFP_RETRY_MAYFAIL, but still got a
mm/internal.h +6 -2
@@ -913,7 +913,7 @@ extern bool free_pages_prepare(struct page *page, unsigned int order);extern int user_min_free_kbytes;struct page *__alloc_frozen_pages_noprof (gfp_t ,unsigned int order,int nid, -nodemask_t *); +nodemask_t *,unsigned int alloc_flags);#define __alloc_frozen_pages (...) \ alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__))void free_frozen_pages (struct page *page,unsigned int order);
@@ -924,7 +924,8 @@ struct page *alloc_frozen_pages_noprof(gfp_t, unsigned int order);#else static inline struct page *alloc_frozen_pages_noprof (gfp_t gfp,unsigned int order) { -return __alloc_frozen_pages_noprof (gfp, order,numa_node_id (),NULL ); +return __alloc_frozen_pages_noprof (gfp, order,numa_node_id (),NULL , +0 /* ALLOC_DEFAULT */ ); }#endif
@@ -1440,6 +1441,9 @@ extern void set_pageblock_order(void);unsigned long reclaim_pages (struct list_head *folio_list);unsigned int reclaim_clean_pages_from_list (struct zone *zone,struct list_head *folio_list); + + +#define ALLOC_DEFAULT 0/* The ALLOC_WMARK bits are used as an index to zone->watermark */ #define ALLOC_WMARK_MIN WMARK_MIN#define ALLOC_WMARK_LOW WMARK_LOW
mm/mempolicy.c +6 -4
@@ -2425,9 +2425,11 @@ static struct page *alloc_pages_preferred_many(gfp_t gfp, unsigned int order,*/ preferred_gfp = gfp | __GFP_NOWARN; preferred_gfp &= ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); - page =__alloc_frozen_pages_noprof (preferred_gfp, order, nid, nodemask); + page =__alloc_frozen_pages_noprof (preferred_gfp, order, nid, nodemask, +ALLOC_DEFAULT );if (!page) - page =__alloc_frozen_pages_noprof (gfp, order, nid,NULL ); + page =__alloc_frozen_pages_noprof (gfp, order, nid,NULL , +ALLOC_DEFAULT );return page; }
@@ -2475,7 +2477,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order,*/ page =__alloc_frozen_pages_noprof ( gfp | __GFP_THISNODE | __GFP_NORETRY, order, - nid,NULL ); + nid,NULL ,ALLOC_DEFAULT );if (page || !(gfp & __GFP_DIRECT_RECLAIM))return page;/*
@@ -2487,7 +2489,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order, } } - page =__alloc_frozen_pages_noprof (gfp, order, nid, nodemask); + page =__alloc_frozen_pages_noprof (gfp, order, nid, nodemask,ALLOC_DEFAULT );if (unlikely (pol->mode ==MPOL_INTERLEAVE || pol->mode ==MPOL_WEIGHTED_INTERLEAVE ) && page) {
mm/page_alloc.c +92 -86
226 lines not on this page · raw message
mm/slub.c +4 -2
@@ -3275,7 +3275,8 @@ static inline struct slab *alloc_slab_page(gfp_t flags, int node,else if (node ==NUMA_NO_NODE ) page =alloc_frozen_pages (flags, order);else - page =__alloc_frozen_pages (flags, order, node,NULL ); + page =__alloc_frozen_pages (flags, order, node,NULL , +ALLOC_DEFAULT );if (!page)return NULL ;
@@ -5236,7 +5237,8 @@ static void *___kmalloc_large_node(size_t size, gfp_t flags, int node)if (node ==NUMA_NO_NODE ) page =alloc_frozen_pages_noprof (flags, order);else - page =__alloc_frozen_pages_noprof (flags, order, node,NULL ); + page =__alloc_frozen_pages_noprof (flags, order, node,NULL , +ALLOC_DEFAULT );if (page) { ptr =page_address (page);
Signature · 1 line
2.54.0
Suren Baghdasaryan
maintainerRe: [PATCH v2 03/13] mm/page_alloc: unify __alloc_frozen_pages[_nolock]_noprof()
Quoted 26 lines · Brendan Jackman
Currently the core allocator code is controlled by
ALLOC_NOLOCK, but the main entry point function is significantly different from the normal__alloc_frozen_pages_nolock(), this is tiring when reading the code.Plumb the
ALLOC_NOLOCKcontrol one layer up in the call stack: create analloc_flagsargument to__alloc_frozen_pages_nolock()(which is only exposed tomm/) and then turn the nolock variant into a thin wrapper that just sets that flag (as well as handlingNUMA_NO_NODE, similar to how some of the wrappers ingfp.hdo).Rationale that this doesn't change anything:
1. Simple bits: A bunch of the nolock-specific handling is just moved to the new
alloc_order_allowed(),alloc_trylock_allowed()andgfp_trylock.2.
__alloc_frozen_pages_noprof()has some extra logic that wasn't previously in the nolock variant:a. Application of
gfp_allowed_mask; this only affects early boot, and
only flags that affect the slowpath get changed here.b. Application of
current_gfp_context()- also only affects the
slowpath
Quoted 6 lines
3. The slowpath itself: this is now just explicitly skipped under !ALLOC_TRYLOCK.
Ulterior motive: adding an
alloc_flagsarg to the allocator's mm-internal entrypoint can later be used to do more allocation customisation without needing to create new GFP flags.
Looks like a nice overall cleanup.
Quoted 6 lines
While adding this flag to a bunch of places, create
ALLOC_DEFAULTto avoid a mysterious literal 0 in most places.alloc_frozen_pages_noprof()is defined above the alloc flags so just leave that as a slightly messy exception instead of trying to fully reordermm/internal.hfor that one case.
Moving the whole alloc_frozen_pages() block down seems simple enough and would avoid special-casing this.
Quoted 176 lines
No functional change intended.
Signed-off-by Brendan Jackman <[email protected]>--- mm/hugetlb.c | 3 +- mm/internal.h | 8 ++- mm/mempolicy.c | 10 ++-- mm/page_alloc.c | 178 +++++++++++++++++++++++++++++--------------------------- mm/slub.c | 6 +- 5 files changed, 110 insertions(+), 95 deletions(-)mm/hugetlb.c +2
-1@@ -1806,7 +1806,8 @@ static struct folio *alloc_buddy_frozen_folio(int order, gfp_t gfp_mask,if (alloc_try_hard) gfp_mask |= __GFP_RETRY_MAYFAIL; - folio = (struct folio *)__alloc_frozen_pages (gfp_mask, order, nid, nmask); + folio = (struct folio *)__alloc_frozen_pages (gfp_mask, order, nid, nmask, +ALLOC_DEFAULT );/* * If we did not specify __GFP_RETRY_MAYFAIL, but still got a mm/internal.h +6
-2@@ -913,7 +913,7 @@ extern bool free_pages_prepare(struct page *page, unsigned int order);extern int user_min_free_kbytes;struct page *__alloc_frozen_pages_noprof (gfp_t ,unsigned int order,int nid, -nodemask_t *); +nodemask_t *,unsigned int alloc_flags);#define __alloc_frozen_pages (...) \ alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__))void free_frozen_pages (struct page *page,unsigned int order);@@ -924,7 +924,8 @@ struct page *alloc_frozen_pages_noprof(gfp_t, unsigned int order);#else static inline struct page *alloc_frozen_pages_noprof (gfp_t gfp,unsigned int order) { -return __alloc_frozen_pages_noprof (gfp, order,numa_node_id (),NULL ); +return __alloc_frozen_pages_noprof (gfp, order,numa_node_id (),NULL , +0 /* ALLOC_DEFAULT */ ); }#endif @@ -1440,6 +1441,9 @@ extern void set_pageblock_order(void);unsigned long reclaim_pages (struct list_head *folio_list);unsigned int reclaim_clean_pages_from_list (struct zone *zone,struct list_head *folio_list); + + +#define ALLOC_DEFAULT 0/* The ALLOC_WMARK bits are used as an index to zone->watermark */ #define ALLOC_WMARK_MIN WMARK_MIN#define ALLOC_WMARK_LOW WMARK_LOWmm/mempolicy.c +6
-4@@ -2425,9 +2425,11 @@ static struct page *alloc_pages_preferred_many(gfp_t gfp, unsigned int order,*/ preferred_gfp = gfp | __GFP_NOWARN; preferred_gfp &= ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL); - page =__alloc_frozen_pages_noprof (preferred_gfp, order, nid, nodemask); + page =__alloc_frozen_pages_noprof (preferred_gfp, order, nid, nodemask, +ALLOC_DEFAULT );if (!page) - page =__alloc_frozen_pages_noprof (gfp, order, nid,NULL ); + page =__alloc_frozen_pages_noprof (gfp, order, nid,NULL , +ALLOC_DEFAULT );return page; }@@ -2475,7 +2477,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order,*/ page =__alloc_frozen_pages_noprof ( gfp | __GFP_THISNODE | __GFP_NORETRY, order, - nid,NULL ); + nid,NULL ,ALLOC_DEFAULT );if (page || !(gfp & __GFP_DIRECT_RECLAIM))return page;/* @@ -2487,7 +2489,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order, } } - page =__alloc_frozen_pages_noprof (gfp, order, nid, nodemask); + page =__alloc_frozen_pages_noprof (gfp, order, nid, nodemask,ALLOC_DEFAULT );if (unlikely (pol->mode ==MPOL_INTERLEAVE || pol->mode ==MPOL_WEIGHTED_INTERLEAVE ) && page) {mm/page_alloc.c +49
-11@@ -5204,7 +5204,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid, } nr_account++; -prep_new_page (page,0 , gfp,0 ); +prep_new_page (page,0 , gfp,ALLOC_DEFAULT );set_page_refcounted (page); page_array[nr_populated++] = page; }@@ -5253,24 +5253,98 @@ void free_pages_bulk(struct page **page_array, unsigned long nr_pages) } } -/* -* This is the 'heart' of the zoned buddy allocator. -*/ -struct page *__alloc_frozen_pages_noprof (gfp_t gfp,unsigned int order, -int preferred_nid,nodemask_t *nodemask) +static inline bool alloc_order_allowed (gfp_t gfp,unsigned int order, +unsigned int alloc_flags) { -struct page *page; -unsigned int fastpath_alloc_flags =ALLOC_WMARK_LOW ; -gfp_t alloc_gfp;/* The gfp_t that was actually used for allocation */ -struct alloc_context ac = { }; +if (alloc_flags &ALLOC_NOLOCK ) +return pcp_allowed_order (order);/* * There are several places where we assume that the order value is sane * so bail out early if the request is out of bound. */ -if (WARN_ON_ONCE_GFP (order >MAX_PAGE_ORDER , gfp)) +return !(WARN_ON_ONCE_GFP (order >MAX_PAGE_ORDER , gfp)); +} + +static inline bool alloc_trylock_allowed (void ) +{ +/* +* In PREEMPT_RT spin_trylock() will call raw_spin_lock() which is +* unsafe in NMI. If spin_trylock() is called from hard IRQ the current +* task may be waiting for one rt_spin_lock, but rt_spin_trylock() will +* mark the task as the owner of another rt_spin_lock which will +* confuse PI logic, so return immediately if called from hard IRQ or +* NMI. +* +* Note, irqs_disabled() case is ok. This function can be called +* from raw_spin_lock_irqsave region. +*/ +if (IS_ENABLED (CONFIG_PREEMPT_RT ) && (in_nmi () ||in_hardirq ())) +return false; + +/* On UP, spin_trylock() always succeeds even when it is locked */ +if (!IS_ENABLED (CONFIG_SMP ) &&in_nmi ()) +return false; + +/* Bailout, since _deferred_grow_zone() needs to take a lock */ +if (deferred_pages_enabled ()) +return false; + +return true; +} + +/* +* GFP flags to set for ALLOC_NOLOCK i.e. alloc_pages_nolock(). +* +* Do not specify __GFP_DIRECT_RECLAIM, since direct claim is not allowed. +* Do not specify __GFP_KSWAPD_RECLAIM either, since wake up of kswapd +* is not safe in arbitrary context. +* +* These two are the conditions for gfpflags_allow_spinning() being true. +* +* Specify __GFP_NOWARN since failing alloc_pages_nolock() is not a reason +* to warn. Also warn would trigger printk() which is unsafe from +* various contexts. We cannot use printk_deferred_enter() to mitigate, +* since the running context is unknown. +*
mm/page_alloc.c void free_pages_bulk(struct page **page_array, unsigned long nr_pages) · line 5319
Quoted 10 lines
mm/page_alloc.c +10
-0+* Specify __GFP_ZERO to make sure that call to kmsan_alloc_page() below +* is safe in any context. Also zeroing the page is mandatory for +* BPF use cases. +* +* Though __GFP_NOMEMALLOC is not checked in the code path below, +* specify it here to highlight that alloc_pages_nolock() +* doesn't want to deplete reserves. +*/ +static const gfp_t gfp_nolock = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC | + __GFP_COMP;
__alloc_frozen_pages_noprof() is the only user of gfp_nolock. Can we move it into that function to limit its scope? (unless you plan to use it elsewhere).
Quoted 174 lines
mm/page_alloc.c +33
-75+ +/* +* This is the 'heart' of the zoned buddy allocator. +*/ +struct page *__alloc_frozen_pages_noprof (gfp_t gfp,unsigned int order, +int preferred_nid,nodemask_t *nodemask,unsigned int alloc_flags) +{ +struct page *page; +gfp_t alloc_gfp;/* The gfp_t that was actually used for allocation */ +struct alloc_context ac = { }; +unsigned int fastpath_alloc_flags = alloc_flags; + +/* Other flags could be supported later if needed. */ +if (WARN_ON (alloc_flags & ~ALLOC_NOLOCK ))return NULL ; +if (!alloc_order_allowed (gfp, order, alloc_flags)) +return NULL ; + +if (alloc_flags &ALLOC_NOLOCK ) { +VM_WARN_ON_ONCE (gfp & ~__GFP_ACCOUNT); +if (!alloc_trylock_allowed ()) +return NULL ; + gfp |= gfp_nolock; + }else { + fastpath_alloc_flags |=ALLOC_WMARK_LOW ; + } + gfp &= gfp_allowed_mask;/* * Apply scoped allocation constraints. This is mainly about GFP_NOFS @@ -5291,9 +5365,9 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,*/ fastpath_alloc_flags |=alloc_flags_nofragment (zonelist_zone (ac.preferred_zoneref), gfp); -/* First allocation attempt */ +/* First allocation attempt (or, for nolock, only attempt) */ page =get_page_from_freelist (alloc_gfp, order, fastpath_alloc_flags, &ac); -if (likely (page)) +if (likely (page) || (alloc_flags &ALLOC_NOLOCK )) goto out; alloc_gfp = gfp;@@ -5310,7 +5384,8 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, out:if (memcg_kmem_online () && (gfp & __GFP_ACCOUNT) && page &&unlikely (__memcg_kmem_charge_page (page, gfp, order) !=0 )) { -free_frozen_pages (page, order); +__free_frozen_pages (page, order, + alloc_flags &ALLOC_NOLOCK ?FPI_TRYLOCK :0 ); page =NULL ; }@@ -5326,7 +5401,8 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, {struct page *page; - page =__alloc_frozen_pages_noprof (gfp, order, preferred_nid, nodemask); + page =__alloc_frozen_pages_noprof (gfp, order, preferred_nid, nodemask, +ALLOC_DEFAULT );if (page)set_page_refcounted (page);return page;@@ -7856,80 +7932,10 @@ static bool __free_unaccepted(struct page *page)struct page *alloc_frozen_pages_nolock_noprof (gfp_t gfp_flags,int nid,unsigned int order) { -/* -* Do not specify __GFP_DIRECT_RECLAIM, since direct claim is not allowed. -* Do not specify __GFP_KSWAPD_RECLAIM either, since wake up of kswapd -* is not safe in arbitrary context. -* -* These two are the conditions for gfpflags_allow_spinning() being true. -* -* Specify __GFP_NOWARN since failing alloc_pages_nolock() is not a reason -* to warn. Also warn would trigger printk() which is unsafe from -* various contexts. We cannot use printk_deferred_enter() to mitigate, -* since the running context is unknown. -* -* Specify __GFP_ZERO to make sure that call to kmsan_alloc_page() below -* is safe in any context. Also zeroing the page is mandatory for -* BPF use cases. -* -* Though __GFP_NOMEMALLOC is not checked in the code path below, -* specify it here to highlight that alloc_pages_nolock() -* doesn't want to deplete reserves. -*/ -gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC | __GFP_COMP - | gfp_flags; -unsigned int alloc_flags =ALLOC_NOLOCK ; -struct alloc_context ac = { }; -struct page *page; - -VM_WARN_ON_ONCE (gfp_flags & ~__GFP_ACCOUNT); -/* -* In PREEMPT_RT spin_trylock() will call raw_spin_lock() which is -* unsafe in NMI. If spin_trylock() is called from hard IRQ the current -* task may be waiting for one rt_spin_lock, but rt_spin_trylock() will -* mark the task as the owner of another rt_spin_lock which will -* confuse PI logic, so return immediately if called from hard IRQ or -* NMI. -* -* Note, irqs_disabled() case is ok. This function can be called -* from raw_spin_lock_irqsave region. -*/ -if (IS_ENABLED (CONFIG_PREEMPT_RT ) && (in_nmi () ||in_hardirq ())) -return NULL ; - -/* On UP, spin_trylock() always succeeds even when it is locked */ -if (!IS_ENABLED (CONFIG_SMP ) &&in_nmi ()) -return NULL ; - -if (!pcp_allowed_order (order)) -return NULL ; - -/* Bailout, since _deferred_grow_zone() needs to take a lock */ -if (deferred_pages_enabled ()) -return NULL ; -if (nid ==NUMA_NO_NODE ) nid =numa_node_id (); -prepare_alloc_pages (alloc_gfp, order, nid,NULL , &ac, - &alloc_gfp, &alloc_flags); - -/* -* Best effort allocation from percpu free list. -* If it's empty attempt to spin_trylock zone->lock. -*/ - page =get_page_from_freelist (alloc_gfp, order, alloc_flags, &ac); - -/* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */ - -if (memcg_kmem_online () && page && (gfp_flags & __GFP_ACCOUNT) && -unlikely (__memcg_kmem_charge_page (page, alloc_gfp, order) !=0 )) { -__free_frozen_pages (page, order,FPI_TRYLOCK ); - page =NULL ; - } -trace_mm_page_alloc (page, order, alloc_gfp, ac.migratetype); -kmsan_alloc_page (page, order, alloc_gfp); -return page; +return __alloc_frozen_pages_noprof (gfp_flags, order, nid,NULL ,ALLOC_NOLOCK ); }/** * alloc_pages_nolock - opportunistic reentrant allocation from any context mm/slub.c +4
-3@@ -3275,7 +3275,8 @@ static inline struct slab *alloc_slab_page(gfp_t flags, int node,else if (node ==NUMA_NO_NODE ) page =alloc_frozen_pages (flags, order);else - page =__alloc_frozen_pages (flags, order, node,NULL ); + page =__alloc_frozen_pages (flags, order, node,NULL , +ALLOC_DEFAULT );if (!page)return NULL ;@@ -5236,7 +5237,8 @@ static void *___kmalloc_large_node(size_t size, gfp_t flags, int node)if (node ==NUMA_NO_NODE ) page =alloc_frozen_pages_noprof (flags, order);else - page =__alloc_frozen_pages_noprof (flags, order, node,NULL ); + page =__alloc_frozen_pages_noprof (flags, order, node,NULL , +ALLOC_DEFAULT );if (page) { ptr =page_address (page); --2.54.0
Brendan Jackman
reviewerRe: [PATCH v2 03/13] mm/page_alloc: unify __alloc_frozen_pages[_nolock]_noprof()
Quoted 37 lines · Suren Baghdasaryan
Quoted 26 lines · Brendan Jackman
Currently the core allocator code is controlled by
ALLOC_NOLOCK, but the main entry point function is significantly different from the normal__alloc_frozen_pages_nolock(), this is tiring when reading the code.Plumb the
ALLOC_NOLOCKcontrol one layer up in the call stack: create analloc_flagsargument to__alloc_frozen_pages_nolock()(which is only exposed tomm/) and then turn the nolock variant into a thin wrapper that just sets that flag (as well as handlingNUMA_NO_NODE, similar to how some of the wrappers ingfp.hdo).Rationale that this doesn't change anything:
1. Simple bits: A bunch of the nolock-specific handling is just moved to the new
alloc_order_allowed(),alloc_trylock_allowed()andgfp_trylock.2.
__alloc_frozen_pages_noprof()has some extra logic that wasn't previously in the nolock variant:a. Application of
gfp_allowed_mask; this only affects early boot, and
only flags that affect the slowpath get changed here.b. Application of
current_gfp_context()- also only affects the
slowpathQuoted 6 lines
3. The slowpath itself: this is now just explicitly skipped under !ALLOC_TRYLOCK.
Ulterior motive: adding an
alloc_flagsarg to the allocator's mm-internal entrypoint can later be used to do more allocation customisation without needing to create new GFP flags.Looks like a nice overall cleanup.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
While adding this flag to a bunch of places, create
ALLOC_DEFAULTto avoid a mysterious literal 0 in most places.alloc_frozen_pages_noprof()is defined above the alloc flags so just leave that as a slightly messy exception instead of trying to fully reordermm/internal.hfor that one case.Moving the whole
alloc_frozen_pages()block down seems simple enough and would avoid special-casing this.
Yeah... when you put it like that, I don't actually know why I was so intimidated by the prospect of moving a handful of function declarations!
Anyway in the v3 I'm creating a new mm/page_alloc.h so this will happen as a side effect of that.
PATCH v2 4/13 mm/page_alloc: relax GFP WARN in nolock allocs
In reply to Brendan JackmanThis WARN forbids setting other flags than __GFP_ACCOUNT but we unconditionally set the ones in gfp_nolock so they are certainly fine for the caller to set.
There are other GFP flags that are almost certainly fine to set here; Willy noted GFP_HIGHMEM, GFP_DMA, GFP_MOVABLE and GFP_HARDWALL. But, nolock allocation is rather special, so be conservative to try and ensure we have a chance to think carefully before nontrivial new usecases arise.
--- mm/page_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/page_alloc.c +2 -1
@@ -5337,7 +5337,8 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,return NULL ;if (alloc_flags &ALLOC_NOLOCK ) { -VM_WARN_ON_ONCE (gfp & ~__GFP_ACCOUNT); +/* Certain other flags could be supported later if needed. */ +VM_WARN_ON_ONCE (gfp & ~(__GFP_ACCOUNT | gfp_nolock));if (!alloc_trylock_allowed ())return NULL ; gfp |= gfp_nolock;
Signature · 1 line
2.54.0
Re: [PATCH v2 04/13] mm/page_alloc: relax GFP WARN in nolock allocs
Quoted 11 lines · Brendan Jackman
This WARN forbids setting other flags than
__GFP_ACCOUNTbut we unconditionally set the ones ingfp_nolockso they are certainly fine for the caller to set.There are other GFP flags that are almost certainly fine to set here; Willy noted
GFP_HIGHMEM,GFP_DMA,GFP_MOVABLEandGFP_HARDWALL. But, nolock allocation is rather special, so be conservative to try and ensure we have a chance to think carefully before nontrivial new usecases arise.
Quoted 3 lines
Suggested-by Matthew Wilcox <[email protected]>Signed-off-by Brendan Jackman <[email protected]>
Quoted 22 lines
--- mm/page_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/page_alloc.c +2
-2@@ -5337,7 +5337,8 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,return NULL ;if (alloc_flags &ALLOC_NOLOCK ) { -VM_WARN_ON_ONCE (gfp & ~__GFP_ACCOUNT); +/* Certain other flags could be supported later if needed. */ +VM_WARN_ON_ONCE (gfp & ~(__GFP_ACCOUNT | gfp_nolock));if (!alloc_trylock_allowed ())return NULL ; gfp |= gfp_nolock; --2.54.0
PATCH v2 5/13 perf/x86/intel: Use higher-level allocator
In reply to Brendan JackmanThe difference between __alloc_pages_node() and alloc_pages_node() is that the former allows you to pass NUMA_NO_NODE.
The former is going away and the latter works fine here so switch over.
--- arch/x86/events/intel/ds.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/events/intel/ds.c +3 -3
@@ -834,7 +834,7 @@ static void *dsalloc_pages(size_t size, gfp_t flags, int cpu)int node =cpu_to_node (cpu);struct page *page; - page =__alloc_pages_node (node, flags | __GFP_ZERO, order); + page =alloc_pages_node (node, flags | __GFP_ZERO, order);return page ?page_address (page) :NULL ; }
@@ -1090,9 +1090,9 @@ void init_arch_pebs_on_cpu(int cpu)/* * 4KB-aligned pointer of the output buffer -* (__alloc_pages_node() return page aligned address) +* (alloc_pages_node() returns page aligned address) * Buffer Size = 4KB * 2^SIZE -* contiguous physical buffer (__alloc_pages_node() with order) +* contiguous physical buffer (alloc_pages_node() with order) */ arch_pebs_base =virt_to_phys (cpuc->pebs_vaddr) |PEBS_BUFFER_SHIFT ; wrmsr_on_cpu(cpu, MSR_IA32_PEBS_BASE, (u32)arch_pebs_base,
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v2 05/13] perf/x86/intel: Use higher-level allocator
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The commit message factually misrepresents the API differences between `__alloc_pages_node()`…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message factually misrepresents the API differences between __alloc_pages_node() and alloc_pages_node(). --
commit a5667683e56825d97c5814c0349e4de3300e3e14
Author: Brendan Jackman <[email protected]>
perf/x86/intel: Use higher-level allocator
This commit switches the memory allocation in dsalloc_pages() from __alloc_pages_node() to the higher-level alloc_pages_node() function. It also updates a comment to reflect the API change.
Quoted 2 lines
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.
[Severity: Medium]
Is this description of the API differences accurate?
Looking at include/linux/gfp.h, it appears the capabilities are actually reversed. alloc_pages_node() is the function that explicitly supports and safely handles NUMA_NO_NODE:
include/linux/gfp.h:alloc_pages_node_noprof() {
if (nid == NUMA_NO_NODE)
nid = numa_mem_id();
...
}Meanwhile, __alloc_pages_node() expects a valid node ID and contains a VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES) check, which will crash if passed NUMA_NO_NODE.
Could the commit message be updated to clarify that alloc_pages_node() is the API that safely handles NUMA_NO_NODE?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Brendan Jackman
reviewerRe: [PATCH v2 05/13] perf/x86/intel: Use higher-level allocator
Quoted 4 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message factually misrepresents the API differences between__alloc_pages_node()andalloc_pages_node(). --
Quoted 11 lines
commit
a5667683e56825d97c5814c0349e4de3300e3e14
Author: Brendan Jackman <[email protected]>perf/x86/intel: Use higher-level allocator
This commit switches the memory allocation in
dsalloc_pages()from__alloc_pages_node()to the higher-levelalloc_pages_node()function. It also updates a comment to reflect the API change.Quoted 2 lines
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.
^^^^^^
Sashiko is correct, that should say "latter".
Quoted 2 lines
[Severity: Medium]
Seems like an inflated severity rating, this is basically a typo in the commit mesage, and anyone that noticed it would probably have realised what happened.
Quoted 18 lines
Is this description of the API differences accurate?
Looking at
include/linux/gfp.h, it appears the capabilities are actually reversed.alloc_pages_node()is the function that explicitly supports and safely handlesNUMA_NO_NODE:include/linux/gfp.h:alloc_pages_node_noprof() { if (nid == NUMA_NO_NODE) nid = numa_mem_id(); ... }Meanwhile,
__alloc_pages_node()expects a valid node ID and contains aVM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES)check, which will crash if passedNUMA_NO_NODE.Could the commit message be updated to clarify that
alloc_pages_node()is the API that safely handlesNUMA_NO_NODE?
Re: [PATCH v2 05/13] perf/x86/intel: Use higher-level allocator
Quoted 17 lines · Brendan Jackman
Quoted 4 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message factually misrepresents the API differences between__alloc_pages_node()andalloc_pages_node(). --Quoted 11 lines
commit
a5667683e56825d97c5814c0349e4de3300e3e14
Author: Brendan Jackman <[email protected]>perf/x86/intel: Use higher-level allocator
This commit switches the memory allocation in
dsalloc_pages()from__alloc_pages_node()to the higher-levelalloc_pages_node()function. It also updates a comment to reflect the API change.Quoted 2 lines
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.
Quoted 8 lines
^^^^^^
Sashiko is correct, that should say "latter".Quoted 2 lines
[Severity: Medium]
Seems like an inflated severity rating, this is basically a typo in the commit mesage, and anyone that noticed it would probably have realised what happened.
With the fix of that "extremely medium severity issue",
Quoted 20 lines
Quoted 19 lines
Is this description of the API differences accurate?
Looking at
include/linux/gfp.h, it appears the capabilities are actually reversed.alloc_pages_node()is the function that explicitly supports and safely handlesNUMA_NO_NODE:include/linux/gfp.h:alloc_pages_node_noprof() { if (nid == NUMA_NO_NODE) nid = numa_mem_id(); ... }Meanwhile,
__alloc_pages_node()expects a valid node ID and contains aVM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES)check, which will crash if passedNUMA_NO_NODE.Could the commit message be updated to clarify that
alloc_pages_node()is the API that safely handlesNUMA_NO_NODE?
PATCH v2 6/13 KVM: VMX: Use higher-level allocator
In reply to Brendan JackmanThe difference between __alloc_pages_node() and alloc_pages_node() is that the former allows you to pass NUMA_NO_NODE.
The former is going away and the latter works fine here so switch over.
--- arch/x86/kvm/vmx/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +1 -1
@@ -2994,7 +2994,7 @@ struct vmcs *alloc_vmcs_cpu(bool shadow, int cpu, gfp_t flags)struct page *pages;struct vmcs *vmcs; - pages =__alloc_pages_node (node, flags,0 ); + pages =alloc_pages_node (node, flags,0 );if (!pages)return NULL ; vmcs =page_address (pages);
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v2 06/13] KVM: VMX: Use higher-level allocator
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The commit message incorrectly states that `__alloc_pages_node()` allows passing `NUMA_NO_NODE`…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message incorrectly states that __alloc_pages_node() allows passing NUMA_NO_NODE, while the opposite is true. --
commit 7bd439c242125db27305b61b14c9972fb028282a
Author: Brendan Jackman <[email protected]>
KVM: VMX: Use higher-level allocator
This commit switches the allocation function used in alloc_vmcs_cpu() from __alloc_pages_node() to alloc_pages_node().
Quoted 4 lines
KVM: VMX: Use higher-level allocator
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.
[Severity: Medium]
Is this description inverted?
Looking at include/linux/gfp.h, it appears __alloc_pages_node() explicitly forbids NUMA_NO_NODE (-1) via VM_BUG_ON(nid < 0).
Instead, it is alloc_pages_node() that handles NUMA_NO_NODE by explicitly checking for it and falling back to numa_mem_id().
While the code change itself is safe, the justification reverses the behavior of the two APIs. Could the commit message be updated to accurately reflect the API semantics?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Brendan Jackman
reviewerRe: [PATCH v2 06/13] KVM: VMX: Use higher-level allocator
Quoted 23 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message incorrectly states that__alloc_pages_node()allows passingNUMA_NO_NODE, while the opposite is true. --commit
7bd439c242125db27305b61b14c9972fb028282a
Author: Brendan Jackman <[email protected]>KVM: VMX: Use higher-level allocator
This commit switches the allocation function used in
alloc_vmcs_cpu()from__alloc_pages_node()toalloc_pages_node().Quoted 4 lines
KVM: VMX: Use higher-level allocator
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.[Severity: Medium]
Is this description inverted?Looking at
include/linux/gfp.h, it appears__alloc_pages_node()explicitly forbidsNUMA_NO_NODE(-1) viaVM_BUG_ON(nid < 0).
Quoted 6 lines
Instead, it is
alloc_pages_node()that handlesNUMA_NO_NODEby explicitly checking for it and falling back tonuma_mem_id().While the code change itself is safe, the justification reverses the behavior of the two APIs. Could the commit message be updated to accurately reflect the API semantics?
Repeating myself[0] as this patch has a different CC list from the others:
Sashiko is correct, the commit message says "former" but it should say "latter".
Sean Christopherson
maintainerRe: [PATCH v2 06/13] KVM: VMX: Use higher-level allocator
Quoted 9 lines · Brendan Jackman
Quoted 8 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message incorrectly states that__alloc_pages_node()allows passingNUMA_NO_NODE, while the opposite is true. --commit
7bd439c242125db27305b61b14c9972fb028282a
Author: Brendan Jackman <[email protected]>KVM: VMX: Use higher-level allocator
While you're dealing with nits, can you massage the shortlog to something like:
KVM: VMX: Use no-underscores API when allocating pages for a specific NUMA node
"Use higher-level allocator" is extremely vague, and arguably misleading because the "allocator" being used isn't changing. Which is kinda the point: *nothing* is changing in practice.
Re: [PATCH v2 06/13] KVM: VMX: Use higher-level allocator
Quoted 11 lines · Sean Christopherson
Quoted 9 lines · Brendan Jackman
Quoted 8 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message incorrectly states that__alloc_pages_node()allows passingNUMA_NO_NODE, while the opposite is true. --commit
7bd439c242125db27305b61b14c9972fb028282a
Author: Brendan Jackman <[email protected]>KVM: VMX: Use higher-level allocator
Quoted 7 lines
While you're dealing with nits, can you massage the shortlog to something like:
KVM: VMX: Use no-underscores API when allocating pages for a specific NUMA node
"Use higher-level allocator" is extremely vague, and arguably misleading because the "allocator" being used isn't changing. Which is kinda the point: *nothing* is changing in practice.
Maybe "higher-level allocator API"?
no-underscores is just.. meh :P
Suren Baghdasaryan
maintainerRe: [PATCH v2 06/13] KVM: VMX: Use higher-level allocator
Quoted 17 lines · Yosry Ahmed
Quoted 15 lines · Sean Christopherson
Quoted 9 lines · Brendan Jackman
Quoted 8 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message incorrectly states that__alloc_pages_node()allows passingNUMA_NO_NODE, while the opposite is true. --commit
7bd439c242125db27305b61b14c9972fb028282a
Author: Brendan Jackman <[email protected]>KVM: VMX: Use higher-level allocator
While you're dealing with nits, can you massage the shortlog to something like:
KVM: VMX: Use no-underscores API when allocating pages for a specific NUMA node
Quoted 7 lines
Quoted 3 lines
"Use higher-level allocator" is extremely vague, and arguably misleading because the "allocator" being used isn't changing. Which is kinda the point: *nothing* is changing in practice.
Maybe "higher-level allocator API"?
no-underscores is just.. meh :P
It's overall a good idea to add "No functional change intended" at the end of the changelog in all these cleanup patches.
Quoted 1 line
Brendan Jackman
reviewerRe: [PATCH v2 06/13] KVM: VMX: Use higher-level allocator
Quoted 22 lines · Suren Baghdasaryan
Quoted 21 lines · Yosry Ahmed
Quoted 18 lines · Sean Christopherson
Quoted 9 lines · Brendan Jackman
Quoted 8 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message incorrectly states that__alloc_pages_node()allows passingNUMA_NO_NODE, while the opposite is true. --commit
7bd439c242125db27305b61b14c9972fb028282a
Author: Brendan Jackman <[email protected]>KVM: VMX: Use higher-level allocator
While you're dealing with nits, can you massage the shortlog to something like:
KVM: VMX: Use no-underscores API when allocating pages for a specific NUMA node
"Use higher-level allocator" is extremely vague, and arguably misleading because the "allocator" being used isn't changing. Which is kinda the point: *nothing* is changing in practice.
Quoted 6 lines
Quoted 3 lines
Maybe "higher-level allocator API"?
no-underscores is just.. meh :P
It's overall a good idea to add "No functional change intended" at the end of the changelog in all these cleanup patches.
Oh yeah good point, I'm adding that for each of these "remove the __" ones and some others.
I'm skipping it for the ones that are trivially identifiable as such (e.g. "move function to a different file" and "delete unused function"), but let me know if you think I should just add this note everywhere instead.
PATCH v2 7/13 x86/virt: Use higher-level allocator
In reply to Brendan JackmanThe difference between __alloc_pages_node() and alloc_pages_node() is that the former allows you to pass NUMA_NO_NODE.
The former is going away and the latter works fine here so switch over.
--- arch/x86/virt/hw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/virt/hw.c +1 -1
@@ -183,7 +183,7 @@ static __init int __x86_vmx_init(void)struct page *page;struct vmcs *vmcs; - page =__alloc_pages_node (node,GFP_KERNEL | __GFP_ZERO,0 ); + page =alloc_pages_node (node,GFP_KERNEL | __GFP_ZERO,0 );if (WARN_ON_ONCE (!page)) {x86_vmx_exit ();return -ENOMEM ;
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v2 07/13] x86/virt: Use higher-level allocator
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Commit message factually misstates the difference between __alloc_pages_node() and…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Commit message factually misstates the difference between __alloc_pages_node() and alloc_pages_node() --
commit ec153a4ff69fcf9b29806faedae74ed9c08f7dda
Author: Brendan Jackman <[email protected]>
x86/virt: Use higher-level allocator
This commit switches the __x86_vmx_init() function to use the higher-level alloc_pages_node() function instead of __alloc_pages_node(). The code change itself is safe and functions correctly.
Quoted 2 lines
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.
[Severity: Low]
Is this description accurate?
Looking at the definitions, __alloc_pages_node() explicitly contains a VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES), which forbids passing NUMA_NO_NODE (-1).
Instead, alloc_pages_node() is the one that explicitly handles NUMA_NO_NODE by converting it to numa_mem_id().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Brendan Jackman
reviewerRe: [PATCH v2 07/13] x86/virt: Use higher-level allocator
Quoted 19 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Commit message factually misstates the difference between__alloc_pages_node()andalloc_pages_node()--commit
ec153a4ff69fcf9b29806faedae74ed9c08f7dda
Author: Brendan Jackman <[email protected]>x86/virt: Use higher-level allocator
This commit switches the
__x86_vmx_init()function to use the higher-levelalloc_pages_node()function instead of__alloc_pages_node(). The code change itself is safe and functions correctly.Quoted 2 lines
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.[Severity: Low]
Is this description accurate?
Quoted 6 lines
Looking at the definitions,
__alloc_pages_node()explicitly contains aVM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES), which forbids passingNUMA_NO_NODE(-1).Instead,
alloc_pages_node()is the one that explicitly handlesNUMA_NO_NODEby converting it tonuma_mem_id().
Repeating myself[0] as this patch has a different CC list from the others:
Sashiko is correct, the commit message says "former" but it should say "latter".
PATCH v2 8/13 sgi-xp: Use higher-level allocator
In reply to Brendan JackmanThe difference between __alloc_pages_node() and alloc_pages_node() is that the former allows you to pass NUMA_NO_NODE.
The former is going away and the latter works fine here so switch over.
--- drivers/misc/sgi-xp/xpc_uv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/sgi-xp/xpc_uv.c +1 -1
@@ -170,7 +170,7 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name, mq->mmr_blade =uv_cpu_to_blade_id (cpu); nid =cpu_to_node (cpu); - page =__alloc_pages_node (nid, + page =alloc_pages_node (nid,GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE, pg_order);if (page ==NULL ) {
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v2 08/13] sgi-xp: Use higher-level allocator
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Medium] Commit message fundamentally misunderstands and inverts the documented differences between __alloc_pages_node() and alloc_pages_node().
Pre-existing issues:
- [High] Logic Error / Variable Mismatch in xpc_init_mq_node() breaks CPU fallback and NUMA affinity.
- [High] Hardware IRQ enabled before GRU message queue descriptors are fully initialized leads to NULL pointer dereference on spurious interrupts. --
commit 2717112c630ddd5adcf0324575c2741c6d3bf969
Author: Brendan Jackman <[email protected]>
sgi-xp: Use higher-level allocator
This commit switches xpc_create_gru_mq_uv() to use alloc_pages_node() instead of __alloc_pages_node(). The change is intended to replace an allocator function that is being removed with one that handles similar requirements.
Quoted 6 lines
sgi-xp: Use higher-level allocator
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.The former is going away and the latter works fine here so switch over.
[Severity: Medium]
Is this description accurate?
__alloc_pages_node() strictly prohibits NUMA_NO_NODE, while alloc_pages_node() safely handles it by falling back to numa_mem_id().
While the code change itself appears safe here since cpu_to_node() returns a valid node, could the commit message be updated to reflect the correct behavior of these memory allocation APIs?
drivers/misc/sgi-xp/xpc_uv.c xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name, · line 175
Quoted 12 lines
drivers/misc/sgi-xp/xpc_uv.c +1
-1@@ -170,7 +170,7 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name, mq->mmr_blade =uv_cpu_to_blade_id (cpu); nid =cpu_to_node (cpu); - page =__alloc_pages_node (nid, + page =alloc_pages_node (nid,GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE, pg_order);
[Severity: High]
This isn't a bug introduced by this patch, but looking at the interrupt setup that occurs further down in xpc_create_gru_mq_uv():
drivers/misc/sgi-xp/xpc_uv.c:xpc_create_gru_mq_uv() {
...
ret = request_irq(mq->irq, irq_handler, 0, irq_name, NULL);
...
}If a spurious interrupt occurs immediately after request_irq() is called, could xpc_handle_activate_IRQ_uv() dereference the global xpc_activate_mq_uv pointer before it is initialized?
drivers/misc/sgi-xp/xpc_uv.c:xpc_handle_activate_IRQ_uv() {
...
msg_hdr = gru_get_next_message(xpc_activate_mq_uv->gru_mq_desc);
...
}The global pointer doesn't seem to be assigned until xpc_create_gru_mq_uv() returns to its caller.
[Severity: High]
This is a pre-existing issue, but looking at xpc_init_mq_node() which calls xpc_create_gru_mq_uv():
drivers/misc/sgi-xp/xpc_uv.c:xpc_init_mq_node() {
...
for_each_cpu(cpu, cpumask_of_node(nid)) {
xpc_activate_mq_uv =
xpc_create_gru_mq_uv(XPC_ACTIVATE_MQ_SIZE_UV, nid,
...
}Does this loop inadvertently pass the nid variable instead of the cpu variable to xpc_create_gru_mq_uv()?
This appears to bypass the CPU fallback iteration and could result in querying uv_cpu_to_blade_id() and cpu_to_node() with a node index rather than a CPU index.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH v2 08/13] sgi-xp: Use higher-level allocator
In reply to Brendan JackmanQuoted 32 lines · Brendan Jackman
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.The former is going away and the latter works fine here so switch over.
Cc Robin Holt <[email protected]>Cc Steve Wahl <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Assisted-by Gemini:unknown-modelSigned-off-by Brendan Jackman <[email protected]>--- drivers/misc/sgi-xp/xpc_uv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/misc/sgi-xp/xpc_uv.c +1
-1@@ -170,7 +170,7 @@ xpc_create_gru_mq_uv(unsigned int mq_size, int cpu, char *irq_name, mq->mmr_blade =uv_cpu_to_blade_id (cpu); nid =cpu_to_node (cpu); - page =__alloc_pages_node (nid, + page =alloc_pages_node (nid,GFP_KERNEL | __GFP_ZERO | __GFP_THISNODE, pg_order);if (page ==NULL ) {Signature · 2 lines
-- 2.54.0
PATCH v2 9/13 net/funeth: Switch to higher-level allocator
In reply to Brendan JackmanThe difference between __alloc_pages_node() and alloc_pages_node() is that the former allows you to pass NUMA_NO_NODE.
The former is going away and the latter works fine here so switch over.
--- drivers/net/ethernet/fungible/funeth/funeth_rx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/fungible/funeth/funeth_rx.c +1 -1
@@ -103,7 +103,7 @@ static int funeth_alloc_page(struct funeth_rxq *q, struct funeth_rxbuf *rb,if (cache_get (q, rb))return 0 ; - p =__alloc_pages_node (node, gfp | __GFP_NOWARN,0 ); + p =alloc_pages_node (node, gfp | __GFP_NOWARN,0 );if (unlikely (!p))return -ENOMEM ;
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v2 09/13] net/funeth: Switch to higher-level allocator
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The commit message logic regarding __alloc_pages_node and alloc_pages_node is inverted. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message logic regarding __alloc_pages_node and alloc_pages_node is inverted. --
commit ab883602f87dc726f65726ac01fce73a498907b3
Author: Brendan Jackman <[email protected]>
net/funeth: Switch to higher-level allocator
This commit replaces __alloc_pages_node() with alloc_pages_node() in the funeth driver.
Quoted 4 lines
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.The former is going away and the latter works fine here so switch over.
[Severity: Medium]
Is this description inverted? Looking at include/linux/gfp.h, it is alloc_pages_node() that safely handles passing NUMA_NO_NODE by checking if (nid == NUMA_NO_NODE). On the other hand, __alloc_pages_node() contains a VM_BUG_ON() which strictly prevents passing NUMA_NO_NODE (-1).
The code change itself appears correct since the node variable can be -1 here, but could the commit message be updated to accurately reflect which function handles NUMA_NO_NODE?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Brendan Jackman
reviewerRe: [PATCH v2 09/13] net/funeth: Switch to higher-level allocator
Quoted 23 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message logic regarding__alloc_pages_nodeandalloc_pages_nodeis inverted. --commit
ab883602f87dc726f65726ac01fce73a498907b3
Author: Brendan Jackman <[email protected]>net/funeth: Switch to higher-level allocator
This commit replaces
__alloc_pages_node()withalloc_pages_node()in the funeth driver.Quoted 4 lines
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.The former is going away and the latter works fine here so switch over.
[Severity: Medium]
Is this description inverted? Looking atinclude/linux/gfp.h, it isalloc_pages_node()that safely handles passingNUMA_NO_NODEby checking if (nid ==NUMA_NO_NODE). On the other hand,__alloc_pages_node()contains aVM_BUG_ON()which strictly prevents passingNUMA_NO_NODE(-1).
Quoted 3 lines
The code change itself appears correct since the node variable can be -1 here, but could the commit message be updated to accurately reflect which function handles
NUMA_NO_NODE?
Repeating myself[0] as this patch has a different CC list from the others:
Sashiko is correct, the commit message says "former" but it should say "latter".
Suren Baghdasaryan
maintainerRe: [PATCH v2 09/13] net/funeth: Switch to higher-level allocator
Quoted 25 lines · Brendan Jackman
Quoted 23 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message logic regarding__alloc_pages_nodeandalloc_pages_nodeis inverted. --commit
ab883602f87dc726f65726ac01fce73a498907b3
Author: Brendan Jackman <[email protected]>net/funeth: Switch to higher-level allocator
This commit replaces
__alloc_pages_node()withalloc_pages_node()in the funeth driver.Quoted 4 lines
The difference between
__alloc_pages_node()andalloc_pages_node()is that the former allows you to passNUMA_NO_NODE.The former is going away and the latter works fine here so switch over.
[Severity: Medium]
Is this description inverted? Looking atinclude/linux/gfp.h, it isalloc_pages_node()that safely handles passingNUMA_NO_NODEby checking if (nid ==NUMA_NO_NODE). On the other hand,__alloc_pages_node()contains aVM_BUG_ON()which strictly prevents passingNUMA_NO_NODE(-1).
Quoted 3 lines
Quoted 3 lines
The code change itself appears correct since the node variable can be -1 here, but could the commit message be updated to accurately reflect which function handles
NUMA_NO_NODE?
After fixing the changelogs and titles as suggested in [1], feel free to add my Reviewed-by to all the patches replacing __alloc_pages_node() with alloc_pages_node()
[1] https://lore.kernel.org/all/[email protected]/
Quoted 9 lines
Repeating myself[0] as this patch has a different CC list from the others:
Sashiko is correct, the commit message says "former" but it should say "latter".
PATCH v2 10/13 mm: Remove __alloc_pages_node()
In reply to Brendan JackmanThere were only a few users, which have been removed. The only advantage of this API over alloc_pages_node() is avoiding a single conditional branch. The disadvantages are:
1. More API surface, more sources of confusion, more maintenance.
2. Worse impact of CPU hotplug bugs: most users of __alloc_pages_node() were using the result of cpu_to_node(); if the CPU gets hotplugged out this will return NUMA_NO_NODE. If one of these paths fails to protect against a concurrent hotplug then page_alloc.c will use NUMA_NO_NODE as an index into NODE_DATA() and cause some horrible memory corruption or other. With alloc_pages_node(), the code might just work fine.
Ulterior motive: this frees up the __* variants of the allocator APIs to serve specifically for use as mm-internal API.
--- include/linux/gfp.h | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-)
include/linux/gfp.h +4 -16
@@ -278,21 +278,6 @@ static inline void warn_if_node_offline(int this_node, gfp_t gfp_mask)dump_stack (); } -/* -* Allocate pages, preferring the node given as nid. The node must be valid and -* online. For more general interface, see alloc_pages_node(). -*/ -static inline struct page * -__alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) -{ -VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES ); -warn_if_node_offline (nid, gfp_mask); - -return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); -} - -#define __alloc_pages_node (...) alloc_hooks(__alloc_pages_node_noprof(__VA_ARGS__)) -static inline struct folio *__folio_alloc_node_noprof (gfp_t gfp,unsigned int order,int nid) {
@@ -315,7 +300,10 @@ static inline struct page *alloc_pages_node_noprof(int nid, gfp_t gfp_mask,if (nid ==NUMA_NO_NODE ) nid =numa_mem_id (); -return __alloc_pages_node_noprof (nid, gfp_mask, order); +VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES ); +warn_if_node_offline (nid, gfp_mask); + +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); }#define alloc_pages_node (...) alloc_hooks(alloc_pages_node_noprof(__VA_ARGS__))
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v2 10/13] mm: Remove __alloc_pages_node()
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch leaves __folio_alloc_node() exposed to the exact same CPU hotplug out-of-bounds vulnerability that justified the removal of __alloc_pages_node(). --
commit b690a6726aee701f88a87b35d2db8bfbfa39bc05
Author: Brendan Jackman <[email protected]>
mm: Remove __alloc_pages_node()
This patch removes __alloc_pages_node() because its usage with cpu_to_node() can return NUMA_NO_NODE during CPU hotplug, bypassing validation and causing out-of-bounds accesses on NODE_DATA().
Quoted 16 lines
include/linux/gfp.h +0
-8@@ -278,21 +278,6 @@ static inline void warn_if_node_offline(int this_node, gfp_t gfp_mask)dump_stack (); } -/* -* Allocate pages, preferring the node given as nid. The node must be valid and -* online. For more general interface, see alloc_pages_node(). -*/ -static inline struct page * -__alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) -{ -VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES );
include/linux/gfp.h static inline void warn_if_node_offline(int this_node, gfp_t gfp_mask) · line 283
Quoted 10 lines
include/linux/gfp.h +0
-7-warn_if_node_offline (nid, gfp_mask); - -return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); -} - -#define __alloc_pages_node (...) alloc_hooks(__alloc_pages_node_noprof(__VA_ARGS__)) -static inline struct folio *__folio_alloc_node_noprof (gfp_t gfp,unsigned int order,int nid) {
[Severity: High]
This isn't a bug introduced by this patch, but does leaving __folio_alloc_node_noprof() exposed maintain the exact same CPU hotplug vulnerability that justified removing __alloc_pages_node()?
The commit message notes that passing the result of cpu_to_node() to the allocator can yield NUMA_NO_NODE if the CPU is hotplugged out, which bypasses validation and causes out-of-bounds accesses on NODE_DATA().
Can this still happen with __folio_alloc_node()? For example, in net/sunrpc/svc.c, svc_prepare_thread() calls:
rqstp->rq_scratch_folio = __folio_alloc_node(GFP_KERNEL, 0, node);
with a potentially invalid node ID originating from cpu_to_node(). Should __folio_alloc_node() also be removed or updated to safely handle NUMA_NO_NODE?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Brendan Jackman
reviewerRe: [PATCH v2 10/13] mm: Remove __alloc_pages_node()
Quoted 38 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch leaves__folio_alloc_node()exposed to the exact same CPU hotplug out-of-bounds vulnerability that justified the removal of__alloc_pages_node(). --commit
b690a6726aee701f88a87b35d2db8bfbfa39bc05
Author: Brendan Jackman <[email protected]>mm: Remove
__alloc_pages_node()This patch removes
__alloc_pages_node()because its usage withcpu_to_node()can returnNUMA_NO_NODEduring CPU hotplug, bypassing validation and causing out-of-bounds accesses onNODE_DATA().Quoted 23 lines
include/linux/gfp.h +0
-15@@ -278,21 +278,6 @@ static inline void warn_if_node_offline(int this_node, gfp_t gfp_mask)dump_stack (); } -/* -* Allocate pages, preferring the node given as nid. The node must be valid and -* online. For more general interface, see alloc_pages_node(). -*/ -static inline struct page * -__alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) -{ -VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES ); -warn_if_node_offline (nid, gfp_mask); - -return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); -} - -#define __alloc_pages_node (...) alloc_hooks(__alloc_pages_node_noprof(__VA_ARGS__)) -
Quoted 8 lines
include/linux/gfp.h static inline void warn_if_node_offline(int this_node, gfp_t gfp_mask) · line 283
Quoted 3 lines
include/linux/gfp.h +0
-0static inline struct folio *__folio_alloc_node_noprof (gfp_t gfp,unsigned int order,int nid) {[Severity: High]
This isn't a bug introduced by this patch, but does leaving__folio_alloc_node_noprof()exposed maintain the exact same CPU hotplug vulnerability that justified removing__alloc_pages_node()?
^^^^^^^^^^^^^ No, Sashiko-chan! Why are you disclosing this critical
vulnerability without an embargo!?!?!
Quoted 5 lines
The commit message notes that passing the result of
cpu_to_node()to the allocator can yieldNUMA_NO_NODEif the CPU is hotplugged out, which bypasses validation and causes out-of-bounds accesses onNODE_DATA().
Quoted 8 lines
Can this still happen with
__folio_alloc_node()? For example, innet/sunrpc/svc.c,svc_prepare_thread()calls:
rqstp->rq_scratch_folio=__folio_alloc_node(GFP_KERNEL, 0, node);with a potentially invalid node ID originating from
cpu_to_node(). Should__folio_alloc_node()also be removed or updated to safely handleNUMA_NO_NODE?
Serious answer: this is discussed in the cover letter, leaving the *folio* API untouched was deliberate.
(Not saying we _shouldn't_ make that change, but this patchset is already pretty big and the __alloc_pages* changes had an ulterior motive).
Re: [PATCH v2 10/13] mm: Remove __alloc_pages_node()
In reply to Brendan JackmanQuoted 15 lines · Brendan Jackman
There were only a few users, which have been removed. The only advantage of this API over
alloc_pages_node()is avoiding a single conditional branch. The disadvantages are:1. More API surface, more sources of confusion, more maintenance.
2. Worse impact of CPU hotplug bugs: most users of
__alloc_pages_node()were using the result ofcpu_to_node(); if the CPU gets hotplugged out this will returnNUMA_NO_NODE. If one of these paths fails to protect against a concurrent hotplug thenpage_alloc.cwill useNUMA_NO_NODEas an index intoNODE_DATA()and cause some horrible memory corruption or other. Withalloc_pages_node(), the code might just work fine.
Quoted 2 lines
Ulterior motive: this frees up the __* variants of the allocator APIs to serve specifically for use as mm-internal API.
Ah, that's what motivated all that churn! :)
Quoted 2 lines
Signed-off-by Brendan Jackman <[email protected]>
Quoted 46 lines
--- include/linux/gfp.h | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-)include/linux/gfp.h +4
-17@@ -278,21 +278,6 @@ static inline void warn_if_node_offline(int this_node, gfp_t gfp_mask)dump_stack (); } -/* -* Allocate pages, preferring the node given as nid. The node must be valid and -* online. For more general interface, see alloc_pages_node(). -*/ -static inline struct page * -__alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) -{ -VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES ); -warn_if_node_offline (nid, gfp_mask); - -return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); -} - -#define __alloc_pages_node (...) alloc_hooks(__alloc_pages_node_noprof(__VA_ARGS__)) -static inline struct folio *__folio_alloc_node_noprof (gfp_t gfp,unsigned int order,int nid) {@@ -315,7 +300,10 @@ static inline struct page *alloc_pages_node_noprof(int nid, gfp_t gfp_mask,if (nid ==NUMA_NO_NODE ) nid =numa_mem_id (); -return __alloc_pages_node_noprof (nid, gfp_mask, order); +VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES ); +warn_if_node_offline (nid, gfp_mask); + +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); }#define alloc_pages_node (...) alloc_hooks(alloc_pages_node_noprof(__VA_ARGS__)) --2.54.0
PATCH v2 11/13 alloc_tag: Move to mm/
In reply to Brendan JackmanThis is logically mm code. Moving to mm/ allows access to mm/internal.h
---
MAINTAINERS | 2 +-
lib/Makefile | 1 -
mm/Makefile | 1 +
{lib => mm}/alloc_tag.c | 0
4 files changed, 2 insertions(+), 2 deletions(-)MAINTAINERS +1 -1
@@ -16713,7 +16713,7 @@ S: Maintained F: Documentation/mm/allocation-profiling.rst F: include/linux/alloc_tag.h F: include/linux/pgalloc_tag.h -F: lib/alloc_tag.c +F: mm/alloc_tag.c MEMORY CONTROLLER DRIVERS M: Krzysztof Kozlowski <[email protected]>
lib/Makefile +0 -1
@@ -197,7 +197,6 @@ obj-$(CONFIG_OF_RECONFIG_NOTIFIER_ERROR_INJECT) += \ obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o obj-$(CONFIG_CODE_TAGGING) += codetag.o -obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o lib-$(CONFIG_GENERIC_BUG) += bug.o
mm/Makefile +1 -0
@@ -147,3 +147,4 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o +obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o
mm/alloc_tag.c renamed from lib/alloc_tag.c +0 -0
Signature · 1 line
2.54.0
Lorenzo Stoakes
reviewerRe: [PATCH v2 11/13] alloc_tag: Move to mm/
Quoted 3 lines · Brendan Jackman
This is logically mm code. Moving to
mm/allows access tomm/internal.hSigned-off-by Brendan Jackman <[email protected]>
Sorry to be a pain, but I feel that this change should be dealt with separately perhaps as a pre-requisite to this series.
Thanks, Lorenzo
Quoted 49 lines
--- MAINTAINERS | 2 +- lib/Makefile | 1 - mm/Makefile | 1 + {lib => mm}/alloc_tag.c | 0 4 files changed, 2 insertions(+), 2 deletions(-)MAINTAINERS +1
-1@@ -16713,7 +16713,7 @@ S: Maintained F: Documentation/mm/allocation-profiling.rst F: include/linux/alloc_tag.h F: include/linux/pgalloc_tag.h -F: lib/alloc_tag.c +F: mm/alloc_tag.c MEMORY CONTROLLER DRIVERS M: Krzysztof Kozlowski <[email protected]>lib/Makefile +0
-1@@ -197,7 +197,6 @@ obj-$(CONFIG_OF_RECONFIG_NOTIFIER_ERROR_INJECT) += \ obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o obj-$(CONFIG_CODE_TAGGING) += codetag.o -obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o lib-$(CONFIG_GENERIC_BUG) += bug.omm/Makefile +1
-0@@ -147,3 +147,4 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o +obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.omm/alloc_tag.c renamed from lib/alloc_tag.c +0
-1--2.54.0
Suren Baghdasaryan
maintainerRe: [PATCH v2 11/13] alloc_tag: Move to mm/
Quoted 8 lines · Lorenzo Stoakes
Quoted 3 lines · Brendan Jackman
This is logically mm code. Moving to
mm/allows access tomm/internal.hSigned-off-by Brendan Jackman <[email protected]>Sorry to be a pain, but I feel that this change should be dealt with separately perhaps as a pre-requisite to this series.
I know you have an idea for some cleanup. Let's wait for your patch and then rebase this series over it. In the meantime I'll start reviewing the rest.
Quoted 52 lines
Thanks, Lorenzo
Quoted 49 lines
--- MAINTAINERS | 2 +- lib/Makefile | 1 - mm/Makefile | 1 + {lib => mm}/alloc_tag.c | 0 4 files changed, 2 insertions(+), 2 deletions(-)MAINTAINERS +1
-1@@ -16713,7 +16713,7 @@ S: Maintained F: Documentation/mm/allocation-profiling.rst F: include/linux/alloc_tag.h F: include/linux/pgalloc_tag.h -F: lib/alloc_tag.c +F: mm/alloc_tag.c MEMORY CONTROLLER DRIVERS M: Krzysztof Kozlowski <[email protected]>lib/Makefile +0
-1@@ -197,7 +197,6 @@ obj-$(CONFIG_OF_RECONFIG_NOTIFIER_ERROR_INJECT) += \ obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o obj-$(CONFIG_CODE_TAGGING) += codetag.o -obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.o lib-$(CONFIG_GENERIC_BUG) += bug.omm/Makefile +1
-0@@ -147,3 +147,4 @@ obj-$(CONFIG_SHRINKER_DEBUG) += shrinker_debug.o obj-$(CONFIG_EXECMEM) += execmem.o obj-$(CONFIG_TMPFS_QUOTA) += shmem_quota.o obj-$(CONFIG_LAZY_MMU_MODE_KUNIT_TEST) += tests/lazy_mmu_mode_kunit.o +obj-$(CONFIG_MEM_ALLOC_PROFILING) += alloc_tag.omm/alloc_tag.c renamed from lib/alloc_tag.c +0
-1--2.54.0
Lorenzo Stoakes
reviewerRe: [PATCH v2 11/13] alloc_tag: Move to mm/
Quoted 5 lines · Suren Baghdasaryan
Quoted 4 lines · Lorenzo Stoakes
Quoted 2 lines · Brendan Jackman
This is logically mm code. Moving to
mm/allows access tomm/internal.h
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Brendan Jackman <[email protected]>Sorry to be a pain, but I feel that this change should be dealt with separately perhaps as a pre-requisite to this series.
I know you have an idea for some cleanup. Let's wait for your patch and then rebase this series over it. In the meantime I'll start reviewing the rest.
Thanks!
Cheers, Lorenzo
PATCH v2 12/13 mm: Move __alloc_pages() to mm/internal.h
In reply to Brendan JackmanIt's no longer used outside of mm/.
Since this means __alloc_pages_noprof() is no longer visible from gfp.h, this also means moving the definition of alloc_pages_node_noprof into the .c file.
--- Documentation/admin-guide/cgroup-v1/cpusets.rst | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- include/linux/gfp.h | 16 +--------------- mm/internal.h | 4 ++++ mm/page_alloc.c | 11 +++++++++++ 5 files changed, 18 insertions(+), 17 deletions(-)
Documentation/admin-guide/cgroup-v1/cpusets.rst +1 -1
@@ -284,7 +284,7 @@ take action. ==> Unless this feature is enabled by writing "1" to the special file /dev/cpuset/memory_pressure_enabled, the hook in the rebalance - code of __alloc_pages() for this metric reduces to simply noticing + code of the page allocator for this metric reduces to simply noticing that the cpuset_memory_pressure_enabled flag is zero. So only systems that enable this feature will compute the metric.
Documentation/admin-guide/mm/transhuge.rst +1 -1
@@ -761,7 +761,7 @@ compact_fail but failed. It is possible to establish how long the stalls were using the function -tracer to record how long was spent in __alloc_pages() and +tracer to record how long was spent in the page allocator and using the mm_page_alloc tracepoint to identify which allocations were for huge pages.
include/linux/gfp.h +1 -15
@@ -226,10 +226,6 @@ static inline void arch_free_page(struct page *page, int order) { }static inline void arch_alloc_page (struct page *page,int order) { }#endif -struct page *__alloc_pages_noprof (gfp_t gfp,unsigned int order,int preferred_nid, -nodemask_t *nodemask); -#define __alloc_pages (...) alloc_hooks(__alloc_pages_noprof(__VA_ARGS__)) -struct folio *__folio_alloc_noprof (gfp_t gfp,unsigned int order,int preferred_nid,nodemask_t *nodemask);#define __folio_alloc (...) alloc_hooks(__folio_alloc_noprof(__VA_ARGS__))
@@ -294,17 +290,7 @@ struct folio *__folio_alloc_node_noprof(gfp_t gfp, unsigned int order, int nid)* prefer the current CPU's closest node. Otherwise node must be valid and * online. */ -static inline struct page *alloc_pages_node_noprof (int nid,gfp_t gfp_mask, -unsigned int order) -{ -if (nid ==NUMA_NO_NODE ) - nid =numa_mem_id (); - -VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES ); -warn_if_node_offline (nid, gfp_mask); - -return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); -} +struct page *alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order);#define alloc_pages_node (...) alloc_hooks(alloc_pages_node_noprof(__VA_ARGS__))
mm/internal.h +4 -0
@@ -1955,4 +1955,8 @@ static inline int get_sysctl_max_map_count(void)bool may_expand_vm (struct mm_struct *mm,const vma_flags_t *vma_flags,unsigned long npages); +struct page *__alloc_pages_noprof (gfp_t gfp,unsigned int order,int preferred_nid, +nodemask_t *nodemask); +#define __alloc_pages (...) alloc_hooks(__alloc_pages_noprof(__VA_ARGS__)) +#endif /* __MM_INTERNAL_H */
mm/page_alloc.c +11 -0
@@ -5410,6 +5410,17 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, }EXPORT_SYMBOL (__alloc_pages_noprof); +struct page *alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) +{ +if (nid ==NUMA_NO_NODE ) + nid =numa_mem_id (); + +VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES ); +warn_if_node_offline (nid, gfp_mask); + +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); +} +struct folio *__folio_alloc_noprof (gfp_t gfp,unsigned int order,int preferred_nid,nodemask_t *nodemask) {
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Missing EXPORT_SYMBOL for out-of-line alloc_pages_node_noprof() causes widespread module linker…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Missing EXPORT_SYMBOL for out-of-line alloc_pages_node_noprof() causes widespread module linker errors. --
commit 42f7742177beb0066c00a7aa081250feb5859171
Author: Brendan Jackman <[email protected]>
mm: Move __alloc_pages() to mm/internal.h
This commit moves the __alloc_pages() family of internal functions to mm/internal.h to restrict them to the mm subsystem. It also moves alloc_pages_node_noprof() out-of-line into mm/page_alloc.c since it depends on __alloc_pages_noprof().
Quoted 4 lines
mm/page_alloc.c +0
-0
[ ... ]
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5420
Quoted 3 lines
mm/page_alloc.c +0
-0@@ -5419,6 +5419,17 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, }EXPORT_SYMBOL (__alloc_pages_noprof);
[Severity: Low]
Since __alloc_pages_noprof() is no longer visible outside of mm/, should this EXPORT_SYMBOL be removed?
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5422
Quoted 10 lines
mm/page_alloc.c +10
-0+struct page *alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) +{ +if (nid ==NUMA_NO_NODE ) + nid =numa_mem_id (); + +VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES ); +warn_if_node_offline (nid, gfp_mask); + +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); +}
[Severity: Low]
Does this code cause module linker errors? alloc_pages_node_noprof() is called by the alloc_pages_node() macro in include/linux/gfp.h, but it does not have an EXPORT_SYMBOL.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Brendan Jackman
reviewerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
Quoted 21 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] MissingEXPORT_SYMBOLfor out-of-linealloc_pages_node_noprof()causes widespread module linker errors. --commit
42f7742177beb0066c00a7aa081250feb5859171
Author: Brendan Jackman <[email protected]>mm: Move
__alloc_pages()tomm/internal.hThis commit moves the
__alloc_pages()family of internal functions tomm/internal.hto restrict them to the mm subsystem. It also movesalloc_pages_node_noprof()out-of-line intomm/page_alloc.csince it depends on__alloc_pages_noprof().Quoted 4 lines
mm/page_alloc.c +0
-0[ ... ]
Quoted 7 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5420
Quoted 3 lines
mm/page_alloc.c +0
-0@@ -5419,6 +5419,17 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, }EXPORT_SYMBOL (__alloc_pages_noprof);[Severity: Low]
Since__alloc_pages_noprof()is no longer visible outside ofmm/, should thisEXPORT_SYMBOLbe removed?
Yep.
Quoted 7 lines
Quoted 7 lines
mm/page_alloc.c +7
-0+struct page *alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) +{ +if (nid ==NUMA_NO_NODE ) + nid =numa_mem_id (); + +VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES ); +warn_if_node_offline (nid, gfp_mask);
Quoted 8 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5422
Quoted 3 lines
mm/page_alloc.c +3
-0+ +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); +}[Severity: Low]
Does this code cause module linker errors?alloc_pages_node_noprof()is called by thealloc_pages_node()macro ininclude/linux/gfp.h, but it does not have anEXPORT_SYMBOL.
Yep. Doesn't show up in defconfig but if you set CONFIG_BLK_DEV_UBLK=m then:
ERROR: modpost: "alloc_pages_node_noprof" [drivers/block/ublk_drv.ko] undefined!
Hao Ge
reviewerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
Hi Brendan
Quoted 43 lines · Brendan Jackman
Quoted 20 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] MissingEXPORT_SYMBOLfor out-of-linealloc_pages_node_noprof()causes widespread module linker errors. --commit
42f7742177beb0066c00a7aa081250feb5859171
Author: Brendan Jackman <[email protected]>mm: Move
__alloc_pages()tomm/internal.hThis commit moves the
__alloc_pages()family of internal functions tomm/internal.hto restrict them to the mm subsystem. It also movesalloc_pages_node_noprof()out-of-line intomm/page_alloc.csince it depends on__alloc_pages_noprof().Quoted 4 lines
mm/page_alloc.c +0
-0[ ... ]
Quoted 6 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5420
Quoted 3 lines
mm/page_alloc.c +0
-0@@ -5419,6 +5419,17 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, }EXPORT_SYMBOL (__alloc_pages_noprof);[Severity: Low]
Since__alloc_pages_noprof()is no longer visible outside ofmm/, should thisEXPORT_SYMBOLbe removed?Yep.
Quoted 6 lines
Quoted 6 lines
mm/page_alloc.c +6
-0+struct page *alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) +{ +if (nid ==NUMA_NO_NODE ) + nid =numa_mem_id (); + +VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES );Quoted 8 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5422
Quoted 4 lines
mm/page_alloc.c +4
-0+warn_if_node_offline (nid, gfp_mask); + +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); +}[Severity: Low]
Does this code cause module linker errors?alloc_pages_node_noprof()is called by thealloc_pages_node()macro ininclude/linux/gfp.h, but it does not have anEXPORT_SYMBOL.
Quoted 4 lines
Yep. Doesn't show up in defconfig but if you set
CONFIG_BLK_DEV_UBLK=mthen:ERROR: modpost: "
alloc_pages_node_noprof" [drivers/block/ublk_drv.ko] undefined!
I was about to report this linker issue myself, but Sashiko caught it first.
While testing your patch on top of mm-new, I hit the exact same modpost
undefined symbol error as mentioned above:
MODPOST Module.symvers
ERROR: modpost: "alloc_pages_node_noprof" [arch/x86/kvm/kvm-intel.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [arch/x86/kvm/kvm-amd.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/gpu/drm/ttm/ttm.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/misc/sgi-xp/xpc.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/misc/sgi-gru/gru.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/amazon/ena/ena.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/amd/xgbe/amd-xgbe.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/aquantia/atlantic/atlantic.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/chelsio/cxgb4/cxgb4.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf.ko] undefined!
WARNING: modpost: suppressed 14 unresolved symbol warnings because there were too many)
I'll resolve this locally and retest the patch afterward.
Thanks
Best Regards
Hao
Brendan Jackman
reviewerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
Quoted 73 lines · Hao Ge
Hi Brendan
Quoted 43 lines · Brendan Jackman
Quoted 20 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] MissingEXPORT_SYMBOLfor out-of-linealloc_pages_node_noprof()causes widespread module linker errors. --commit
42f7742177beb0066c00a7aa081250feb5859171
Author: Brendan Jackman <[email protected]>mm: Move
__alloc_pages()tomm/internal.hThis commit moves the
__alloc_pages()family of internal functions tomm/internal.hto restrict them to the mm subsystem. It also movesalloc_pages_node_noprof()out-of-line intomm/page_alloc.csince it depends on__alloc_pages_noprof().Quoted 4 lines
mm/page_alloc.c +0
-0[ ... ]
Quoted 6 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5420
Quoted 3 lines
mm/page_alloc.c +0
-0@@ -5419,6 +5419,17 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, }EXPORT_SYMBOL (__alloc_pages_noprof);[Severity: Low]
Since__alloc_pages_noprof()is no longer visible outside ofmm/, should thisEXPORT_SYMBOLbe removed?Yep.
Quoted 6 lines
Quoted 6 lines
mm/page_alloc.c +6
-0+struct page *alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) +{ +if (nid ==NUMA_NO_NODE ) + nid =numa_mem_id (); + +VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES );Quoted 8 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5422
Quoted 4 lines
mm/page_alloc.c +4
-0+warn_if_node_offline (nid, gfp_mask); + +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); +}[Severity: Low]
Does this code cause module linker errors?alloc_pages_node_noprof()is called by thealloc_pages_node()macro ininclude/linux/gfp.h, but it does not have anEXPORT_SYMBOL.Quoted 4 lines
Yep. Doesn't show up in defconfig but if you set
CONFIG_BLK_DEV_UBLK=mthen:ERROR: modpost: "
alloc_pages_node_noprof" [drivers/block/ublk_drv.ko] undefined!I was about to report this linker issue myself, but Sashiko caught it first.
While testing your patch on top of mm-new, I hit the exact same modpost
undefined symbol error as mentioned above:
MODPOST Module.symvers
ERROR: modpost: "alloc_pages_node_noprof" [arch/x86/kvm/kvm-intel.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [arch/x86/kvm/kvm-amd.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/gpu/drm/ttm/ttm.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/misc/sgi-xp/xpc.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/misc/sgi-gru/gru.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/amazon/ena/ena.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/amd/xgbe/amd-xgbe.ko] undefined!
Quoted 8 lines
ERROR: modpost: "
alloc_pages_node_noprof" [drivers/net/ethernet/aquantia/atlantic/atlantic.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/chelsio/cxgb4/cxgb4.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf.ko] undefined!
WARNING: modpost: suppressed 14 unresolved symbol warnings because there were too many)
FWIW something like this happened on a previous patchset of mine, and someone was like "so you just sent patches without any testing huh?" so I just wanna note: I did test this (see cover letter for details) I just don't bother with modules!
Anyway, this is the 2nd time I've sent a patch that breaks the build of CONFIG_KVM_INTEL=m so I guess it's time to add a new build to my test scripts :)
Hao Ge
reviewerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
Quoted 81 lines · Brendan Jackman
Quoted 72 lines · Hao Ge
Hi Brendan
Quoted 43 lines · Brendan Jackman
Quoted 20 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] MissingEXPORT_SYMBOLfor out-of-linealloc_pages_node_noprof()causes widespread module linker errors. --commit
42f7742177beb0066c00a7aa081250feb5859171
Author: Brendan Jackman <[email protected]>mm: Move
__alloc_pages()tomm/internal.hThis commit moves the
__alloc_pages()family of internal functions tomm/internal.hto restrict them to the mm subsystem. It also movesalloc_pages_node_noprof()out-of-line intomm/page_alloc.csince it depends on__alloc_pages_noprof().Quoted 4 lines
mm/page_alloc.c +0
-0[ ... ]
Quoted 6 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5420
Quoted 3 lines
mm/page_alloc.c +0
-0@@ -5419,6 +5419,17 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, }EXPORT_SYMBOL (__alloc_pages_noprof);[Severity: Low]
Since__alloc_pages_noprof()is no longer visible outside ofmm/, should thisEXPORT_SYMBOLbe removed?Yep.
Quoted 6 lines
Quoted 6 lines
mm/page_alloc.c +6
-0+struct page *alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) +{ +if (nid ==NUMA_NO_NODE ) + nid =numa_mem_id (); + +VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES );Quoted 8 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5422
Quoted 4 lines
mm/page_alloc.c +4
-0+warn_if_node_offline (nid, gfp_mask); + +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); +}[Severity: Low]
Does this code cause module linker errors?alloc_pages_node_noprof()is called by thealloc_pages_node()macro ininclude/linux/gfp.h, but it does not have anEXPORT_SYMBOL.Quoted 4 lines
Yep. Doesn't show up in defconfig but if you set
CONFIG_BLK_DEV_UBLK=mthen:ERROR: modpost: "
alloc_pages_node_noprof" [drivers/block/ublk_drv.ko] undefined!I was about to report this linker issue myself, but Sashiko caught it first.
While testing your patch on top of mm-new, I hit the exact same modpost
undefined symbol error as mentioned above:
MODPOST Module.symvers
ERROR: modpost: "alloc_pages_node_noprof" [arch/x86/kvm/kvm-intel.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [arch/x86/kvm/kvm-amd.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/gpu/drm/ttm/ttm.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/misc/sgi-xp/xpc.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/misc/sgi-gru/gru.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/amazon/ena/ena.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/amd/xgbe/amd-xgbe.ko] undefined!Quoted 8 lines
ERROR: modpost: "
alloc_pages_node_noprof" [drivers/net/ethernet/aquantia/atlantic/atlantic.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/chelsio/cxgb4/cxgb4.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf.ko] undefined!
WARNING: modpost: suppressed 14 unresolved symbol warnings because there were too many)
Quoted 4 lines
FWIW something like this happened on a previous patchset of mine, and someone was like "so you just sent patches without any testing huh?" so I just wanna note: I did test this (see cover letter for details) I just don't bother with modules!
No worries, this is quite common. I've run into the same thing in
my own work — missing =m configs in test builds happens to everyone.
It doesn't affect my testing of this series.
Quoted 4 lines
Anyway, this is the 2nd time I've sent a patch that breaks the build of
CONFIG_KVM_INTEL=mso I guess it's time to add a new build to my test scripts :)
Suren Baghdasaryan
maintainerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
Quoted 90 lines · Hao Ge
Quoted 81 lines · Brendan Jackman
Quoted 72 lines · Hao Ge
Hi Brendan
Quoted 43 lines · Brendan Jackman
Quoted 20 lines · sashiko-bot
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] MissingEXPORT_SYMBOLfor out-of-linealloc_pages_node_noprof()causes widespread module linker errors. --commit
42f7742177beb0066c00a7aa081250feb5859171
Author: Brendan Jackman <[email protected]>mm: Move
__alloc_pages()tomm/internal.hThis commit moves the
__alloc_pages()family of internal functions tomm/internal.hto restrict them to the mm subsystem. It also movesalloc_pages_node_noprof()out-of-line intomm/page_alloc.csince it depends on__alloc_pages_noprof().Quoted 4 lines
mm/page_alloc.c +0
-0[ ... ]
Quoted 6 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5420
Quoted 3 lines
mm/page_alloc.c +0
-0@@ -5419,6 +5419,17 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, }EXPORT_SYMBOL (__alloc_pages_noprof);[Severity: Low]
Since__alloc_pages_noprof()is no longer visible outside ofmm/, should thisEXPORT_SYMBOLbe removed?Yep.
Quoted 6 lines
Quoted 6 lines
mm/page_alloc.c +6
-0+struct page *alloc_pages_node_noprof (int nid,gfp_t gfp_mask,unsigned int order) +{ +if (nid ==NUMA_NO_NODE ) + nid =numa_mem_id (); + +VM_BUG_ON (nid <0 || nid >=MAX_NUMNODES );Quoted 8 lines
mm/page_alloc.c struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order, · line 5422
Quoted 4 lines
mm/page_alloc.c +4
-0+warn_if_node_offline (nid, gfp_mask); + +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); +}[Severity: Low]
Does this code cause module linker errors?alloc_pages_node_noprof()is called by thealloc_pages_node()macro ininclude/linux/gfp.h, but it does not have anEXPORT_SYMBOL.Quoted 4 lines
Yep. Doesn't show up in defconfig but if you set
CONFIG_BLK_DEV_UBLK=mthen:ERROR: modpost: "
alloc_pages_node_noprof" [drivers/block/ublk_drv.ko] undefined!I was about to report this linker issue myself, but Sashiko caught it first.
While testing your patch on top of mm-new, I hit the exact same modpost
undefined symbol error as mentioned above:
MODPOST Module.symvers
ERROR: modpost: "alloc_pages_node_noprof" [arch/x86/kvm/kvm-intel.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [arch/x86/kvm/kvm-amd.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/gpu/drm/ttm/ttm.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/misc/sgi-xp/xpc.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/misc/sgi-gru/gru.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/amazon/ena/ena.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/amd/xgbe/amd-xgbe.ko] undefined!Quoted 8 lines
ERROR: modpost: "
alloc_pages_node_noprof" [drivers/net/ethernet/aquantia/atlantic/atlantic.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/chelsio/cxgb4/cxgb4.ko] undefined!
ERROR: modpost: "alloc_pages_node_noprof" [drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf.ko] undefined!
WARNING: modpost: suppressed 14 unresolved symbol warnings because there were too many)Quoted 4 lines
FWIW something like this happened on a previous patchset of mine, and someone was like "so you just sent patches without any testing huh?" so I just wanna note: I did test this (see cover letter for details) I just don't bother with modules!
Quoted 5 lines
No worries, this is quite common. I've run into the same thing in
my own work — missing =m configs in test builds happens to everyone.
It doesn't affect my testing of this series.
Building allmodconfig before posting the series is a good idea. I was bitten by this enough times that it's on my pre-posting checklist.
Quoted 7 lines
Quoted 6 lines
Anyway, this is the 2nd time I've sent a patch that breaks the build of
CONFIG_KVM_INTEL=mso I guess it's time to add a new build to my test scripts :)
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
In reply to Brendan JackmanQuoted 6 lines · Brendan Jackman
It's no longer used outside of
mm/.Since this means
__alloc_pages_noprof()is no longer visible fromgfp.h, this also means moving the definition ofalloc_pages_node_noprofinto the .c file.
Quoted 8 lines
Signed-off-by Brendan Jackman <[email protected]>--- Documentation/admin-guide/cgroup-v1/cpusets.rst | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- include/linux/gfp.h | 16 +--------------- mm/internal.h | 4 ++++ mm/page_alloc.c | 11 +++++++++++ 5 files changed, 18 insertions(+), 17 deletions(-)
Do we want some mm/page_alloc.h , to start splitting up mm/internal.h
Signature · 3 lines
Cheers, David
Lorenzo Stoakes
reviewerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
Quoted 16 lines · David Hildenbrand (Arm)
Quoted 6 lines · Brendan Jackman
It's no longer used outside of
mm/.Since this means
__alloc_pages_noprof()is no longer visible fromgfp.h, this also means moving the definition ofalloc_pages_node_noprofinto the .c file.Quoted 8 lines
Signed-off-by Brendan Jackman <[email protected]>--- Documentation/admin-guide/cgroup-v1/cpusets.rst | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- include/linux/gfp.h | 16 +--------------- mm/internal.h | 4 ++++ mm/page_alloc.c | 11 +++++++++++ 5 files changed, 18 insertions(+), 17 deletions(-)
Quoted 1 line
Do we want some
mm/page_alloc.h, to start splitting upmm/internal.h
Yes please!
Quoted 5 lines
--
Cheers,David
Brendan Jackman
reviewerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
In reply to David Hildenbrand (Arm)Quoted 16 lines · David Hildenbrand (Arm)
Quoted 6 lines · Brendan Jackman
It's no longer used outside of
mm/.Since this means
__alloc_pages_noprof()is no longer visible fromgfp.h, this also means moving the definition ofalloc_pages_node_noprofinto the .c file.Quoted 8 lines
Signed-off-by Brendan Jackman <[email protected]>--- Documentation/admin-guide/cgroup-v1/cpusets.rst | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- include/linux/gfp.h | 16 +--------------- mm/internal.h | 4 ++++ mm/page_alloc.c | 11 +++++++++++ 5 files changed, 18 insertions(+), 17 deletions(-)
Quoted 1 line
Do we want some
mm/page_alloc.h, to start splitting upmm/internal.h
Don't see why not, if people are on board I'm happy to do that for v3.
(I just realised I put __alloc_pages_noprof() at the bottom of the file, while it should be next to __alloc_frozen_pages etc, should fix that in case we don't end up going for the separated header).
So what would go in the new header...
- All the buddy alloc/free entry points
- ALLOC_ flags
- alloc_context
- buddy_order*(), page_is_buddy(), find_buddy_page_pfn() and __find_buddy_pfn()
- post_alloc_hook(), free_pages_prepare()
- zone_pcp_*()
- find_suitable_fallback()
- free_area_empty()
Anything else? Or anything on that list that should stay in mm/internal.h?
David Hildenbrand (Arm)
maintainerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
Quoted 37 lines · Brendan Jackman
Quoted 16 lines · David Hildenbrand (Arm)
Quoted 6 lines · Brendan Jackman
It's no longer used outside of
mm/.Since this means
__alloc_pages_noprof()is no longer visible fromgfp.h, this also means moving the definition ofalloc_pages_node_noprofinto the .c file.Quoted 8 lines
Signed-off-by Brendan Jackman <[email protected]>--- Documentation/admin-guide/cgroup-v1/cpusets.rst | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- include/linux/gfp.h | 16 +--------------- mm/internal.h | 4 ++++ mm/page_alloc.c | 11 +++++++++++ 5 files changed, 18 insertions(+), 17 deletions(-)Quoted 1 line
Do we want some
mm/page_alloc.h, to start splitting upmm/internal.hDon't see why not, if people are on board I'm happy to do that for v3.
(I just realised I put
__alloc_pages_noprof()at the bottom of the file, while it should be next to__alloc_frozen_pagesetc, should fix that in case we don't end up going for the separated header).So what would go in the new header...
- All the buddy alloc/free entry points
-ALLOC_flags
-alloc_context
- buddy_order*(),page_is_buddy(),find_buddy_page_pfn()and__find_buddy_pfn()
-post_alloc_hook(),free_pages_prepare()
- zone_pcp_*()
-find_suitable_fallback()
-free_area_empty()
Quoted 2 lines
Anything else? Or anything on that list that should stay in
mm/internal.h?
Above looks like a decent start :) Thanks!
Signature · 3 lines
Cheers, David
Vlastimil Babka (SUSE)
maintainerRe: [PATCH v2 12/13] mm: Move __alloc_pages() to mm/internal.h
Quoted 38 lines · David Hildenbrand (Arm)
Quoted 37 lines · Brendan Jackman
Quoted 16 lines · David Hildenbrand (Arm)
Quoted 6 lines · Brendan Jackman
It's no longer used outside of
mm/.Since this means
__alloc_pages_noprof()is no longer visible fromgfp.h, this also means moving the definition ofalloc_pages_node_noprofinto the .c file.Quoted 8 lines
Signed-off-by Brendan Jackman <[email protected]>--- Documentation/admin-guide/cgroup-v1/cpusets.rst | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- include/linux/gfp.h | 16 +--------------- mm/internal.h | 4 ++++ mm/page_alloc.c | 11 +++++++++++ 5 files changed, 18 insertions(+), 17 deletions(-)Quoted 1 line
Do we want some
mm/page_alloc.h, to start splitting upmm/internal.hDon't see why not, if people are on board I'm happy to do that for v3.
(I just realised I put
__alloc_pages_noprof()at the bottom of the file, while it should be next to__alloc_frozen_pagesetc, should fix that in case we don't end up going for the separated header).So what would go in the new header...
- All the buddy alloc/free entry points
-ALLOC_flags
-alloc_context
- buddy_order*(),page_is_buddy(),find_buddy_page_pfn()and__find_buddy_pfn()
-post_alloc_hook(),free_pages_prepare()
- zone_pcp_*()
-find_suitable_fallback()
-free_area_empty()
Quoted 4 lines
Quoted 2 lines
Anything else? Or anything on that list that should stay in
mm/internal.h?Above looks like a decent start :) Thanks!
Ack!
PATCH v2 13/13 mm: remove __GFP_NO_CODETAG
In reply to Brendan JackmanNow that alloc_pages has an entrypoint that allows passing alloc_flags, we can take advantage of this to start removing GFP flags that are only used for mm-internal stuff.
This requires also plumbing the alloc_flags into some more of the allocator code, in particular __alloc_pages[_noprof]() gets an alloc_flags arg to go along with its callees, and we now need to pass those flags deeper into the allocator so they can reach the alloc_tag code.
To try and keep the new ALLOC_NO_CODETAG's scope nice and narrow, don't define it in mm/internal.h, instead just define a "reserved bit" and then use that in places that don't care about what it means.
--- mm/alloc_tag.c | 18 ++++++++++-------- mm/compaction.c | 4 ++-- mm/internal.h | 8 ++++++-- mm/page_alloc.c | 42 ++++++++++++++++++++++++------------------ mm/page_frag_cache.c | 4 ++-- 5 files changed, 44 insertions(+), 32 deletions(-)
mm/alloc_tag.c +10 -8
@@ -15,6 +15,8 @@#include <linux/vmalloc.h> #include <linux/kmemleak.h> +#include "internal.h" +#define ALLOCINFO_FILE_NAME "allocinfo"#define MODULE_ALLOC_TAG_VMAP_SIZE (100000UL * sizeof(struct alloc_tag))#define SECTION_START (NAME ) (CODETAG_SECTION_START_PREFIX NAME)
@@ -785,16 +787,15 @@ struct pfn_pool { sizeof(unsigned long))/* -* Skip early PFN recording for a page allocation. Reuses the -* %__GFP_NO_OBJ_EXT bit. Used by __alloc_tag_add_early_pfn() to avoid -* recursion when allocating pages for the early PFN tracking list -* itself. +* Skip early PFN recording for a page allocation. Used by +* __alloc_tag_add_early_pfn() to avoid recursion when allocating pages for the +* early PFN tracking list itself. * * Codetags of the pages allocated with __GFP_NO_CODETAG should be * cleared (via clear_page_tag_ref()) before freeing the pages to prevent * alloc_tag_sub_check() from triggering a warning. */ -#define __GFP_NO_CODETAG __GFP_NO_OBJ_EXT +#define ALLOC_NO_CODETAG __ALLOC_ALLOC_TAGstatic struct pfn_pool *current_pfn_pool__initdata ;
@@ -806,7 +807,8 @@ static void __init __alloc_tag_add_early_pfn(unsigned long pfn) do { pool = READ_ONCE(current_pfn_pool); if (!pool || atomic_read(&pool->count) >= PFN_POOL_SIZE) { - struct page *new_page = alloc_page(__GFP_HIGH | __GFP_NO_CODETAG); + struct page *new_page = __alloc_pages(__GFP_HIGH, 0, numa_mem_id(), + NULL, ALLOC_NO_CODETAG); struct pfn_pool *new; if (!new_page) {
@@ -837,7 +839,7 @@ typedef void alloc_tag_add_func(unsigned long pfn);static alloc_tag_add_func __rcu *alloc_tag_add_early_pfn_ptr__refdata =RCU_INITIALIZER (__alloc_tag_add_early_pfn); -void alloc_tag_add_early_pfn (unsigned long pfn,gfp_t gfp_flags) +void alloc_tag_add_early_pfn (unsigned long pfn,unsigned int alloc_flags) {alloc_tag_add_func *alloc_tag_add;
@@ -845,7 +847,7 @@ void alloc_tag_add_early_pfn(unsigned long pfn, gfp_t gfp_flags)return ;/* Skip allocations for the tracking list itself to avoid recursion. */ -if (gfp_flags & __GFP_NO_CODETAG) +if (alloc_flags &ALLOC_NO_CODETAG )return ;rcu_read_lock ();
mm/compaction.c +2 -2
@@ -82,7 +82,7 @@ static inline bool is_via_compact_memory(int order) { return false; }static struct page *mark_allocated_noprof (struct page *page,unsigned int order,gfp_t gfp_flags) { -post_alloc_hook (page, order, __GFP_MOVABLE); +post_alloc_hook (page, order, __GFP_MOVABLE,ALLOC_DEFAULT );set_page_refcounted (page);return page; }
@@ -1850,7 +1850,7 @@ static struct folio *compaction_alloc_noprof(struct folio *src, unsigned long da } dst = (struct folio *)freepage; -post_alloc_hook (&dst->page, order, __GFP_MOVABLE); +post_alloc_hook (&dst->page, order, __GFP_MOVABLE,ALLOC_DEFAULT );set_page_refcounted (&dst->page);if (order)prep_compound_page (&dst->page, order);
mm/internal.h +6 -2
@@ -684,6 +684,8 @@ struct alloc_context {*/ enum zone_type highest_zoneidx;bool spread_dirty_pages; +/* Only flags that are global to the whole allocation go here. */ +unsigned int alloc_flags; };/*
@@ -907,7 +909,8 @@ static inline void init_compound_tail(struct page *tail,prep_compound_tail (tail, head, order); } -void post_alloc_hook (struct page *page,unsigned int order,gfp_t gfp_flags); +void post_alloc_hook (struct page *page,unsigned int order,gfp_t gfp_flags, +unsigned int alloc_flags);extern bool free_pages_prepare (struct page *page,unsigned int order);extern int user_min_free_kbytes;
@@ -1481,6 +1484,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,#define ALLOC_HIGHATOMIC 0x200/* Allows access to MIGRATE_HIGHATOMIC */ #define ALLOC_NOLOCK 0x400/* Only use spin_trylock in allocation path */ #define ALLOC_KSWAPD 0x800/* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */ +#define __ALLOC_ALLOC_TAG 0x1000/* Reserved bit for use by alloc_tag code */ /* Flags that allow allocations below the min watermark. */ #define ALLOC_RESERVES (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM)
@@ -1956,7 +1960,7 @@ bool may_expand_vm(struct mm_struct *mm, const vma_flags_t *vma_flags, unsigned long npages);struct page *__alloc_pages_noprof (gfp_t gfp,unsigned int order,int preferred_nid, -nodemask_t *nodemask); +nodemask_t *nodemask,unsigned int alloc_flags);#define __alloc_pages (...) alloc_hooks(__alloc_pages_noprof(__VA_ARGS__))#endif /* __MM_INTERNAL_H */
mm/page_alloc.c +24 -18
141 lines not on this page · raw message
mm/page_frag_cache.c +2 -2
@@ -57,10 +57,10 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC; page =__alloc_pages (gfp_mask,PAGE_FRAG_CACHE_MAX_ORDER , -numa_mem_id (),NULL ); +numa_mem_id (),NULL ,ALLOC_DEFAULT );#endif if (unlikely (!page)) { - page =__alloc_pages (gfp,0 ,numa_mem_id (),NULL ); + page =__alloc_pages (gfp,0 ,numa_mem_id (),NULL ,ALLOC_DEFAULT ); order =0 ; }
Signature · 1 line
2.54.0
Hao Ge
reviewerRe: [PATCH v2 13/13] mm: remove __GFP_NO_CODETAG
Hi Brendan
Quoted 10 lines · Brendan Jackman
Now that
alloc_pageshas an entrypoint that allows passingalloc_flags, we can take advantage of this to start removing GFP flags that are only used for mm-internal stuff.This requires also plumbing the
alloc_flagsinto some more of the allocator code, in particular __alloc_pages[_noprof]() gets analloc_flagsarg to go along with its callees, and we now need to pass those flags deeper into the allocator so they can reach thealloc_tagcode.
Quoted 5 lines
To try and keep the new ALLOC_NO_CODETAG's scope nice and narrow, don't define it in
mm/internal.h, instead just define a "reserved bit" and then use that in places that don't care about what it means.Signed-off-by Brendan Jackman <[email protected]>
Nit: The title says "remove __GFP_NO_CODETAG" but the flag isn't really removed — it's migrated from gfp_t to alloc_flags as
ALLOC_NO_CODETAG. Something like "mm: replace __GFP_NO_CODETAG with an alloc_flag" would be more accurate.
Additionally, as Lorenzo pointed out in another thread, you will likely need to rebase this series later.
I noticed Vlastimil has already landed the slab changes removing __GFP_NO_OBJ_EXT into mainline:
For v3, it might make sense to fold in Vlastimil's patch so the full removal of __GFP_NO_OBJ_EXT can be completed end-to-end
https://lore.kernel.org/all/[email protected]/
Quoted 53 lines
--- mm/alloc_tag.c | 18 ++++++++++-------- mm/compaction.c | 4 ++-- mm/internal.h | 8 ++++++-- mm/page_alloc.c | 42 ++++++++++++++++++++++++------------------ mm/page_frag_cache.c | 4 ++-- 5 files changed, 44 insertions(+), 32 deletions(-)mm/alloc_tag.c +8
-6@@ -15,6 +15,8 @@#include <linux/vmalloc.h> #include <linux/kmemleak.h> +#include "internal.h" +#define ALLOCINFO_FILE_NAME "allocinfo"#define MODULE_ALLOC_TAG_VMAP_SIZE (100000UL * sizeof(struct alloc_tag))#define SECTION_START (NAME ) (CODETAG_SECTION_START_PREFIX NAME)@@ -785,16 +787,15 @@ struct pfn_pool { sizeof(unsigned long))/* -* Skip early PFN recording for a page allocation. Reuses the -* %__GFP_NO_OBJ_EXT bit. Used by __alloc_tag_add_early_pfn() to avoid -* recursion when allocating pages for the early PFN tracking list -* itself. +* Skip early PFN recording for a page allocation. Used by +* __alloc_tag_add_early_pfn() to avoid recursion when allocating pages for the +* early PFN tracking list itself. * * Codetags of the pages allocated with __GFP_NO_CODETAG should be * cleared (via clear_page_tag_ref()) before freeing the pages to prevent * alloc_tag_sub_check() from triggering a warning. */ -#define __GFP_NO_CODETAG __GFP_NO_OBJ_EXT +#define ALLOC_NO_CODETAG __ALLOC_ALLOC_TAGstatic struct pfn_pool *current_pfn_pool__initdata ;@@ -806,7 +807,8 @@ static void __init __alloc_tag_add_early_pfn(unsigned long pfn) do { pool = READ_ONCE(current_pfn_pool); if (!pool || atomic_read(&pool->count) >= PFN_POOL_SIZE) { - struct page *new_page = alloc_page(__GFP_HIGH | __GFP_NO_CODETAG); + struct page *new_page = __alloc_pages(__GFP_HIGH, 0, numa_mem_id(), + NULL, ALLOC_NO_CODETAG); struct pfn_pool *new; if (!new_page) {
mm/alloc_tag.c typedef void alloc_tag_add_func(unsigned long pfn); · line 842
Quoted 5 lines
mm/alloc_tag.c +1
-1@@ -837,7 +839,7 @@ typedef void alloc_tag_add_func(unsigned long pfn);static alloc_tag_add_func __rcu *alloc_tag_add_early_pfn_ptr__refdata =RCU_INITIALIZER (__alloc_tag_add_early_pfn); -void alloc_tag_add_early_pfn (unsigned long pfn,gfp_t gfp_flags) +void alloc_tag_add_early_pfn (unsigned long pfn,unsigned int alloc_flags)
alloc_tag_add_early_pfn is actually declared in include/linux/alloc_tag.h,
so we need to update this header in sync as well.
include/linux/alloc_tag.h:166:void alloc_tag_add_early_pfn(unsigned long pfn, gfp_t gfp_flags); include/linux/alloc_tag.h:170:static inline void alloc_tag_add_early_pfn(unsigned long pfn, gfp_t gfp_flags) {}
Quoted 91 lines
mm/alloc_tag.c +1
-1{alloc_tag_add_func *alloc_tag_add;@@ -845,7 +847,7 @@ void alloc_tag_add_early_pfn(unsigned long pfn, gfp_t gfp_flags)return ;/* Skip allocations for the tracking list itself to avoid recursion. */ -if (gfp_flags & __GFP_NO_CODETAG) +if (alloc_flags &ALLOC_NO_CODETAG )return ;rcu_read_lock ();mm/compaction.c +2
-2@@ -82,7 +82,7 @@ static inline bool is_via_compact_memory(int order) { return false; }static struct page *mark_allocated_noprof (struct page *page,unsigned int order,gfp_t gfp_flags) { -post_alloc_hook (page, order, __GFP_MOVABLE); +post_alloc_hook (page, order, __GFP_MOVABLE,ALLOC_DEFAULT );set_page_refcounted (page);return page; }@@ -1850,7 +1850,7 @@ static struct folio *compaction_alloc_noprof(struct folio *src, unsigned long da } dst = (struct folio *)freepage; -post_alloc_hook (&dst->page, order, __GFP_MOVABLE); +post_alloc_hook (&dst->page, order, __GFP_MOVABLE,ALLOC_DEFAULT );set_page_refcounted (&dst->page);if (order)prep_compound_page (&dst->page, order);mm/internal.h +6
-2@@ -684,6 +684,8 @@ struct alloc_context {*/ enum zone_type highest_zoneidx;bool spread_dirty_pages; +/* Only flags that are global to the whole allocation go here. */ +unsigned int alloc_flags; };/* @@ -907,7 +909,8 @@ static inline void init_compound_tail(struct page *tail,prep_compound_tail (tail, head, order); } -void post_alloc_hook (struct page *page,unsigned int order,gfp_t gfp_flags); +void post_alloc_hook (struct page *page,unsigned int order,gfp_t gfp_flags, +unsigned int alloc_flags);extern bool free_pages_prepare (struct page *page,unsigned int order);extern int user_min_free_kbytes;@@ -1481,6 +1484,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,#define ALLOC_HIGHATOMIC 0x200/* Allows access to MIGRATE_HIGHATOMIC */ #define ALLOC_NOLOCK 0x400/* Only use spin_trylock in allocation path */ #define ALLOC_KSWAPD 0x800/* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */ +#define __ALLOC_ALLOC_TAG 0x1000/* Reserved bit for use by alloc_tag code */ /* Flags that allow allocations below the min watermark. */ #define ALLOC_RESERVES (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM)@@ -1956,7 +1960,7 @@ bool may_expand_vm(struct mm_struct *mm, const vma_flags_t *vma_flags, unsigned long npages);struct page *__alloc_pages_noprof (gfp_t gfp,unsigned int order,int preferred_nid, -nodemask_t *nodemask); +nodemask_t *nodemask,unsigned int alloc_flags);#define __alloc_pages (...) alloc_hooks(__alloc_pages_noprof(__VA_ARGS__))#endif /* __MM_INTERNAL_H */ mm/page_alloc.c +1
-1@@ -1246,7 +1246,7 @@ void __clear_page_tag_ref(struct page *page)/* Should be called only if mem_alloc_profiling_enabled() */ static noinline void __pgalloc_tag_add(struct page *page, struct task_struct *task, -unsigned int nr,gfp_t gfp_flags) +unsigned int nr,unsigned int alloc_flags) {union pgtag_ref_handle handle;union codetag_ref ref;@@ -1260,17 +1260,17 @@ void __pgalloc_tag_add(struct page *page, struct task_struct *task,* page_ext is not available yet, record the pfn so we can * clear the tag ref later when page_ext is initialized. */
mm/page_alloc.c void __pgalloc_tag_add(struct page *page, struct task_struct *task, · line 1270
Quoted 10 lines
mm/page_alloc.c +2
-2-alloc_tag_add_early_pfn (page_to_pfn (page), gfp_flags); +alloc_tag_add_early_pfn (page_to_pfn (page), alloc_flags);if (task->alloc_tag)alloc_tag_set_inaccurate (task->alloc_tag); } }static inline void pgalloc_tag_add (struct page *page,struct task_struct *task, -unsigned int nr,gfp_t gfp_flags) +unsigned int nr,unsigned int alloc_flags)
The pgalloc_tag_add() stub in the non-CONFIG_MEM_ALLOC_PROFILING build could use the same parameter types for consistency
Thanks
Best Regards
Hao
Quoted 148 lines
mm/page_alloc.c +21
-15{if (mem_alloc_profiling_enabled ()) -__pgalloc_tag_add (page, task, nr, gfp_flags); +__pgalloc_tag_add (page, task, nr, alloc_flags); }/* Should be called only if mem_alloc_profiling_enabled() */ @@ -1807,7 +1807,7 @@ static inline bool should_skip_init(gfp_t flags) }inline void post_alloc_hook (struct page *page,unsigned int order, -gfp_t gfp_flags) +gfp_t gfp_flags,unsigned int alloc_flags) {const bool zero_tags = gfp_flags & __GFP_ZEROTAGS; bool init = !want_init_on_free() && want_init_on_alloc(gfp_flags) &&@@ -1858,13 +1858,13 @@ inline void post_alloc_hook(struct page *page, unsigned int order,set_page_owner (page, order, gfp_flags);page_table_check_alloc (page, order); -pgalloc_tag_add (page, current,1 << order, gfp_flags); +pgalloc_tag_add (page, current,1 << order, alloc_flags); }static void prep_new_page (struct page *page,unsigned int order,gfp_t gfp_flags,unsigned int alloc_flags) { -post_alloc_hook (page, order, gfp_flags); +post_alloc_hook (page, order, gfp_flags, alloc_flags);if (order && (gfp_flags & __GFP_COMP))prep_compound_page (page, order);@@ -4773,8 +4773,12 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,* The fast path uses conservative alloc_flags to succeed only until * kswapd needs to be woken up, and to avoid the cost of setting up * alloc_flags precisely. So we do that now. +* +* Can't just or alloc_flags if it contains WMARK bits, but those flags +* shouldn't be set in ac->alloc_flags. */ - alloc_flags =slowpath_alloc_flags (gfp_mask, order); +VM_WARN_ON (ac->alloc_flags &ALLOC_WMARK_MASK ); + alloc_flags = ac->alloc_flags |slowpath_alloc_flags (gfp_mask, order);/* * We need to recalculate the starting point for the zonelist iterator @@ -4816,7 +4820,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, reserve_flags =__gfp_pfmemalloc_flags (gfp_mask);if (reserve_flags) alloc_flags =cma_alloc_flags (gfp_mask, reserve_flags) | - (alloc_flags &ALLOC_KSWAPD ); + ac->alloc_flags | (alloc_flags &ALLOC_KSWAPD );/* * Reset the nodemask and zonelist iterators if memory policies can be @@ -5218,7 +5222,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,return nr_populated; failed: - page =__alloc_pages_noprof (gfp,0 , preferred_nid, nodemask); + page =__alloc_pages_noprof (gfp,0 , preferred_nid, nodemask,ALLOC_DEFAULT );if (page) page_array[nr_populated++] = page; goto out;@@ -5326,11 +5330,13 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, {struct page *page;gfp_t alloc_gfp;/* The gfp_t that was actually used for allocation */ -struct alloc_context ac = { }; +struct alloc_context ac = { + .alloc_flags = alloc_flags, + };unsigned int fastpath_alloc_flags = alloc_flags;/* Other flags could be supported later if needed. */ -if (WARN_ON (alloc_flags & ~ALLOC_NOLOCK )) +if (WARN_ON (alloc_flags & ~(ALLOC_NOLOCK | __ALLOC_ALLOC_TAG)))return NULL ;if (!alloc_order_allowed (gfp, order, alloc_flags))@@ -5398,12 +5404,12 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,EXPORT_SYMBOL (__alloc_frozen_pages_noprof);struct page *__alloc_pages_noprof (gfp_t gfp,unsigned int order, -int preferred_nid,nodemask_t *nodemask) +int preferred_nid,nodemask_t *nodemask,unsigned int alloc_flags) {struct page *page; page =__alloc_frozen_pages_noprof (gfp, order, preferred_nid, nodemask, -ALLOC_DEFAULT ); + alloc_flags);if (page)set_page_refcounted (page);return page;@@ -5418,14 +5424,14 @@ struct page *alloc_pages_node_noprof(int nid, gfp_t gfp_mask, unsigned int orderVM_BUG_ON (nid <0 || nid >=MAX_NUMNODES );warn_if_node_offline (nid, gfp_mask); -return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ,ALLOC_DEFAULT ); }struct folio *__folio_alloc_noprof (gfp_t gfp,unsigned int order,int preferred_nid,nodemask_t *nodemask) {struct page *page =__alloc_pages_noprof (gfp | __GFP_COMP, order, - preferred_nid, nodemask); + preferred_nid, nodemask,ALLOC_DEFAULT );return page_rmappable_folio (page); }EXPORT_SYMBOL (__folio_alloc_noprof);@@ -7107,7 +7113,7 @@ static void split_free_frozen_pages(struct list_head *list, gfp_t gfp_mask)list_for_each_entry_safe (page, next, &list[order], lru) {int i; -post_alloc_hook (page, order, gfp_mask); +post_alloc_hook (page, order, gfp_mask,ALLOC_DEFAULT );if (!order)continue ;@@ -7312,7 +7318,7 @@ int alloc_contig_frozen_range_noprof(unsigned long start, unsigned long end,struct page *head =pfn_to_page (start);check_new_pages (head, order); -prep_new_page (head, order, gfp_mask,0 ); +prep_new_page (head, order, gfp_mask,ALLOC_DEFAULT ); }else { ret = -EINVAL ; WARN(true, "PFN range: requested [%lu, %lu), allocated [%lu, %lu)\n",mm/page_frag_cache.c +2
-2@@ -57,10 +57,10 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC; page =__alloc_pages (gfp_mask,PAGE_FRAG_CACHE_MAX_ORDER , -numa_mem_id (),NULL ); +numa_mem_id (),NULL ,ALLOC_DEFAULT );#endif if (unlikely (!page)) { - page =__alloc_pages (gfp,0 ,numa_mem_id (),NULL ); + page =__alloc_pages (gfp,0 ,numa_mem_id (),NULL ,ALLOC_DEFAULT ); order =0 ; }
Brendan Jackman
reviewerRe: [PATCH v2 13/13] mm: remove __GFP_NO_CODETAG
Quoted 18 lines · Hao Ge
Hi Brendan
Quoted 14 lines · Brendan Jackman
Now that
alloc_pageshas an entrypoint that allows passingalloc_flags, we can take advantage of this to start removing GFP flags that are only used for mm-internal stuff.This requires also plumbing the
alloc_flagsinto some more of the allocator code, in particular __alloc_pages[_noprof]() gets analloc_flagsarg to go along with its callees, and we now need to pass those flags deeper into the allocator so they can reach thealloc_tagcode.To try and keep the new ALLOC_NO_CODETAG's scope nice and narrow, don't define it in
mm/internal.h, instead just define a "reserved bit" and then use that in places that don't care about what it means.
Quoted 8 lines
Quoted 1 line
Signed-off-by Brendan Jackman <[email protected]>Nit: The title says "remove
__GFP_NO_CODETAG" but the flag isn't really removed — it's migrated fromgfp_ttoalloc_flagsas
ALLOC_NO_CODETAG. Something like "mm: replace__GFP_NO_CODETAGwith analloc_flag" would be more accurate.
Good point, will reword this.
Quoted 6 lines
Additionally, as Lorenzo pointed out in another thread, you will likely need to rebase this series later.
I noticed Vlastimil has already landed the slab changes removing
__GFP_NO_OBJ_EXTinto mainline:
Quoted 6 lines
For v3, it might make sense to fold in Vlastimil's patch so the full removal of
__GFP_NO_OBJ_EXTcan be completed end-to-end
Ack, thanks for the links and review!
Suren Baghdasaryan
maintainerRe: [PATCH v2 13/13] mm: remove __GFP_NO_CODETAG
In reply to Hao GeQuoted 18 lines · Hao Ge
Hi Brendan
Quoted 13 lines · Brendan Jackman
Now that
alloc_pageshas an entrypoint that allows passingalloc_flags, we can take advantage of this to start removing GFP flags that are only used for mm-internal stuff.This requires also plumbing the
alloc_flagsinto some more of the allocator code, in particular __alloc_pages[_noprof]() gets analloc_flagsarg to go along with its callees, and we now need to pass those flags deeper into the allocator so they can reach thealloc_tagcode.To try and keep the new ALLOC_NO_CODETAG's scope nice and narrow, don't define it in
mm/internal.h, instead just define a "reserved bit" and then use that in places that don't care about what it means.
I don't understand why you want to narrow down visibility of one of the alloc_flag bits. We don't do that for any other flags, and this seems like an unnecessary complexity.
Quoted 17 lines
Quoted 2 lines
Signed-off-by Brendan Jackman <[email protected]>Nit: The title says "remove
__GFP_NO_CODETAG" but the flag isn't really removed — it's migrated fromgfp_ttoalloc_flagsas
ALLOC_NO_CODETAG. Something like "mm: replace__GFP_NO_CODETAGwith analloc_flag" would be more accurate.Additionally, as Lorenzo pointed out in another thread, you will likely need to rebase this series later.
I noticed Vlastimil has already landed the slab changes removing
__GFP_NO_OBJ_EXTinto mainline:
Quoted 6 lines
For v3, it might make sense to fold in Vlastimil's patch so the full removal of
__GFP_NO_OBJ_EXTcan be completed end-to-end
I think Vlastimil's patch will be merged before this one, so this patch could remove __GFP_NO_OBJ_EXT complely, saying that its last user (__GFP_NO_CODETAG) is gone.
Quoted 170 lines
Quoted 55 lines
--- mm/alloc_tag.c | 18 ++++++++++-------- mm/compaction.c | 4 ++-- mm/internal.h | 8 ++++++-- mm/page_alloc.c | 42 ++++++++++++++++++++++++------------------ mm/page_frag_cache.c | 4 ++-- 5 files changed, 44 insertions(+), 32 deletions(-)mm/alloc_tag.c +8
-6@@ -15,6 +15,8 @@#include <linux/vmalloc.h> #include <linux/kmemleak.h> +#include "internal.h" +#define ALLOCINFO_FILE_NAME "allocinfo"#define MODULE_ALLOC_TAG_VMAP_SIZE (100000UL * sizeof(struct alloc_tag))#define SECTION_START (NAME ) (CODETAG_SECTION_START_PREFIX NAME)@@ -785,16 +787,15 @@ struct pfn_pool { sizeof(unsigned long))/* -* Skip early PFN recording for a page allocation. Reuses the -* %__GFP_NO_OBJ_EXT bit. Used by __alloc_tag_add_early_pfn() to avoid -* recursion when allocating pages for the early PFN tracking list -* itself. +* Skip early PFN recording for a page allocation. Used by +* __alloc_tag_add_early_pfn() to avoid recursion when allocating pages for the +* early PFN tracking list itself. * * Codetags of the pages allocated with __GFP_NO_CODETAG should be * cleared (via clear_page_tag_ref()) before freeing the pages to prevent * alloc_tag_sub_check() from triggering a warning. */ -#define __GFP_NO_CODETAG __GFP_NO_OBJ_EXT +#define ALLOC_NO_CODETAG __ALLOC_ALLOC_TAGstatic struct pfn_pool *current_pfn_pool__initdata ;@@ -806,7 +807,8 @@ static void __init __alloc_tag_add_early_pfn(unsigned long pfn) do { pool = READ_ONCE(current_pfn_pool); if (!pool || atomic_read(&pool->count) >= PFN_POOL_SIZE) { - struct page *new_page = alloc_page(__GFP_HIGH | __GFP_NO_CODETAG); + struct page *new_page = __alloc_pages(__GFP_HIGH, 0, numa_mem_id(), + NULL, ALLOC_NO_CODETAG); struct pfn_pool *new; if (!new_page) {mm/alloc_tag.c typedef void alloc_tag_add_func(unsigned long pfn); · line 842
Quoted 5 lines
mm/alloc_tag.c +1
-1@@ -837,7 +839,7 @@ typedef void alloc_tag_add_func(unsigned long pfn);static alloc_tag_add_func __rcu *alloc_tag_add_early_pfn_ptr__refdata =RCU_INITIALIZER (__alloc_tag_add_early_pfn); -void alloc_tag_add_early_pfn (unsigned long pfn,gfp_t gfp_flags) +void alloc_tag_add_early_pfn (unsigned long pfn,unsigned int alloc_flags)
alloc_tag_add_early_pfnis actually declared ininclude/linux/alloc_tag.h,so we need to update this header in sync as well.
include/linux/alloc_tag.h:166:void
alloc_tag_add_early_pfn(unsigned long pfn, gfp_t gfp_flags);
include/linux/alloc_tag.h:170:static inline voidalloc_tag_add_early_pfn(unsigned long pfn, gfp_t gfp_flags){}Quoted 98 lines
mm/alloc_tag.c +1
-1{alloc_tag_add_func *alloc_tag_add;@@ -845,7 +847,7 @@ void alloc_tag_add_early_pfn(unsigned long pfn, gfp_t gfp_flags)return ;/* Skip allocations for the tracking list itself to avoid recursion. */ -if (gfp_flags & __GFP_NO_CODETAG) +if (alloc_flags &ALLOC_NO_CODETAG )return ;rcu_read_lock ();mm/compaction.c +2
-2@@ -82,7 +82,7 @@ static inline bool is_via_compact_memory(int order) { return false; }static struct page *mark_allocated_noprof (struct page *page,unsigned int order,gfp_t gfp_flags) { -post_alloc_hook (page, order, __GFP_MOVABLE); +post_alloc_hook (page, order, __GFP_MOVABLE,ALLOC_DEFAULT );set_page_refcounted (page);return page; }@@ -1850,7 +1850,7 @@ static struct folio *compaction_alloc_noprof(struct folio *src, unsigned long da } dst = (struct folio *)freepage; -post_alloc_hook (&dst->page, order, __GFP_MOVABLE); +post_alloc_hook (&dst->page, order, __GFP_MOVABLE,ALLOC_DEFAULT );set_page_refcounted (&dst->page);if (order)prep_compound_page (&dst->page, order);mm/internal.h +6
-2@@ -684,6 +684,8 @@ struct alloc_context {*/ enum zone_type highest_zoneidx;bool spread_dirty_pages; +/* Only flags that are global to the whole allocation go here. */ +unsigned int alloc_flags; };/* @@ -907,7 +909,8 @@ static inline void init_compound_tail(struct page *tail,prep_compound_tail (tail, head, order); } -void post_alloc_hook (struct page *page,unsigned int order,gfp_t gfp_flags); +void post_alloc_hook (struct page *page,unsigned int order,gfp_t gfp_flags, +unsigned int alloc_flags);extern bool free_pages_prepare (struct page *page,unsigned int order);extern int user_min_free_kbytes;@@ -1481,6 +1484,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone,#define ALLOC_HIGHATOMIC 0x200/* Allows access to MIGRATE_HIGHATOMIC */ #define ALLOC_NOLOCK 0x400/* Only use spin_trylock in allocation path */ #define ALLOC_KSWAPD 0x800/* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */ +#define __ALLOC_ALLOC_TAG 0x1000/* Reserved bit for use by alloc_tag code */ /* Flags that allow allocations below the min watermark. */ #define ALLOC_RESERVES (ALLOC_NON_BLOCK|ALLOC_MIN_RESERVE|ALLOC_HIGHATOMIC|ALLOC_OOM)@@ -1956,7 +1960,7 @@ bool may_expand_vm(struct mm_struct *mm, const vma_flags_t *vma_flags, unsigned long npages);struct page *__alloc_pages_noprof (gfp_t gfp,unsigned int order,int preferred_nid, -nodemask_t *nodemask); +nodemask_t *nodemask,unsigned int alloc_flags);#define __alloc_pages (...) alloc_hooks(__alloc_pages_noprof(__VA_ARGS__))#endif /* __MM_INTERNAL_H */ mm/page_alloc.c +2
-2@@ -1246,7 +1246,7 @@ void __clear_page_tag_ref(struct page *page)/* Should be called only if mem_alloc_profiling_enabled() */ static noinline void __pgalloc_tag_add(struct page *page, struct task_struct *task, -unsigned int nr,gfp_t gfp_flags) +unsigned int nr,unsigned int alloc_flags) {union pgtag_ref_handle handle;union codetag_ref ref;@@ -1260,17 +1260,17 @@ void __pgalloc_tag_add(struct page *page, struct task_struct *task,* page_ext is not available yet, record the pfn so we can * clear the tag ref later when page_ext is initialized. */ -alloc_tag_add_early_pfn (page_to_pfn (page), gfp_flags); +alloc_tag_add_early_pfn (page_to_pfn (page), alloc_flags);if (task->alloc_tag)alloc_tag_set_inaccurate (task->alloc_tag); } }
Quoted 7 lines
mm/page_alloc.c void __pgalloc_tag_add(struct page *page, struct task_struct *task, · line 1270
Quoted 3 lines
mm/page_alloc.c +1
-1static inline void pgalloc_tag_add (struct page *page,struct task_struct *task, -unsigned int nr,gfp_t gfp_flags) +unsigned int nr,unsigned int alloc_flags)The
pgalloc_tag_add()stub in the non-CONFIG_MEM_ALLOC_PROFILING build could use the same parameter types for consistency
Umm, correction. It *should* use the same parameter type. It's unfortunate that the compiler doesn't catch this...
Quoted 157 lines
Thanks
Best Regards
Hao
Quoted 148 lines
mm/page_alloc.c +21
-15{if (mem_alloc_profiling_enabled ()) -__pgalloc_tag_add (page, task, nr, gfp_flags); +__pgalloc_tag_add (page, task, nr, alloc_flags); }/* Should be called only if mem_alloc_profiling_enabled() */ @@ -1807,7 +1807,7 @@ static inline bool should_skip_init(gfp_t flags) }inline void post_alloc_hook (struct page *page,unsigned int order, -gfp_t gfp_flags) +gfp_t gfp_flags,unsigned int alloc_flags) {const bool zero_tags = gfp_flags & __GFP_ZEROTAGS; bool init = !want_init_on_free() && want_init_on_alloc(gfp_flags) &&@@ -1858,13 +1858,13 @@ inline void post_alloc_hook(struct page *page, unsigned int order,set_page_owner (page, order, gfp_flags);page_table_check_alloc (page, order); -pgalloc_tag_add (page, current,1 << order, gfp_flags); +pgalloc_tag_add (page, current,1 << order, alloc_flags); }static void prep_new_page (struct page *page,unsigned int order,gfp_t gfp_flags,unsigned int alloc_flags) { -post_alloc_hook (page, order, gfp_flags); +post_alloc_hook (page, order, gfp_flags, alloc_flags);if (order && (gfp_flags & __GFP_COMP))prep_compound_page (page, order);@@ -4773,8 +4773,12 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,* The fast path uses conservative alloc_flags to succeed only until * kswapd needs to be woken up, and to avoid the cost of setting up * alloc_flags precisely. So we do that now. +* +* Can't just or alloc_flags if it contains WMARK bits, but those flags +* shouldn't be set in ac->alloc_flags. */ - alloc_flags =slowpath_alloc_flags (gfp_mask, order); +VM_WARN_ON (ac->alloc_flags &ALLOC_WMARK_MASK ); + alloc_flags = ac->alloc_flags |slowpath_alloc_flags (gfp_mask, order);/* * We need to recalculate the starting point for the zonelist iterator @@ -4816,7 +4820,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, reserve_flags =__gfp_pfmemalloc_flags (gfp_mask);if (reserve_flags) alloc_flags =cma_alloc_flags (gfp_mask, reserve_flags) | - (alloc_flags &ALLOC_KSWAPD ); + ac->alloc_flags | (alloc_flags &ALLOC_KSWAPD );/* * Reset the nodemask and zonelist iterators if memory policies can be @@ -5218,7 +5222,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,return nr_populated; failed: - page =__alloc_pages_noprof (gfp,0 , preferred_nid, nodemask); + page =__alloc_pages_noprof (gfp,0 , preferred_nid, nodemask,ALLOC_DEFAULT );if (page) page_array[nr_populated++] = page; goto out;@@ -5326,11 +5330,13 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, {struct page *page;gfp_t alloc_gfp;/* The gfp_t that was actually used for allocation */ -struct alloc_context ac = { }; +struct alloc_context ac = { + .alloc_flags = alloc_flags, + };unsigned int fastpath_alloc_flags = alloc_flags;/* Other flags could be supported later if needed. */ -if (WARN_ON (alloc_flags & ~ALLOC_NOLOCK )) +if (WARN_ON (alloc_flags & ~(ALLOC_NOLOCK | __ALLOC_ALLOC_TAG)))return NULL ;if (!alloc_order_allowed (gfp, order, alloc_flags))@@ -5398,12 +5404,12 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,EXPORT_SYMBOL (__alloc_frozen_pages_noprof);struct page *__alloc_pages_noprof (gfp_t gfp,unsigned int order, -int preferred_nid,nodemask_t *nodemask) +int preferred_nid,nodemask_t *nodemask,unsigned int alloc_flags) {struct page *page; page =__alloc_frozen_pages_noprof (gfp, order, preferred_nid, nodemask, -ALLOC_DEFAULT ); + alloc_flags);if (page)set_page_refcounted (page);return page;@@ -5418,14 +5424,14 @@ struct page *alloc_pages_node_noprof(int nid, gfp_t gfp_mask, unsigned int orderVM_BUG_ON (nid <0 || nid >=MAX_NUMNODES );warn_if_node_offline (nid, gfp_mask); -return __alloc_pages_noprof (gfp_mask, order, nid,NULL ); +return __alloc_pages_noprof (gfp_mask, order, nid,NULL ,ALLOC_DEFAULT ); }struct folio *__folio_alloc_noprof (gfp_t gfp,unsigned int order,int preferred_nid,nodemask_t *nodemask) {struct page *page =__alloc_pages_noprof (gfp | __GFP_COMP, order, - preferred_nid, nodemask); + preferred_nid, nodemask,ALLOC_DEFAULT );return page_rmappable_folio (page); }EXPORT_SYMBOL (__folio_alloc_noprof);@@ -7107,7 +7113,7 @@ static void split_free_frozen_pages(struct list_head *list, gfp_t gfp_mask)list_for_each_entry_safe (page, next, &list[order], lru) {int i; -post_alloc_hook (page, order, gfp_mask); +post_alloc_hook (page, order, gfp_mask,ALLOC_DEFAULT );if (!order)continue ;@@ -7312,7 +7318,7 @@ int alloc_contig_frozen_range_noprof(unsigned long start, unsigned long end,struct page *head =pfn_to_page (start);check_new_pages (head, order); -prep_new_page (head, order, gfp_mask,0 ); +prep_new_page (head, order, gfp_mask,ALLOC_DEFAULT ); }else { ret = -EINVAL ; WARN(true, "PFN range: requested [%lu, %lu), allocated [%lu, %lu)\n",mm/page_frag_cache.c +2
-2@@ -57,10 +57,10 @@ static struct page *__page_frag_cache_refill(struct page_frag_cache *nc, gfp_mask = (gfp_mask & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN | __GFP_NORETRY | __GFP_NOMEMALLOC; page =__alloc_pages (gfp_mask,PAGE_FRAG_CACHE_MAX_ORDER , -numa_mem_id (),NULL ); +numa_mem_id (),NULL ,ALLOC_DEFAULT );#endif if (unlikely (!page)) { - page =__alloc_pages (gfp,0 ,numa_mem_id (),NULL ); + page =__alloc_pages (gfp,0 ,numa_mem_id (),NULL ,ALLOC_DEFAULT ); order =0 ; }
Brendan Jackman
reviewerRe: [PATCH v2 13/13] mm: remove __GFP_NO_CODETAG
Quoted 16 lines · Suren Baghdasaryan
Quoted 15 lines · Hao Ge
Hi Brendan
Quoted 10 lines · Brendan Jackman
Now that
alloc_pageshas an entrypoint that allows passingalloc_flags, we can take advantage of this to start removing GFP flags that are only used for mm-internal stuff.This requires also plumbing the
alloc_flagsinto some more of the allocator code, in particular __alloc_pages[_noprof]() gets analloc_flagsarg to go along with its callees, and we now need to pass those flags deeper into the allocator so they can reach thealloc_tagcode.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
To try and keep the new ALLOC_NO_CODETAG's scope nice and narrow, don't define it in
mm/internal.h, instead just define a "reserved bit" and then use that in places that don't care about what it means.I don't understand why you want to narrow down visibility of one of the
alloc_flagbits. We don't do that for any other flags, and this seems like an unnecessary complexity.
OK can drop this and just expose it directly.
This was just coz __GFP_NO_CODETAG was local to the .c file and it felt like a "regression" to "leak" it into the header. But yeah on the other hand this "reserved bit" thing is unncessary indirection.
Quoted 18 lines
Quoted 18 lines
Quoted 1 line
Signed-off-by Brendan Jackman <[email protected]>Nit: The title says "remove
__GFP_NO_CODETAG" but the flag isn't really removed — it's migrated fromgfp_ttoalloc_flagsas
ALLOC_NO_CODETAG. Something like "mm: replace__GFP_NO_CODETAGwith analloc_flag" would be more accurate.Additionally, as Lorenzo pointed out in another thread, you will likely need to rebase this series later.
I noticed Vlastimil has already landed the slab changes removing
__GFP_NO_OBJ_EXTinto mainline:
Quoted 8 lines
Quoted 4 lines
For v3, it might make sense to fold in Vlastimil's patch so the full removal of
__GFP_NO_OBJ_EXTcan be completed end-to-endI think Vlastimil's patch will be merged before this one, so this patch could remove
__GFP_NO_OBJ_EXTcomplely, saying that its last user (__GFP_NO_CODETAG) is gone.
Yup, Vlastimil's other patches went directly to Linus so the final __GFP_NO_OBJ_EXT removal is already in my local branch for the v3 :)
Vlastimil Babka (SUSE)
maintainer+Cc Hao Ge for the "remove __GFP_NO_CODETAG" part
Quoted 94 lines · Brendan Jackman
Some tweaks and cleanups for page allocator entrypoint and flags. This is motivated by preparation for
__GFP_UNMAPPED[1] (which will probably becomeALLOC_UNMAPPEDin its next iteration), but all this is supposed to be an improvement to the codebase in its own right: unifying code paths, reducing API surface, and removing GFP flags.[1] https://lore.kernel.org/all/[email protected]/
This started with unifying __alloc_frozen_pages[_nolock]_noprof() and expanded from there.
Unifying the nolock allocator entrypoint with the normal allocator entrypoint means adding an
alloc_flagsargument to the later (only exposed withinmm/). This presents an opportunity to take advantage of that arg to remove some GFP flags, if we add thatalloc_flagsarg a bit more broadly to allocator entrypoints.To distinguish between mm-internal and "public" allocator entrypoints, it makes sense to use the __ prefix. There are already some public APIs with that prefix. For *alloc_pages*, just removing those variants seems like a nice cleanup anyway, so do that. For
get_free_pages, the "__" variant is the _only_ variant and it's very widely used, so it doesn't seem worthwhile to modify that. Therefore, scope this "__" change specifically to the *alloc_pages* API, which means we leave the *folio_alloc* API untouched too, even though that could probably be cleaned up if so desired.Tested:
- KVM, mm, and BPF selftests in a QEMU VM
-
kunit.pyonx86_64- For the
ALLOC_NO_CODETAGbits I just booted a VM and read/proc/allocinfo. I confirmed that if I removeALLOC_NO_CODETAG, the kernel crashes in early boot, so I was at least booting code that depends on this logic.I used Google's internal version of Antigravity (AI coding harness) to do the repetitive bits, those commits are marked with Assisted-by, the rest is manual.
Signed-off-by Brendan Jackman <[email protected]>---
Changes in v2:
- Fixed up whitespace in nolock unification patch
- IntroducedALLOC_DEFAULTto replace literal 0 foralloc_flags
- All other patches are new
- Link to v1: https://patch.msgid.link/[email protected]---
Brendan Jackman (13):
mm/page_alloc: renameALLOC_TRYLOCK->ALLOC_NOLOCKmm/page_alloc: some renames to clarifyalloc_flagsscopesmm/page_alloc: unify __alloc_frozen_pages[_nolock]_noprof()mm/page_alloc: relax GFP WARN in nolock allocs perf/x86/intel: Use higher-level allocator
KVM: VMX: Use higher-level allocator
x86/virt: Use higher-level allocator
sgi-xp: Use higher-level allocator
net/funeth: Switch to higher-level allocator
mm: Remove__alloc_pages_node()
alloc_tag: Move tomm/
mm: Move__alloc_pages()tomm/internal.h
mm: remove__GFP_NO_CODETAGDocumentation/admin-guide/cgroup-v1/cpusets.rst | 2 +- Documentation/admin-guide/mm/transhuge.rst | 2 +- MAINTAINERS | 2 +- arch/x86/events/intel/ds.c | 6 +- arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/virt/hw.c | 2 +- drivers/misc/sgi-xp/xpc_uv.c | 2 +- drivers/net/ethernet/fungible/funeth/funeth_rx.c | 2 +- include/linux/gfp.h | 28 +-- lib/Makefile | 1 - mm/Makefile | 1 + {lib => mm}/alloc_tag.c | 18 +- mm/compaction.c | 4 +- mm/hugetlb.c | 3 +- mm/internal.h | 20 +- mm/mempolicy.c | 10 +- mm/page_alloc.c | 254 +++++++++++++---------- mm/page_frag_cache.c | 4 +- mm/slub.c | 6 +- 19 files changed, 193 insertions(+), 176 deletions(-)---
base-commit:cbe5256a15fc26f592efb037e528da54b2139ee5
change-id: 20260617-alloc-trylock-14ad37dab337Best regards,
Signature · 1 line
Brendan Jackman <[email protected]>
Lorenzo Stoakes
reviewerThanks for the series (cleanups are always welcome :) but just a gentle, annoying, note to say it's week 2 of the merge window soooo we're not taking anything at the moment as it's a quiet period (mm-unstable taking only fixes AFAICT).
Though, it's potentially good to get stuff in front of people early, just an FYI that we're trying to move towards keeping the merge window preview/RFC-only going forwards.
I'm not sure if that'll fix the impossible review load problem (TM), but it at least helps keep us sane re: what's actually landing/not.
So Andrew will expect you to resend this after 7.2-rc1 appears!
Thanks, Lorenzo
Quoted 6 lines · Lorenzo Stoakes
Thanks for the series (cleanups are always welcome :) but just a gentle, annoying, note to say it's week 2 of the merge window soooo we're not taking anything at the moment as it's a quiet period (mm-unstable taking only fixes AFAICT).
Quoted 8 lines
Though, it's potentially good to get stuff in front of people early, just an FYI that we're trying to move towards keeping the merge window preview/RFC-only going forwards.
I'm not sure if that'll fix the impossible review load problem (TM), but it at least helps keep us sane re: what's actually landing/not.
So Andrew will expect you to resend this after 7.2-rc1 appears!
Sorry as I discovered on [0] I am completely ignorant about merge windows, etc. Even after that thread it never really occurred to me that people might not want to receive patches at all when busy trying to get the rc into shape!
Anyway in this case I'm assuming there will be at least a v3 so I'll just wait before sending that.