Linux filesystem development
 help / color / mirror / Atom feed
From: Mateusz Guzik <mjguzik@gmail.com>
To: brauner@kernel.org
Cc: viro@zeniv.linux.org.uk, jack@suse.cz,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Mateusz Guzik <mjguzik@gmail.com>
Subject: [RFC PATCH 0/2] avoid the extra atomic on a ref when closing a fd
Date: Tue,  4 Mar 2025 17:36:29 +0100	[thread overview]
Message-ID: <20250304163631.490769-1-mjguzik@gmail.com> (raw)

The stock kernel transitioning the file to no refs held penalizes the
caller with an extra atomic to block any increments.

For cases where the file is highly likely to be going away this is
easily avoidable.

The obvious place is the close() system call, patched in 2/2.

But part from that possible callers (to be evaluated):
- clean up after failed open (common)
- close_range
- close on exec
- process exit

So 1/1 adds some routines and 2/2 uses one of them. The rest can be
tackled on later or I can send a v2 with more places sorted out.

In the open+close case the win is very modest because of the following
problems:
- kmem and memcg having terrible performance
- putname using an atomic (I have a wip to whack that)
- open performing an extra ref/unref on the dentry (there are patches to
  do it, including by Al. I'll be mailing about it separately)
- creds using atomics (I have a wip to whack that)
- apparmor using atomics (ditto, same mechanism)

On top of that I have a WIP patch to dodge some of the work at lookup
itself.

All in all there is several % avoidably lost here.

Mateusz Guzik (2):
  file: add fput and file_ref_put routines optimized for use when
    closing a fd
  fs: use fput_close() in close()

 fs/file.c                | 75 ++++++++++++++++++++++++++++++----------
 fs/file_table.c          | 72 +++++++++++++++++++++++++++-----------
 fs/open.c                |  2 +-
 include/linux/file.h     |  2 ++
 include/linux/file_ref.h |  1 +
 5 files changed, 112 insertions(+), 40 deletions(-)

-- 
2.43.0


             reply	other threads:[~2025-03-04 16:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-04 16:36 Mateusz Guzik [this message]
2025-03-04 16:36 ` [PATCH 1/2] file: add fput and file_ref_put routines optimized for use when closing a fd Mateusz Guzik
2025-03-04 16:36 ` [PATCH 2/2] fs: use fput_close() in close() Mateusz Guzik

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=20250304163631.490769-1-mjguzik@gmail.com \
    --to=mjguzik@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