From: Catalin Marinas <catalin.marinas@arm.com>
To: Breno Leitao <leitao@debian.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, kernel-team@meta.com
Subject: Re: [PATCH 1/2] mm/kmemleak: dedupe verbose scan output by allocation backtrace
Date: Fri, 24 Apr 2026 13:05:20 +0100 [thread overview]
Message-ID: <aetcgHhBXfPe6lr1@arm.com> (raw)
In-Reply-To: <aesymSWyh8NRIrDQ@gmail.com>
On Fri, Apr 24, 2026 at 02:26:53AM -0700, Breno Leitao wrote:
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index 2eff0d6b622b6..d521cc71ec1ee 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -92,6 +92,7 @@
> #include <linux/nodemask.h>
> #include <linux/mm.h>
> #include <linux/workqueue.h>
> +#include <linux/xarray.h>
> #include <linux/crc32.h>
>
> #include <asm/sections.h>
> @@ -153,6 +154,8 @@ struct kmemleak_object {
> /* checksum for detecting modified objects */
> u32 checksum;
> depot_stack_handle_t trace_handle;
> + /* per-scan dedup count, valid only while in scan-local dedup xarray */
> + unsigned int dup_count;
I would add this around the pid_t pid member since both are 32-bit,
better struct compaction. Here we'll get 32-bit padding.
> /* memory ranges to be scanned inside an object (empty for all) */
> struct hlist_head area_list;
> unsigned long jiffies; /* creation timestamp */
> @@ -360,8 +363,9 @@ static const char *__object_type_str(struct kmemleak_object *object)
> * Printing of the unreferenced objects information to the seq file. The
> * print_unreferenced function must be called with the object->lock held.
> */
> -static void print_unreferenced(struct seq_file *seq,
> - struct kmemleak_object *object)
> +static void __print_unreferenced(struct seq_file *seq,
> + struct kmemleak_object *object,
> + bool no_hex_dump)
> {
> int i;
> unsigned long *entries;
> @@ -373,7 +377,8 @@ static void print_unreferenced(struct seq_file *seq,
> object->pointer, object->size);
> warn_or_seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu\n",
> object->comm, object->pid, object->jiffies);
> - hex_dump_object(seq, object);
> + if (!no_hex_dump)
> + hex_dump_object(seq, object);
Nit: just use "hex_dump" and avoid double negation.
> warn_or_seq_printf(seq, " backtrace (crc %x):\n", object->checksum);
>
> for (i = 0; i < nr_entries; i++) {
> @@ -382,6 +387,12 @@ static void print_unreferenced(struct seq_file *seq,
> }
> }
>
> +static void print_unreferenced(struct seq_file *seq,
> + struct kmemleak_object *object)
> +{
> + __print_unreferenced(seq, object, false);
> +}
> +
> /*
> * Print the kmemleak_object information. This function is used mainly for
> * debugging special cases when kmemleak operations. It must be called with
> @@ -1684,6 +1695,103 @@ static void kmemleak_cond_resched(struct kmemleak_object *object)
> put_object(object);
> }
>
> +/*
> + * Print one leak inline, re-checking OBJECT_ALLOCATED under the lock so
> + * the hex dump does not touch user memory that was freed concurrently.
> + * Used by the dedup_record() fallback paths where we cannot dedup and defer
> + * printing through the xarray.
> + */
> +static void print_leak_locked(struct kmemleak_object *object, bool no_hex_dump)
> +{
> + raw_spin_lock_irq(&object->lock);
> + if (object->flags & OBJECT_ALLOCATED)
> + __print_unreferenced(NULL, object, no_hex_dump);
> + raw_spin_unlock_irq(&object->lock);
I don't think OBJECT_ALLOCATED should prevent the printing here. If it's
called from dedup_flush() and the first object that kept accumulating
the dup_count is freed, you'd not print anything. I would only use
OBJECT_ALLOCATED to decide whether to do the hex dump if requested.
--
Catalin
next prev parent reply other threads:[~2026-04-24 12:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 13:45 [PATCH 0/2] mm/kmemleak: dedupe verbose scan output Breno Leitao
2026-04-21 13:45 ` [PATCH 1/2] mm/kmemleak: dedupe verbose scan output by allocation backtrace Breno Leitao
2026-04-23 14:29 ` Catalin Marinas
2026-04-24 9:26 ` Breno Leitao
2026-04-24 12:05 ` Catalin Marinas [this message]
2026-04-24 12:43 ` Breno Leitao
2026-04-21 13:45 ` [PATCH 2/2] selftests/mm: add kmemleak verbose dedup test Breno Leitao
2026-04-24 13:53 ` [PATCH 0/2] mm/kmemleak: dedupe verbose scan output Andrew Morton
2026-04-24 14:36 ` Breno Leitao
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=aetcgHhBXfPe6lr1@arm.com \
--to=catalin.marinas@arm.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=kernel-team@meta.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@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