All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/page_owner: make page_owner stack depth runtime configurable
@ 2026-10-10  9:38 Kanishka Solanki
  2026-10-10 11:42 ` Zi Yan
  0 siblings, 1 reply; 3+ messages in thread
From: Kanishka Solanki @ 2026-10-10  9:38 UTC (permalink / raw)
  To: akpm, vbabka
  Cc: surenb, mhocko, brendan.jackman, hannes, ziy, linux-mm,
	linux-kernel, Kanishka Solanki

The stack depth for page_owner allocations was previously fixed at
PAGE_OWNER_STACK_DEPTH (16).

Replace the fixed stack depth constant with a compile-time max ceiling
(PAGE_OWNER_STACK_DEPTH_MAX = 64) and expose a module parameter
'stack_depth' via module_param_named. This allows users to configure
the stack recording depth between 1 and 64 at boot or runtime via sysfs,
while preventing unbounded stack usage.

Signed-off-by: Kanishka <kanishkasolanki456s@gmail.com>
Signed-off-by: Kanishka Solanki <kanishkasolanki456s@gmail.com>
---
 mm/page_owner.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/mm/page_owner.c b/mm/page_owner.c
index fbbda7ba914b..fcb584070f1d 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -15,11 +15,10 @@
 
 #include "page_alloc.h"
 
-/*
- * TODO: teach PAGE_OWNER_STACK_DEPTH (__dump_page_owner and save_stack)
- * to use off stack temporal storage
- */
-#define PAGE_OWNER_STACK_DEPTH (16)
+#define PAGE_OWNER_STACK_DEPTH_MAX (64)
+
+static unsigned int page_owner_stack_depth = 16;
+module_param_named(stack_depth, page_owner_stack_depth, uint, 0644);
 
 struct page_owner {
 	unsigned short order;
@@ -172,15 +171,17 @@ static inline struct page_owner *get_page_owner(struct page_ext *page_ext)
 
 static noinline depot_stack_handle_t save_stack(gfp_t flags)
 {
-	unsigned long entries[PAGE_OWNER_STACK_DEPTH];
+	unsigned long entries[PAGE_OWNER_STACK_DEPTH_MAX];
 	depot_stack_handle_t handle;
 	unsigned int nr_entries;
+	unsigned int max_entries;
 
 	if (current->in_page_owner)
 		return dummy_handle;
 
 	set_current_in_page_owner();
-	nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 2);
+	max_entries = min_t(unsigned int, page_owner_stack_depth, ARRAY_SIZE(entries));
+	nr_entries = stack_trace_save(entries, max_entries, 2);
 	handle = stack_depot_save(entries, nr_entries, flags);
 	if (!handle)
 		handle = failure_handle;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/page_owner: make page_owner stack depth runtime configurable
  2026-10-10  9:38 [PATCH] mm/page_owner: make page_owner stack depth runtime configurable Kanishka Solanki
@ 2026-10-10 11:42 ` Zi Yan
  2026-10-12  4:15   ` Kanishka Solanki
  0 siblings, 1 reply; 3+ messages in thread
From: Zi Yan @ 2026-10-10 11:42 UTC (permalink / raw)
  To: Kanishka Solanki, akpm, vbabka
  Cc: surenb, mhocko, brendan.jackman, hannes, linux-mm, linux-kernel

On Sat Oct 10, 2026 at 5:38 AM EDT, Kanishka Solanki wrote:
> The stack depth for page_owner allocations was previously fixed at
> PAGE_OWNER_STACK_DEPTH (16).
>
> Replace the fixed stack depth constant with a compile-time max ceiling
> (PAGE_OWNER_STACK_DEPTH_MAX = 64) and expose a module parameter
> 'stack_depth' via module_param_named. This allows users to configure
> the stack recording depth between 1 and 64 at boot or runtime via sysfs,
> while preventing unbounded stack usage.

What is your motivation? If you see page owner stack gets cutoff due to
insufficient depth, explain your use cases first.

>
> Signed-off-by: Kanishka <kanishkasolanki456s@gmail.com>
> Signed-off-by: Kanishka Solanki <kanishkasolanki456s@gmail.com>
> ---
>  mm/page_owner.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index fbbda7ba914b..fcb584070f1d 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -15,11 +15,10 @@
>  
>  #include "page_alloc.h"
>  
> -/*
> - * TODO: teach PAGE_OWNER_STACK_DEPTH (__dump_page_owner and save_stack)
> - * to use off stack temporal storage
> - */
> -#define PAGE_OWNER_STACK_DEPTH (16)
> +#define PAGE_OWNER_STACK_DEPTH_MAX (64)

This uses more stack. Do not do this.

> +
> +static unsigned int page_owner_stack_depth = 16;
> +module_param_named(stack_depth, page_owner_stack_depth, uint, 0644);
>  
>  struct page_owner {
>  	unsigned short order;
> @@ -172,15 +171,17 @@ static inline struct page_owner *get_page_owner(struct page_ext *page_ext)
>  
>  static noinline depot_stack_handle_t save_stack(gfp_t flags)
>  {
> -	unsigned long entries[PAGE_OWNER_STACK_DEPTH];
> +	unsigned long entries[PAGE_OWNER_STACK_DEPTH_MAX];
>  	depot_stack_handle_t handle;
>  	unsigned int nr_entries;
> +	unsigned int max_entries;
>  
>  	if (current->in_page_owner)
>  		return dummy_handle;
>  
>  	set_current_in_page_owner();
> -	nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 2);
> +	max_entries = min_t(unsigned int, page_owner_stack_depth, ARRAY_SIZE(entries));
> +	nr_entries = stack_trace_save(entries, max_entries, 2);
>  	handle = stack_depot_save(entries, nr_entries, flags);
>  	if (!handle)
>  		handle = failure_handle;




-- 
Best Regards,
Yan, Zi



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/page_owner: make page_owner stack depth runtime configurable
  2026-10-10 11:42 ` Zi Yan
@ 2026-10-12  4:15   ` Kanishka Solanki
  0 siblings, 0 replies; 3+ messages in thread
From: Kanishka Solanki @ 2026-10-12  4:15 UTC (permalink / raw)
  To: Zi Yan
  Cc: akpm, vbabka, surenb, mhocko, brendan.jackman, hannes, linux-mm,
	linux-kernel

On Sat, Oct 10, 2026 at 5:12 PM Zi Yan <ziy@nvidia.com> wrote:
>
> On Sat Oct 10, 2026 at 5:38 AM EDT, Kanishka Solanki wrote:
> > The stack depth for page_owner allocations was previously fixed at
> > PAGE_OWNER_STACK_DEPTH (16).
> >
> > Replace the fixed stack depth constant with a compile-time max ceiling
> > (PAGE_OWNER_STACK_DEPTH_MAX = 64) and expose a module parameter
> > 'stack_depth' via module_param_named. This allows users to configure
> > the stack recording depth between 1 and 64 at boot or runtime via sysfs,
> > while preventing unbounded stack usage.
>
> What is your motivation? If you see page owner stack gets cutoff due to
> insufficient depth, explain your use cases first.
>
> >
> > Signed-off-by: Kanishka <kanishkasolanki456s@gmail.com>
> > Signed-off-by: Kanishka Solanki <kanishkasolanki456s@gmail.com>
> > ---
> >  mm/page_owner.c | 15 ++++++++-------
> >  1 file changed, 8 insertions(+), 7 deletions(-)
> >
> > diff --git a/mm/page_owner.c b/mm/page_owner.c
> > index fbbda7ba914b..fcb584070f1d 100644
> > --- a/mm/page_owner.c
> > +++ b/mm/page_owner.c
> > @@ -15,11 +15,10 @@
> >
> >  #include "page_alloc.h"
> >
> > -/*
> > - * TODO: teach PAGE_OWNER_STACK_DEPTH (__dump_page_owner and save_stack)
> > - * to use off stack temporal storage
> > - */
> > -#define PAGE_OWNER_STACK_DEPTH (16)
> > +#define PAGE_OWNER_STACK_DEPTH_MAX (64)
>
> This uses more stack. Do not do this.
>
> > +
> > +static unsigned int page_owner_stack_depth = 16;
> > +module_param_named(stack_depth, page_owner_stack_depth, uint, 0644);
> >
> >  struct page_owner {
> >       unsigned short order;
> > @@ -172,15 +171,17 @@ static inline struct page_owner *get_page_owner(struct page_ext *page_ext)
> >
> >  static noinline depot_stack_handle_t save_stack(gfp_t flags)
> >  {
> > -     unsigned long entries[PAGE_OWNER_STACK_DEPTH];
> > +     unsigned long entries[PAGE_OWNER_STACK_DEPTH_MAX];
> >       depot_stack_handle_t handle;
> >       unsigned int nr_entries;
> > +     unsigned int max_entries;
> >
> >       if (current->in_page_owner)
> >               return dummy_handle;
> >
> >       set_current_in_page_owner();
> > -     nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 2);
> > +     max_entries = min_t(unsigned int, page_owner_stack_depth, ARRAY_SIZE(entries));
> > +     nr_entries = stack_trace_save(entries, max_entries, 2);
> >       handle = stack_depot_save(entries, nr_entries, flags);
> >       if (!handle)
> >               handle = failure_handle;
>
>
>
>
> --
> Best Regards,
> Yan, Zi
>


Hi Zi,

Thank you for the feedback.

I misunderstood the original TODO comment in mm/page_owner.c:
/*
- TODO: teach PAGE_OWNER_STACK_DEPTH (__dump_page_owner and save_stack)
- to use off stack temporal storage
 */
You are right. I will drop this patch.


Thank you
Kanishka


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-12  4:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-10  9:38 [PATCH] mm/page_owner: make page_owner stack depth runtime configurable Kanishka Solanki
2026-10-10 11:42 ` Zi Yan
2026-10-12  4:15   ` Kanishka Solanki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.