From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
Peter Zijlstra <peterz@infradead.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Christian Brauner (Amutable)" <brauner@kernel.org>
Subject: [PATCH 0/5] file: fix and document ordering for lockless fd lookup wrt to file_ref
Date: Thu, 05 Nov 2026 14:18:04 +0100 [thread overview]
Message-ID: <20261105-work-file_ref-ordering-v1-0-8713f4876b7b@kernel.org> (raw)
I went through include/linux/file_ref.h and its lockless users with a
TLA+ model and a set of LKMM litmus tests:
__fget_files_rcu(), __get_file_rcu(), fput() and file_ref_put_close()
against close(), open() and the SLAB_TYPESAFE_BY_RCU recycling of the
file. The protocol itself is fine but there are a few minor things:
* __fget_files_rcu() lost the dependency on its reload in
253ca8678d30 making it possible to see f_mode and f_op from an earlier
lifetime of a file on arm64 and power.
* file_ref_get() only needs acquire ordering. The reload has to be
ordered after the increment. This is all we need.
* Add some missing documentation why we need full ordering during put.
This also adds litmus tests for this stuff. Here are the numbers after
this series:
instructions cycles
fcntl(F_GETFL) 457 -> 463 217.6 -> 218.1
fstat() 1052 -> 1058 455.4 -> 454.1
poll(), 16 fds 2394 -> 2458 828.7 -> 833.4
pipe write+read 2261 -> 2271 925.1 -> 913.0
unix socketpair 3269 -> 3277 1202.3 -> 1184.8
io_uring_enter() 1036 -> 1038 284.6 -> 286.5
registered file 942 -> 942 262.6 -> 263.2
open()+close() 4277 -> 4277 1365.7 -> 1334.7
dup()+close() 869 -> 873 525.1 -> 520.5
It's all within noise in terms of performance.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
Christian Brauner (5):
file: depend on the reloaded pointer in __fget_files_rcu()
file_ref: use acquire ordering in file_ref_get()
file_ref: document why file_ref_put() stays fully ordered
Documentation/litmus-tests: add the file reference count tests
Documentation: update the lock-free file lookup in files.rst
Documentation/filesystems/files.rst | 48 +++++++++-----
Documentation/litmus-tests/README | 57 ++++++++++++++++
.../fs/file-ref-get-acquire-recheck.litmus | 66 +++++++++++++++++++
.../fs/file-ref-get-relaxed-recheck.litmus | 50 ++++++++++++++
.../fs/file-ref-put-full-handoff.litmus | 76 ++++++++++++++++++++++
.../fs/file-ref-put-release-handoff.litmus | 66 +++++++++++++++++++
.../fs/file-ref-reload-dep-field.litmus | 74 +++++++++++++++++++++
.../fs/file-ref-reload-nodep-field.litmus | 59 +++++++++++++++++
fs/file.c | 42 +++++++++---
include/linux/file_ref.h | 21 +++++-
10 files changed, 528 insertions(+), 31 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261105-work-file_ref-ordering-00ddcd27bf2d
next reply other threads:[~2026-11-05 13:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 13:18 Christian Brauner [this message]
2026-11-05 13:18 ` [PATCH 1/5] file: depend on the reloaded pointer in __fget_files_rcu() Christian Brauner
2026-11-05 13:18 ` [PATCH 2/5] file_ref: use acquire ordering in file_ref_get() Christian Brauner
2026-11-05 13:18 ` [PATCH 3/5] file_ref: document why file_ref_put() stays fully ordered Christian Brauner
2026-11-05 13:18 ` [PATCH 4/5] Documentation/litmus-tests: add the file reference count tests Christian Brauner
2026-11-05 13:18 ` [PATCH 5/5] Documentation: update the lock-free file lookup in files.rst Christian Brauner
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=20261105-work-file_ref-ordering-v1-0-8713f4876b7b@kernel.org \
--to=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.