All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] file: fix and document ordering for lockless fd lookup wrt to file_ref
@ 2026-11-05 13:18 Christian Brauner
  2026-11-05 13:18 ` [PATCH 1/5] file: depend on the reloaded pointer in __fget_files_rcu() Christian Brauner
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Christian Brauner @ 2026-11-05 13:18 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Alexander Viro, Jan Kara, Peter Zijlstra, Paul E. McKenney,
	Christian Brauner (Amutable)

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-05 13:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05 13:18 [PATCH 0/5] file: fix and document ordering for lockless fd lookup wrt to file_ref Christian Brauner
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

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.