linux-debuggers.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Omar Sandoval <osandov@osandov.com>
To: Adrian Johnston <adrian3@gmail.com>
Cc: linux-debuggers@vger.kernel.org
Subject: Re: Fwd: Debugger for mapcount/reference counting issues
Date: Fri, 4 Apr 2025 13:09:17 -0700	[thread overview]
Message-ID: <Z_A8bYidN9w4YJv2@telecaster> (raw)
In-Reply-To: <CAMtebm+fzVE6iVst=mT5ecWK66C80pM4eFi5SXtU2F46kaGm4Q@mail.gmail.com>

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

      reply	other threads:[~2025-04-04 20:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z_A8bYidN9w4YJv2@telecaster \
    --to=osandov@osandov.com \
    --cc=adrian3@gmail.com \
    --cc=linux-debuggers@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).