Re: [PATCH v2] tracing: record jiffies in writeback events instead of computing age

From: Steven Rostedt

Date: Tue Nov 17 2026 - 17:28:09 EST


On Wed, 28 Oct 2026 11:25:24 +0800
Chaosheng Qu <quchaosheng000406@xxxxxxx> wrote:

> >From 677560a14dae0d9581effc5cdb9375052902bb21 Mon Sep 17 00:00:00 2001
> From: Chaosheng Qu <quchaosheng000406@xxxxxxx>
> Date: Tue, 27 Oct 2026 14:28:09 +0800
> Subject: [PATCH] tracing: record jiffies in writeback events instead of
> computing age
>
> writeback_sb_inodes_requeue and writeback_single_inode_start/() compute
> the inode age with:
>
> (jiffies - __entry->dirtied_when) / HZ
>
> inside TP_printk(). TP_printk() is not part of the recorded event: it
> runs when the trace is read back, so the expression is evaluated at
> formatter time, not at the time the event was recorded.
>
> It is also evaluated outside of the kernel: tracefs renders the format
> string once and userspace re-evaluates it. A tool that has to resolve
> every symbol in the expression (trace-cmd and the parser in LISA both
> do) resolves the bare "jiffies" to its address, so the printed age
> becomes ((unsigned long)&jiffies - dirtied_when) / HZ, which is
> nonsense. This was reported as a wrong "age" value in trace-cmd
> output:
>
> https://bugzilla.kernel.org/show_bug.cgi?id=219839
>
> Nothing in TP_printk() may depend on the state of the machine at read
> time, which is the same rule that keeps ktime_get() and friends out of
> it.
>
> v1 stored the age itself in TP_fast_assign(). Steve pointed out that
> the division then runs on the trace path, which is where the side
> effects have to stay small, and that recording the jiffies snapshot
> instead lets userspace compute whatever it wants from the raw value.
> Do that: save jiffies in TP_fast_assign() and keep the subtraction and
> the division in TP_printk(), where they run on the slow path. This
> follows the same shape as xprtrdma_req's connect/reconnect fields.
>
> The new __entry->jiffies field is appended after the existing fields,
> so no existing field changes offset and trace consumers that index the
> event by offset keep working. The "age=%lu" placeholder keeps its
> position in the output text, and the value it prints is unchanged.
>
> Suggested-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=219839
> Reviewed-by: Jan Kara <jack@xxxxxxx>
> Signed-off-by: Chaosheng Qu <quchaosheng000406@xxxxxxx>
> ---

This should likely go through the fs or mm tree.

-- Steve