From: Vineet Gupta <vineet.gupta@linux.dev>
To: rostedt@goodmis.org, mhiramat@kernel.org
Cc: mark.rutland@arm.com, mathieu.desnoyers@efficios.com,
andrii@kernel.org, peterz@infradead.org,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, kernel-team@meta.com,
Vineet Gupta <vineet.gupta@linux.dev>
Subject: [PATCH v4 0/2] tracing: fgraph: fix the quadratic shadow stack walk
Date: Wed, 21 Oct 2026 10:44:04 -0700 [thread overview]
Message-ID: <20261021174406.2891598-1-vineet.gupta@linux.dev> (raw)
alloc_retstack_tasklist() assigns a shadow stack to every thread when
fgraph is enabled. It did so FTRACE_RETSTACK_ALLOC_SIZE (32) tasks at a
time, and since for_each_process_thread() has no cursor, every sweep
restarted from init_task and re-walked the tasks already served, making
the ftrace_graph_active 0 -> 1 transition quadratic in the thread count.
On a 60-core Sapphire Rapids machine with 400000 idle threads it took
227 s, inside a single bpf() syscall for the kprobe_multi case.
- 1/2 allocates inline with GFP_NOWAIT, which removes the batching:
a single sweep serves every task, 227 s -> 0.092 s. It keeps the
open-coded rcu_read_lock() for ease of backport.
- 2/2 is the cleanup: convert that same walk to scoped_guard(rcu).
No functional change, and not needed by stable.
Both were tested on bare metal and in a VM, including forcing the
GFP_NOWAIT failure path with failslab injection.
v1: https://lore.kernel.org/all/20260922225526.1554758-1-vineet.gupta@linux.dev/
v2: https://lore.kernel.org/all/20260929005411.4105448-1-vineet.gupta@linux.dev/
v3: https://lore.kernel.org/all/20261001102909.1152572-1-vineet.gupta@linux.dev/
Changes since v3:
- split into two patches: the fix keeps goto-based unwinding so it
backports cleanly, and scoped_guard(rcu) moves to a separate
cleanup, per Masami and Steve:
https://lore.kernel.org/all/20261013194542.7e036b03@226.227.38.69.naturalwireless.com/
- in the cleanup, -EAGAIN now exits via the existing free label
rather than returning from inside the guard, so there is no longer
a path that skips the free loop
Changes since v2:
- update the stale alloc_retstack_tasklist() comment, which still
described the old batch-of-32 behaviour (bot+bpf-ci)
Changes since v1:
- replace both v1 patches with Peter's inline GFP_NOWAIT approach,
which removes the quadratic behaviour rather than dividing it by a
constant. With a single sweep there is no retry loop left, so the
v1 cond_resched() patch has nothing to attach to and is dropped.
Vineet Gupta (2):
tracing: fgraph: allocate shadow stacks inline with GFP_NOWAIT
tracing: fgraph: use scoped_guard() for the task list walk
kernel/trace/fgraph.c | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
--
2.53.0-Meta
next reply other threads:[~2026-10-21 17:44 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 17:44 Vineet Gupta [this message]
2026-10-21 17:44 ` [PATCH v4 1/2] tracing: fgraph: allocate shadow stacks inline with GFP_NOWAIT Vineet Gupta
2026-10-23 18:13 ` Andrii Nakryiko
2026-10-23 18:38 ` Steven Rostedt
2026-10-23 20:13 ` Vineet Gupta
2026-10-23 22:09 ` Steven Rostedt
2026-10-23 22:25 ` Vineet Gupta
2026-10-21 17:44 ` [PATCH v4 2/2] tracing: fgraph: use scoped_guard() for the task list walk Vineet Gupta
2026-10-21 17:53 ` sashiko-bot
2026-10-21 17:56 ` Vineet Gupta
2026-10-21 22:01 ` [PATCH v4 0/2] tracing: fgraph: fix the quadratic shadow stack walk Alexei Starovoitov
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=20261021174406.2891598-1-vineet.gupta@linux.dev \
--to=vineet.gupta@linux.dev \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.