Re: [PATCH] radix tree: fix kmemleak false positive in radix_tree_shrink()

From: Breno Leitao

Date: Mon Jul 06 2026 - 06:36:33 EST


Hello Catalin,

On Tue, May 20, 2025 at 02:51:45PM +0100, Catalin Marinas wrote:
> That said, the current logic updates the checksum when it was found
> unreferenced (potential leak). If the object was referenced in
> subsequent scans, the checksum remains intact, so minutes later it may
> be seen again as a transient leak. Something like below should reduce
> the transient leak reports (though not eliminate):
>
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index c12cef3eeb32..b1460c64f4b1 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -1408,6 +1408,12 @@ static void update_refs(struct kmemleak_object *object)
> /* put_object() called when removing from gray_list */
> WARN_ON(!get_object(object));
> list_add_tail(&object->gray_list, &gray_list);
> + /*
> + * Reset the checksum; the object must be unchanged between
> + * two consecutive scans where it was unreferenced
> + * (color_white()) in order to be reported as a leak.
> + */
> + object->checksum = 0;

I noticed this patch never made it upstream. While I understand it's
related to min_unref_scans, I think it still makes sense given that
min_unref_scans defaults to 1.

Your proposal provides an additional mechanism to reduce false
positives, which aligns with my current work in this area.