linux-debuggers.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Fwd: Debugger for mapcount/reference counting issues
       [not found] <CAMtebmKLJ4MaXsNX5zeJN5MoZP+x7_qAru5R+F1WBh10Vzj3=A@mail.gmail.com>
@ 2025-03-29  3:24 ` Adrian Johnston
  2025-04-04 20:09   ` Omar Sandoval
  0 siblings, 1 reply; 2+ messages in thread
From: Adrian Johnston @ 2025-03-29  3:24 UTC (permalink / raw)
  To: linux-debuggers

I was just reading an article about the long running
mapcount/reference counting issues in the kernel over on LWN.
https://lwn.net/Articles/1013956/bigpage

And I'd like to make a recommendation in this ongoing discussion.

The kernel would benefit from a reference count debugger.  This is a
debug build only tool that keeps track of the owner of each increment
to a reference count and then confirms that each call to release a
reference count has an owner that matches an increment by a previously
registered owner.  This enforces an ownership match between allocation
and release of each reference count increment, even in ad hoc code. It
would also be able to validate the reference counter independently
when resources are being processed, created and destroyed.

Ideally this tool would be able to show calls stacks associated with
release operations that have unregistered owners and call stacks for
leaked reference increments at system shutdown.  Having this type of
tool enabled on your integration build (linux-next) might save you a
lot of debugging.

Personally, I don't think this is a good problem to have and would
argue that every resource should have a single owner that arbitrates
it's life cycle.  But there are tools that can help if reference
counting is necessary.

All the best,
Adrian Johnston

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

* Re: Fwd: Debugger for mapcount/reference counting issues
  2025-03-29  3:24 ` Fwd: Debugger for mapcount/reference counting issues Adrian Johnston
@ 2025-04-04 20:09   ` Omar Sandoval
  0 siblings, 0 replies; 2+ messages in thread
From: Omar Sandoval @ 2025-04-04 20:09 UTC (permalink / raw)
  To: Adrian Johnston; +Cc: linux-debuggers

On Fri, Mar 28, 2025 at 08:24:47PM -0700, Adrian Johnston wrote:
> I was just reading an article about the long running
> mapcount/reference counting issues in the kernel over on LWN.
> https://lwn.net/Articles/1013956/bigpage
> 
> And I'd like to make a recommendation in this ongoing discussion.
> 
> The kernel would benefit from a reference count debugger.  This is a
> debug build only tool that keeps track of the owner of each increment
> to a reference count and then confirms that each call to release a
> reference count has an owner that matches an increment by a previously
> registered owner.  This enforces an ownership match between allocation
> and release of each reference count increment, even in ad hoc code. It
> would also be able to validate the reference counter independently
> when resources are being processed, created and destroyed.
> 
> Ideally this tool would be able to show calls stacks associated with
> release operations that have unregistered owners and call stacks for
> leaked reference increments at system shutdown.  Having this type of
> tool enabled on your integration build (linux-next) might save you a
> lot of debugging.
> 
> Personally, I don't think this is a good problem to have and would
> argue that every resource should have a single owner that arbitrates
> it's life cycle.  But there are tools that can help if reference
> counting is necessary.
> 
> All the best,
> Adrian Johnston

Hi,

What you described sounds very similar to ref_tracker:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/ref_tracker.h
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4e66934eaadc83b27ada8d42b60894018f3bfabf

It doesn't seem to be used very widely, but it has proven useful for
debugging network namespace leaks.

Thanks,
Omar

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

end of thread, other threads:[~2025-04-04 20:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAMtebmKLJ4MaXsNX5zeJN5MoZP+x7_qAru5R+F1WBh10Vzj3=A@mail.gmail.com>
2025-03-29  3:24 ` Fwd: Debugger for mapcount/reference counting issues Adrian Johnston
2025-04-04 20:09   ` Omar Sandoval

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).