Skip to content

file: fix and document ordering for lockless fd lookup wrt to file_ref

Christian Brauner linux-fsdevel 1 version New

Get series with b4
b4 am [email protected] change-id 20261105-work-file_ref-ordering-00ddcd27bf2d

Versions newest first

  1. v1 Latest5 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5file: depend on the reloaded pointer in __fget_files_rcu()fs/file.c+24 -10 replies
2/5file_ref: use acquire ordering in file_ref_get()fs/file.c include/linux/file_ref.h+15 -120 replies
3/5file_ref: document why file_ref_put() stays fully orderedinclude/linux/file_ref.h+11 -00 replies
4/5Documentation/litmus-tests: add the file reference count testsDocumentation/litmus-tests/README Documentation/litmus-tests/fs/file-ref-get-acquire-recheck.litmus Documentation/litmus-tests/fs/file-ref-get-relaxed-recheck.litmus +4 more+448 -00 replies
5/5Documentation: update the lock-free file lookup in files.rstDocumentation/filesystems/files.rst+30 -180 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] file: fix and document ordering for lockless fd lookup wrt to file_ref

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.

---
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