Re: [PATCH] mm/page_owner: make page_owner stack depth runtime configurable

From: Kanishka Solanki

Date: Mon Oct 12 2026 - 00:16:16 EST


On Sat, Oct 10, 2026 at 5:12 PM Zi Yan <ziy@xxxxxxxxxx> 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@xxxxxxxxx>
> > Signed-off-by: Kanishka Solanki <kanishkasolanki456s@xxxxxxxxx>
> > ---
> > 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