linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: kfence: print the age time for alloacted objectes to trace memleak
@ 2024-08-03 13:36 Qiwu Chen
  2024-08-03 14:51 ` Marco Elver
  0 siblings, 1 reply; 8+ messages in thread
From: Qiwu Chen @ 2024-08-03 13:36 UTC (permalink / raw)
  To: glider, elver, dvyukov, akpm; +Cc: kasan-dev, linux-mm, qiwu.chen

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



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-08-05 14:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-03 13:36 [PATCH] mm: kfence: print the age time for alloacted objectes to trace memleak Qiwu Chen
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox