From: Qiwu Chen <qiwuchen55@gmail.com>
To: glider@google.com, elver@google.com, dvyukov@google.com,
akpm@linux-foundation.org
Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org,
"qiwu.chen" <qiwu.chen@transsion.com>
Subject: [PATCH] mm: kfence: print the age time for alloacted objectes to trace memleak
Date: Sat, 3 Aug 2024 06:36:08 -0700 [thread overview]
Message-ID: <20240803133608.2124-1-chenqiwu@xiaomi.com> (raw)
From: "qiwu.chen" <qiwu.chen@transsion.com>
For a convienince of tracing slab object leak, print the age time for
alloacted objectes in kfence_print_stack().
Signed-off-by: qiwu.chen <qiwu.chen@transsion.com>
---
mm/kfence/report.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/mm/kfence/report.c b/mm/kfence/report.c
index c509aed326ce..44c3f82b25a8 100644
--- a/mm/kfence/report.c
+++ b/mm/kfence/report.c
@@ -16,6 +16,7 @@
#include <linux/sprintf.h>
#include <linux/stacktrace.h>
#include <linux/string.h>
+#include <linux/sched/clock.h>
#include <trace/events/error_report.h>
#include <asm/kfence.h>
@@ -110,9 +111,18 @@ static void kfence_print_stack(struct seq_file *seq, const struct kfence_metadat
unsigned long rem_nsec = do_div(ts_sec, NSEC_PER_SEC);
/* Timestamp matches printk timestamp format. */
- seq_con_printf(seq, "%s by task %d on cpu %d at %lu.%06lus:\n",
+ if (meta->state == KFENCE_OBJECT_ALLOCATED) {
+ u64 interval_nsec = local_clock() - meta->alloc_track.ts_nsec;
+ unsigned long rem_interval_nsec = do_div(interval_nsec, NSEC_PER_SEC);
+
+ seq_con_printf(seq, "%s by task %d on cpu %d at %lu.%06lus (age: %lu.%06lus):\n",
show_alloc ? "allocated" : "freed", track->pid,
- track->cpu, (unsigned long)ts_sec, rem_nsec / 1000);
+ track->cpu, (unsigned long)ts_sec, rem_nsec / 1000,
+ (unsigned long)interval_nsec, rem_interval_nsec / 1000);
+ } else
+ seq_con_printf(seq, "%s by task %d on cpu %d at %lu.%06lus:\n",
+ show_alloc ? "allocated" : "freed", track->pid,
+ track->cpu, (unsigned long)ts_sec, rem_nsec / 1000);
if (track->num_stack_entries) {
/* Skip allocation/free internals stack. */
--
2.25.1
next reply other threads:[~2024-08-03 13:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-03 13:36 Qiwu Chen [this message]
2024-08-03 14:51 ` Marco Elver
2024-08-04 3:46 ` chenqiwu
2024-08-04 8:37 ` Marco Elver
2024-08-05 3:35 ` chenqiwu
2024-08-05 6:50 ` Marco Elver
2024-08-05 14:06 ` chenqiwu
2024-08-05 14:18 ` Marco Elver
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=20240803133608.2124-1-chenqiwu@xiaomi.com \
--to=qiwuchen55@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-mm@kvack.org \
--cc=qiwu.chen@transsion.com \
/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