Fwd: Debugger for mapcount/reference counting issues

Adrian Johnston <[email protected]> Fri, 28 Mar 2025 20:24:47 -0700
Newsgroups org.kernel.vger.linux-debuggers
Message-ID <CAMtebm+fzVE6iVst=mT5ecWK66C80pM4eFi5SXtU2F46kaGm4Q@mail.gmail.com>
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