public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Shrikanth Hegde" <sshegde@linux.ibm.com>,
	"André Almeida" <andrealmeid@igalia.com>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org,
	"Valentin Schneider" <vschneid@redhat.com>,
	"Waiman Long" <longman@redhat.com>
Subject: Re: [PATCH v2 0/6] futex: Use RCU-based per-CPU reference counting
Date: Thu, 6 Nov 2025 12:09:07 +0100	[thread overview]
Message-ID: <20251106110907.noLpnulw@linutronix.de> (raw)
In-Reply-To: <20251106092929.GR4067720@noisy.programming.kicks-ass.net>

On 2025-11-06 10:29:29 [+0100], Peter Zijlstra wrote:
> Subject: futex: Optimize per-cpu reference counting
> From: Peter Zijlstra <peterz@infradead.org>
> Date: Wed, 16 Jul 2025 16:29:46 +0200
> 
> Shrikanth noted that the per-cpu reference counter was still some 10%
> slower than the old immutable option (which removes the reference
> counting entirely).
> 
> Further optimize the per-cpu reference counter by:
> 
>  - switching from RCU to preempt;
>  - using __this_cpu_*() since we now have preempt disabled;
>  - switching from smp_load_acquire() to READ_ONCE().
> 
> This is all safe because disabling preemption inhibits the RCU grace
> period exactly like rcu_read_lock().
> 
> Having preemption disabled allows using __this_cpu_*() provided the
> only access to the variable is in task context -- which is the case
> here.

Right. Read and Write from softirq happens after the user transitioned
to atomics.

> Furthermore, since we know changing fph->state to FR_ATOMIC demands a
> full RCU grace period we can rely on the implied smp_mb() from that to
> replace the acquire barrier().

That is the only part I struggle with but having a smp_mb() after a
grace period sounds reasonable.

> This is very similar to the percpu_down_read_internal() fast-path.
>
> The reason this is significant for PowerPC is that it uses the generic
> this_cpu_*() implementation which relies on local_irq_disable() (the
> x86 implementation relies on it being a single memop instruction to be
> IRQ-safe). Switching to preempt_disable() and __this_cpu*() avoids
> this IRQ state swizzling. Also, PowerPC needs LWSYNC for the ACQUIRE
> barrier, not having to use explicit barriers safes a bunch.
> 
> Combined this reduces the performance gap by half, down to some 5%.

Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Sebastian

  reply	other threads:[~2025-11-06 11:09 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-10 11:00 [PATCH v2 0/6] futex: Use RCU-based per-CPU reference counting Sebastian Andrzej Siewior
2025-07-10 11:00 ` [PATCH v2 1/6] selftests/futex: Adapt the private hash test to RCU related changes Sebastian Andrzej Siewior
2025-07-11 18:33   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-07-10 11:00 ` [PATCH v2 2/6] futex: Use RCU-based per-CPU reference counting instead of rcuref_t Sebastian Andrzej Siewior
2025-07-11 18:33   ` [tip: locking/futex] " tip-bot2 for Peter Zijlstra
2025-08-16  2:38     ` Sean Christopherson
2025-08-26  0:38       ` Sean Christopherson
2025-07-30 12:20   ` [PATCH v2 2/6] " André Draszik
2025-07-30 19:44     ` Thomas Gleixner
2025-08-01 14:59       ` André Draszik
2025-08-02 13:22       ` [tip: locking/urgent] futex: Move futex cleanup to __mmdrop() tip-bot2 for Thomas Gleixner
2025-08-21 17:39         ` Breno Leitao
2025-07-10 11:00 ` [PATCH v2 3/6] futex: Make futex_private_hash_get() static Sebastian Andrzej Siewior
2025-07-11 18:33   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-07-10 11:00 ` [PATCH v2 4/6] futex: Remove support for IMMUTABLE Sebastian Andrzej Siewior
2025-07-11 18:33   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-07-10 11:00 ` [PATCH v2 5/6] selftests/futex: " Sebastian Andrzej Siewior
2025-07-11 18:33   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-07-10 11:00 ` [PATCH v2 6/6] perf bench futex: " Sebastian Andrzej Siewior
2025-07-11 18:33   ` [tip: locking/futex] " tip-bot2 for Sebastian Andrzej Siewior
2025-07-15 15:59 ` [PATCH v2 0/6] futex: Use RCU-based per-CPU reference counting Shrikanth Hegde
2025-07-15 16:31   ` Sebastian Andrzej Siewior
2025-07-15 17:04     ` Shrikanth Hegde
2025-07-16 14:29       ` Peter Zijlstra
2025-07-16 18:21         ` Shrikanth Hegde
2025-11-06  9:29           ` Peter Zijlstra
2025-11-06 11:09             ` Sebastian Andrzej Siewior [this message]
2025-11-06 11:23               ` Peter Zijlstra
2025-11-06 20:17                 ` Paul E. McKenney
2025-11-06 11:40             ` [tip: locking/urgent] futex: Optimize per-cpu " tip-bot2 for Peter Zijlstra
2025-11-06 15:26               ` Shrikanth Hegde

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=20251106110907.noLpnulw@linutronix.de \
    --to=bigeasy@linutronix.de \
    --cc=andrealmeid@igalia.com \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=sshegde@linux.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=vschneid@redhat.com \
    /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