[PATCH v2] mm: kfence: print the elapsed time for allocated/freed track

3 views
Skip to first unread message

qiwu.chen

unread,
Aug 6, 2024, 10:56:49 PM8/6/24
to el...@google.com, dvy...@google.com, ak...@linux-foundation.org, kasa...@googlegroups.com, linu...@kvack.org, qiwu.chen
Print the elapsed time for the allocated or freed track,
which can be useful in some debugging scenarios.

Signed-off-by: qiwu.chen <qiwu...@transsion.com>
---
mm/kfence/report.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/kfence/report.c b/mm/kfence/report.c
index c509aed326ce..73a6fe42845a 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>
@@ -108,11 +109,14 @@ static void kfence_print_stack(struct seq_file *seq, const struct kfence_metadat
const struct kfence_track *track = show_alloc ? &meta->alloc_track : &meta->free_track;
u64 ts_sec = track->ts_nsec;
unsigned long rem_nsec = do_div(ts_sec, NSEC_PER_SEC);
+ u64 interval_nsec = local_clock() - meta->alloc_track.ts_nsec;
+ unsigned long rem_interval_nsec = do_div(interval_nsec, NSEC_PER_SEC);

/* Timestamp matches printk timestamp format. */
- seq_con_printf(seq, "%s by task %d on cpu %d at %lu.%06lus:\n",
+ seq_con_printf(seq, "%s by task %d on cpu %d at %lu.%06lus (%lu.%06lus ago):\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);

if (track->num_stack_entries) {
/* Skip allocation/free internals stack. */
--
2.25.1

Marco Elver

unread,
Aug 7, 2024, 6:40:31 AM8/7/24
to qiwu.chen, Alexander Potapenko, dvy...@google.com, ak...@linux-foundation.org, kasa...@googlegroups.com, linu...@kvack.org, qiwu.chen, LKML
On Wed, 7 Aug 2024 at 04:56, qiwu.chen <qiwuc...@gmail.com> wrote:
>
> Print the elapsed time for the allocated or freed track,
> which can be useful in some debugging scenarios.
>
> Signed-off-by: qiwu.chen <qiwu...@transsion.com>

Reviewed-by: Marco Elver <el...@google.com>

Thanks for the changes! I think this is more generally useful and much
simpler than v1.
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20240807025627.37419-1-qiwu.chen%40transsion.com.

Andrew Morton

unread,
Aug 7, 2024, 5:05:39 PM8/7/24
to qiwu.chen, el...@google.com, dvy...@google.com, kasa...@googlegroups.com, linu...@kvack.org, qiwu.chen
On Wed, 7 Aug 2024 10:56:27 +0800 "qiwu.chen" <qiwuc...@gmail.com> wrote:

> From: "qiwu.chen" <qiwuc...@gmail.com>
>
> ...
>
> Signed-off-by: qiwu.chen <qiwu...@transsion.com>

Was this intended? It's unusual, which is why checkpatch says

WARNING: From:/Signed-off-by: email address mismatch: 'From: "qiwu.chen" <qiwuc...@gmail.com>' != 'Signed-off-by: qiwu.chen <qiwu...@transsion.com>'

Perhaps you intended to include an explicit From: line in the
changelog to fix this?

Reply all
Reply to author
Forward
0 new messages