mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yaxiong Tian <tianyaxiong@kylinos.cn>
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: rostedt@goodmis.org, mark.rutland@arm.com,
	mathieu.desnoyers@efficios.com, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] ftrace: speed up module enable by binary searching module symbols
Date: Tue, 20 Oct 2026 10:08:51 +0800	[thread overview]
Message-ID: <be63bc89-0a3a-4617-af78-587f8746f0f7@kylinos.cn> (raw)
In-Reply-To: <undine-1792423513137811483-832e0e20f49f84bd@undined.local>


On 2026/10/19 23:25, Masami Hiramatsu (Google) wrote:
> Hi,
>
> On Wed, 16 Sep 2026 16:27:15 +0800, Yaxiong Tian <tianyaxiong@kylinos.cn> wrote:
>
>> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
>> --- a/kernel/trace/ftrace.c
>> +++ b/kernel/trace/ftrace.c
>> @@ -8010,11 +8011,137 @@ void ftrace_release_mod(struct module *mod)
>> +
>> +	/* mod->kallsyms is not replaced until do_init_module() returns. */
>> +	rcu_read_lock();
>> +	kallsyms = rcu_dereference(mod->kallsyms);
> Consider using rcu_access_pointer(mod->kallsyms) or
> rcu_dereference_raw(mod->kallsyms) rather than a transient
> rcu_read_lock()/rcu_read_unlock() pair.
Agreed, I will use rcu_dereference_raw() and drop the lock pair.

>> +	rcu_read_unlock();
>> +
>> +	if (!kallsyms || kallsyms->num_symtab < 2)
>> [...]
>> +	 * ftrace never came up, where the loop below would not run anyway; that
>> +	 * also makes reading ftrace_disabled without the lock safe.
>> +	 */
>> +	syms = ftrace_disabled ? NULL : ftrace_mod_syms_alloc(mod);
> Because ftrace_disabled is one-way flag, if you find ftrace_disabled here,
> you can return from this function soon.
>
> Thanks,
Right. I will check it once before the allocation and jump to a common
out_cached_mods label, so ftrace_lock is not taken at all in that case and
process_cached_mods() still runs exactly once. I keep the second check
under the lock because ftrace_kill() can set the flag after the unlocked
read.

    if (ftrace_disabled)
        goto out_cached_mods;

    syms = ftrace_mod_syms_alloc(mod);

    mutex_lock(&ftrace_lock);

    if (ftrace_disabled)
        goto out_unlock;
    ...
 out_unlock:
    mutex_unlock(&ftrace_lock);
    kvfree(syms);
 out_cached_mods:
    process_cached_mods(mod->name);

>> +
>>  	mutex_lock(&ftrace_lock);
>>  

  reply	other threads:[~2026-10-20  2:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16  8:27 Yaxiong Tian
2026-10-16 18:07 ` Steven Rostedt
2026-10-19  1:06   ` Yaxiong Tian
2026-10-19 15:25 ` Masami Hiramatsu
2026-10-20  2:08   ` Yaxiong Tian [this message]
2026-11-04 18:43 ` Steven Rostedt
2026-11-05  2:08   ` Yaxiong Tian

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=be63bc89-0a3a-4617-af78-587f8746f0f7@kylinos.cn \
    --to=tianyaxiong@kylinos.cn \
    --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=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 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®