Re: [PATCH v15 03/10] unwind_user/deferred: Add unwind cache
From: Jens Remus
Date: Mon Jul 28 2025 - 11:49:30 EST
On 25.07.2025 20:55, Steven Rostedt wrote:
> From: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
>
> Cache the results of the unwind to ensure the unwind is only performed
> once, even when called by multiple tracers.
>
> The cache nr_entries gets cleared every time the task exits the kernel.
> When a stacktrace is requested, nr_entries gets set to the number of
> entries in the stacktrace. If another stacktrace is requested, if
> nr_entries is not zero, then it contains the same stacktrace that would be
> retrieved so it is not processed again and the entries is given to the
> caller.
>
> Co-developed-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
> Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
> Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
Reviewed-by: Jens Remus <jremus@xxxxxxxxxxxxx>
> diff --git a/kernel/unwind/deferred.c b/kernel/unwind/deferred.c
> + cache = info->cache;
> + trace->entries = cache->entries;
> +
> + if (cache->nr_entries) {
> + /*
> + * The user stack has already been previously unwound in this
> + * entry context. Skip the unwind and use the cache.
> + */
> + trace->nr = cache->nr_entries;
> + return 0;
> + }
> +
> trace->nr = 0;
> - trace->entries = info->entries;
> unwind_user(trace, UNWIND_MAX_ENTRIES);
>
> + cache->nr_entries = trace->nr;
> +
Would the following alternative to above excerpt be easier to read?
/* Use the cache, if the user stack has already been previously
* unwound in this entry context. If not this will initialize
* trace->nr to zero to trigger the unwind now.
*/
cache = info->cache;
trace->nr = cache->nr_entries;
trace->entries = cache->entries;
if (!trace->nr) {
unwind_user(trace, UNWIND_MAX_ENTRIES);
cache->nr_entries = trace->nr;
}
> return 0;
> }
Regards,
Jens
--
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
jremus@xxxxxxxxxx
IBM
IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/