Re: [PATCH v3] trace/pid_list: optimize pid_list->lock contention

From: Steven Rostedt

Date: Wed Nov 12 2025 - 19:21:16 EST


On Thu, 13 Nov 2025 08:02:52 +0800
Yongliang Gao <leonylgao@xxxxxxxxx> wrote:

> From: Yongliang Gao <leonylgao@xxxxxxxxxxx>
>
> When the system has many cores and task switching is frequent,
> setting set_ftrace_pid can cause frequent pid_list->lock contention
> and high system sys usage.
>
> For example, in a 288-core VM environment, we observed 267 CPUs
> experiencing contention on pid_list->lock, with stack traces showing:
>
> #4 [ffffa6226fb4bc70] native_queued_spin_lock_slowpath at ffffffff99cd4b7e
> #5 [ffffa6226fb4bc90] _raw_spin_lock_irqsave at ffffffff99cd3e36
> #6 [ffffa6226fb4bca0] trace_pid_list_is_set at ffffffff99267554
> #7 [ffffa6226fb4bcc0] trace_ignore_this_task at ffffffff9925c288
> #8 [ffffa6226fb4bcd8] ftrace_filter_pid_sched_switch_probe at ffffffff99246efe
> #9 [ffffa6226fb4bcf0] __schedule at ffffffff99ccd161
>
> Replaces the existing spinlock with a seqlock to allow concurrent readers,
> while maintaining write exclusivity.
>
> ---
> Changes from v2:
> - Keep trace_pid_list_next() using raw_spin_lock for simplicity. [Steven Rostedt]
> - Link to v2: https://lore.kernel.org/all/20251112181456.473864-1-leonylgao@xxxxxxxxx
> Changes from v1:
> - Fixed sleep-in-atomic issues under PREEMPT_RT. [Steven Rostedt]
> - Link to v1: https://lore.kernel.org/all/20251015114952.4014352-1-leonylgao@xxxxxxxxx
> ---

You don't need to resend, but the "Changes from" needs to go below the
'---' after the tags. Otherwise, git am removes everything from the above
'---', including your tags below.

-- Steve


>
> Signed-off-by: Yongliang Gao <leonylgao@xxxxxxxxxxx>
> Reviewed-by: Huang Cun <cunhuang@xxxxxxxxxxx>
> ---
> kernel/trace/pid_list.c | 30 +++++++++++++++++++++---------
> kernel/trace/pid_list.h | 1 +
> 2 files changed, 22 insertions(+), 9 deletions(-)
>