Re: [PATCH v9 4/7] mm,page_owner: Implement the tracking of the stacks count
From: Oscar Salvador
Date: Thu Feb 15 2024 - 06:57:13 EST
On Thu, Feb 15, 2024 at 12:08:53PM +0100, Vlastimil Babka wrote:
> On 2/14/24 18:01, Oscar Salvador wrote:
> > Implement {inc,dec}_stack_record_count() which increments or
> > decrements on respective allocation and free operations, via
> > __reset_page_owner() (free operation) and __set_page_owner() (alloc
> > operation).
> > Newly allocated stack_record structs will be added to the list stack_list
> > via add_stack_record_to_list().
> > Modifications on the list are protected via a spinlock with irqs
> > disabled, since this code can also be reached from IRQ context.
> >
> > Signed-off-by: Oscar Salvador <osalvador@xxxxxxx>
> > Reviewed-by: Marco Elver <elver@xxxxxxxxxx>
>
> Reviewed-by: Vlastimil Babka <vbabka@xxxxxxx>
Thanks!
> > + if (atomic_try_cmpxchg_relaxed(&stack_record->count.refs, &old, 1))
> > + /* Add the new stack_record to our list */
> > + add_stack_record_to_list(stack_record, gfp_mask);
>
> Not returning here...
>
> > + }
> > + refcount_inc(&stack_record->count);
>
> ... means we'll increase the count to 2 on the first store, so there's a
> bias. Which would be consistent with the failure and dummy stacks that also
> start with a refcount of 1. But then the stack count reporting should
> decrement by 1 to prevent confusion? (in the following patch). Imagine
> somebody debugging an allocation stack where there are not so many of them,
> but the allocation is large, and being sidetracked by an off-by-one error.
Good catch Vlastimil!
Yes, we should substract one from the total count in stack_print.
--
Oscar Salvador
SUSE Labs