On 2/12/24 23:30, Oscar Salvador wrote: > page_owner needs to increment a stack_record refcount when a new allocation > occurs, and decrement it on a free operation. > In order to do that, we need to have a way to get a stack_record from a > handle. > Implement __stack_depot_get_stack_record() which just does that, and make > it public so page_owner can use it. > > Also 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). > > Traversing all stackdepot buckets comes with its own complexity, > plus we would have to implement a way to mark only those stack_records > that were originated from page_owner, as those are the ones we are > interested in. > For that reason, page_owner maintains its own list of stack_records, > because traversing that list is faster than traversing all buckets > while keeping at the same time a low complexity. > inc_stack_record_count() is responsible of adding new stack_records > into the list stack_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> > --- > include/linux/stackdepot.h | 9 +++++ > lib/stackdepot.c | 8 +++++ > mm/page_owner.c | 73 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 90 insertions(+) > static inline void __set_page_owner_handle(struct page_ext *page_ext, > @@ -199,6 +271,7 @@ noinline void __set_page_owner(struct page *page, unsigned short order, > return; > __set_page_owner_handle(page_ext, handle, order, gfp_mask); > page_ext_put(page_ext); > + inc_stack_record_count(handle); What if this is dummy handle, which means we have recursed in page owner, and we'll by trying to kmalloc() its struct stack and link it to the stack_list because it was returned for the first time? Also failure_handle. Could you pre-create static (not kmalloc) struct stack for these handles with refcount of 0 and insert them to stack_list, all during init_page_owner()? Bonus: no longer treating stack_list == NULL in a special way in add_stack_record_to_list() (although you don't need to handle it extra even now, AFAICS). > } > > void __set_page_owner_migrate_reason(struct page *page, int reason)