Message ID | 20230421101415.5734-1-osalvador@suse.de (mailing list archive) |
---|---|
Headers | show |
Series | page_owner: print stacks and their counter | expand |
On Fri, Apr 21, 2023 at 12:14 PM Oscar Salvador <osalvador@suse.de> wrote: > > Changes v3 -> v4: > - Rebase (long time has passed) > - Use boolean instead of enum for action by Alexander Potapenko > - (I left some feedback untouched because it's been long and > would like to discuss it here now instead of re-vamping > and old thread) > > Changes v2 -> v3: > - Replace interface in favor of seq operations (suggested by Vlastimil) > - Use debugfs interface to store/read valued (suggested by Ammar) > > Hi, > > page_owner is a great debug functionality tool that gets us to know > about all pages that have been allocated/freed and their stacktrace. > This comes very handy when e.g: debugging leaks, as with some scripting > we might be able to see those stacktraces that are allocating pages > but not freeing theme. > > In my experience, that is one of the most useful cases, but it can get > really tedious to screen through all pages aand try to reconstruct the > stack <-> allocated/freed relationship. There is a lot of noise > to cancel off. > > This patch aims to fix that by adding a new functionality into page_owner. > What this does is to create a new read-only file "page_owner_stacks", > which prints only the allocating stacktraces and their counting, being that > the times the stacktrace has allocated - the times it has freed. > > So we have a clear overview of stacks <-> allocated/freed relationship > without the need to fiddle with pages and trying to match free stacktraces > with allocated stacktraces. > > This is achieved by adding a new refcount_t field in the stack_record struct, > incrementing that refcount_t everytime the same stacktrace allocates, > and decrementing it when it frees a page. Details can be seen in the > respective patches. I think the implementation of these counters is too specific to page_owner and is hard to use for any other purpose. If we decide to have them, there should be no page_owner-specific logic in the way we initialize/increment/decrement these counters. The thresholds in "mm,page_owner: Filter out stacks by a threshold counter" should also belong elsewhere. Given that no other stackdepot user needs these counters, maybe it should be cleaner to store an opaque struct along with the stack, passing its size to stack_depot_save(), and letting users access it directly using the stackdepot handler. I am also wondering if a separate hashtable mapping handlers to counters would solve the problem for you?
On 2023-04-21 13:19, Alexander Potapenko wrote: > I think the implementation of these counters is too specific to > page_owner and is hard to use for any other purpose. > If we decide to have them, there should be no page_owner-specific > logic in the way we initialize/increment/decrement these counters. Another solution would be to always increment the refcount in __stack_depot_save, in this case the "page-owner" specific changes are gone, and it is more of a generic thing. e.g: Andrey Konovalov mentioned that in a future KASAN remodelation, he would be using a stack refcount as well. > The thresholds in "mm,page_owner: Filter out stacks by a threshold > counter" should also belong elsewhere. That can certainly be cleaned up I guess to not polute non-page_owner code. > Given that no other stackdepot user needs these counters, maybe it > should be cleaner to store an opaque struct along with the stack, > passing its size to stack_depot_save(), and letting users access it > directly using the stackdepot handler. > > I am also wondering if a separate hashtable mapping handlers to > counters would solve the problem for you? Let us see first if with the changes from above the code gets to a more generic and clean stage, if not we can explore further options. Thanks for your feedback Alexander!
On Mon, 24 Apr 2023 05:54:59 +0200 Oscar Salvador <osalvador@suse.de> wrote: > > Given that no other stackdepot user needs these counters, maybe it > > should be cleaner to store an opaque struct along with the stack, > > passing its size to stack_depot_save(), and letting users access it > > directly using the stackdepot handler. > > > > I am also wondering if a separate hashtable mapping handlers to > > counters would solve the problem for you? > > Let us see first if with the changes from above the code gets to a more > generic and clean stage, if not we can explore further options. Alexander, does this approach sound reasonable to you? The overall feature seems useful, although I'm not seeing any positive reviewer feedback.
On 6/9/23 23:55, Andrew Morton wrote: > On Mon, 24 Apr 2023 05:54:59 +0200 Oscar Salvador <osalvador@suse.de> wrote: > >> > Given that no other stackdepot user needs these counters, maybe it >> > should be cleaner to store an opaque struct along with the stack, >> > passing its size to stack_depot_save(), and letting users access it >> > directly using the stackdepot handler. >> > >> > I am also wondering if a separate hashtable mapping handlers to >> > counters would solve the problem for you? >> >> Let us see first if with the changes from above the code gets to a more >> generic and clean stage, if not we can explore further options. > > Alexander, does this approach sound reasonable to you? Note this is a v4 thread; there was (and the version in mm-unstable is) v5, where the latest was Alexander requesting further changes: https://lore.kernel.org/all/CAG_fn%3DUJgnLFGgpkXbMeD6axZN_ifEPHvWpy2_oiPyG1a6PXng@mail.gmail.com/ > The overall feature seems useful, although I'm not seeing any positive > reviewer feedback.