Re: [PATCH 1/1] file: Avoid acquire on shared fd table lookups

From: Christian Brauner

Date: Fri Nov 06 2026 - 05:10:38 EST


On Wed, Nov 04, 2026 at 01:27:49AM -0800, Pranith Kumar wrote:
> __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@xxxxxxxxx>
> ---
> 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.
> */

This needs a litmus test, a TLA+ model, and detailed performance numbers
with reproducer for both the shared case and the non-shared case.