From: Steven Rostedt <rostedt@goodmis.org>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Yongliang Gao <leonylgao@gmail.com>,
mhiramat@kernel.org, mathieu.desnoyers@efficios.com,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
frankjpliu@tencent.com, Yongliang Gao <leonylgao@tencent.com>,
Huang Cun <cunhuang@tencent.com>
Subject: Re: [PATCH v3] trace/pid_list: optimize pid_list->lock contention
Date: Thu, 13 Nov 2025 10:24:45 -0500 [thread overview]
Message-ID: <20251113102445.3e70c1ec@gandalf.local.home> (raw)
In-Reply-To: <20251113151729.4Zky6d-t@linutronix.de>
On Thu, 13 Nov 2025 16:17:29 +0100
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:
> On 2025-11-13 10:05:24 [-0500], Steven Rostedt wrote:
> > This means that the chunks are not being freed and we can't be doing
> > synchronize_rcu() in every exit.
>
> You don't have to, you can do call_rcu().
But the chunk isn't being freed. They may be used right away.
> So if the kfree() is not an issue, it is just the use of the block from
> the freelist which must not point to a wrong item? And therefore the
> seqcount?
Correct.
>
> > > So I *think* the RCU approach should be doable and cover this.
> >
> > Where would you put the synchronize_rcu()? In do_exit()?
>
> simply call_rcu() and let it move to the freelist.
A couple of issues. One, the chunks are fully used. There's no place to put
a "rcu_head" in them. Well, we may be able to make use of them.
Second, if there's a lot of tasks exiting and forking, we can easily run
out of chunks that are waiting to be "freed" via call_rcu().
>
> > Also understanding what this is used for helps in understanding the scope
> > of protection needed.
> >
> > The pid_list is created when you add anything into one of the pid files in
> > tracefs. Let's use /sys/kernel/tracing/set_ftrace_pid:
> >
> > # cd /sys/kernel/tracing
> > # echo $$ > set_ftrace_pid
> > # echo 1 > options/function-fork
> > # cat set_ftrace_pid
> > 2716
> > 2936
> > # cat set_ftrace_pid
> > 2716
> > 2945
> >
> > What the above did was to create a pid_list for the function tracer. I
> > added the bash process pid using $$ (2716). Then when I cat the file, it
> > showed the pid for the bash process as well as the pid for the cat process,
> > as the cat process is a child of the bash process. The function-fork option
> > means to add any child process to the set_ftrace_pid if the parent is
> > already in the list. It also means to remove the pid if a process in the
> > list exits.
>
> This adding/ add-on-fork, removing and remove-on-exit is the only write
> side?
That and manual writes to the set_ftrace_pid file.
> > What we are protecting against is when one chunk is freed, but then
> > allocated again for a different set of PIDs. Where the reader has the chunk,
> > it was freed and re-allocated and the bit that is about to be checked
> > doesn't represent the bit it is checking for.
>
> This I assumed.
> And the kfree() at the end can not happen while there is still a reader?
Correct. That's done by the pid_list user:
In clear_ftrace_pids():
/* Wait till all users are no longer using pid filtering */
synchronize_rcu();
if ((type & TRACE_PIDS) && pid_list)
trace_pid_list_free(pid_list);
if ((type & TRACE_NO_PIDS) && no_pid_list)
trace_pid_list_free(no_pid_list);
-- Steve
next prev parent reply other threads:[~2025-11-13 15:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-13 0:02 Yongliang Gao
2025-11-13 0:21 ` Steven Rostedt
2025-11-13 7:34 ` Sebastian Andrzej Siewior
2025-11-13 11:13 ` Yongliang Gao
2025-11-13 14:15 ` Sebastian Andrzej Siewior
2025-11-13 15:05 ` Steven Rostedt
2025-11-13 15:17 ` Sebastian Andrzej Siewior
2025-11-13 15:24 ` Steven Rostedt [this message]
2025-11-13 15:35 ` Sebastian Andrzej Siewior
2025-11-13 15:51 ` Steven Rostedt
2025-11-13 16:07 ` Sebastian Andrzej Siewior
2025-11-13 16:14 ` Steven Rostedt
2025-11-13 15:35 ` Steven Rostedt
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=20251113102445.3e70c1ec@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=bigeasy@linutronix.de \
--cc=cunhuang@tencent.com \
--cc=frankjpliu@tencent.com \
--cc=leonylgao@gmail.com \
--cc=leonylgao@tencent.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®