mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pranith Kumar <bobby.prani@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and
	infrastructure)), linux-kernel@vger.kernel.org (open list)
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/1] file: Avoid acquire on shared fd table lookups
Date: Wed,  4 Nov 2026 01:27:49 -0800	[thread overview]
Message-ID: <20261104092750.2998440-1-bobby.prani@gmail.com> (raw)

__fget_light() reads files->count to choose whether it can borrow an
fd without taking a file reference. The current acquire load applies
to both branches. Only the single-owner branch uses the count load
to order its subsequent fd table lookup against a concurrent
close_fd() and put_files_struct(). The shared-table branch obtains a
file reference under RCU instead.

Read the count without an acquire and use
smp_acquire__after_ctrl_dep() on the single-owner branch. The branch
provides the control dependency, and the barrier preserves acquire
ordering before the borrowed fd is read. This removes an acquire
barrier from each shared-table fdget() lookup on arm64.

With two threads sharing an fd table and each performing 10,000 pipe
write/read pairs on separate arm64 cores, performance improves 1.75%.

Signed-off-by: Pranith Kumar <bobby.prani@gmail.com>
---
 fs/file.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/file.c b/fs/file.c
index 4cd40dfa6129..20ab46434abe 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -1337,10 +1337,12 @@ static inline struct fd __fget_light(unsigned int fd, fmode_t mask)
 	 * entry combined with the new refcount - otherwise we could
 	 * return a file that is concurrently being freed.
 	 *
-	 * atomic_read_acquire() pairs with atomic_dec_and_test() in
-	 * put_files_struct().
+	 * The acquire on the single-owner path pairs with
+	 * atomic_dec_and_test() in put_files_struct(). The shared-table
+	 * path obtains its own file reference under RCU.
 	 */
-	if (likely(atomic_read_acquire(&files->count) == 1)) {
+	if (likely(atomic_read(&files->count) == 1)) {
+		smp_acquire__after_ctrl_dep();
 		file = files_lookup_fd_raw(files, fd);
 		if (!file || unlikely(file->f_mode & mask))
 			return EMPTY_FD;
-- 
2.47.3


                 reply	other threads:[~2026-11-04  9:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261104092750.2998440-1-bobby.prani@gmail.com \
    --to=bobby.prani@gmail.com \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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®