[PATCH v6 0/3] assorted ->i_count changes + extension of lockless handling

Mateusz Guzik posted 3 patches 1 month, 3 weeks ago
arch/powerpc/platforms/cell/spufs/file.c |  2 +-
fs/btrfs/inode.c                         |  2 +-
fs/ceph/mds_client.c                     |  2 +-
fs/dcache.c                              |  4 +
fs/ext4/ialloc.c                         |  4 +-
fs/hpfs/inode.c                          |  2 +-
fs/inode.c                               | 96 ++++++++++++++++++++----
fs/nfs/inode.c                           |  4 +-
fs/smb/client/inode.c                    |  2 +-
fs/ubifs/super.c                         |  2 +-
fs/xfs/xfs_inode.c                       |  2 +-
fs/xfs/xfs_trace.h                       |  2 +-
include/linux/fs.h                       | 13 ++++
include/trace/events/filelock.h          |  2 +-
security/landlock/fs.c                   |  2 +-
15 files changed, 112 insertions(+), 29 deletions(-)
[PATCH v6 0/3] assorted ->i_count changes + extension of lockless handling
Posted by Mateusz Guzik 1 month, 3 weeks ago
The stock kernel support partial lockless in handling in that iput() can
decrement any value > 1. Any ref acquire however requires the spinlock.

With this patchset ref acquires when the value was already at least 1
also become lockless. That is, only transitions 0->1 and 1->0 take the
lock.

I verified when nfs calls into the hash taking the lock is typically
avoided. Similarly, btrfs likes to igrab() and avoids the lock.
However, I have to fully admit I did not perform any benchmarks. While
cleaning stuff up I noticed lockless operation is almost readily
available so I went for it.

Clean-up wise, the icount_read_once() stuff lines up with inode_state_read_once().
The prefix is different but I opted to not change it due to igrab(), ihold() et al.

v6
- remove the DONTCACHE vs drop patch for the time being
- s/igrab_try_lockless/igrab_from_hash/

v5:
- reword some commentary
- add unlikely to the new icount check in iput_final()

v4:
- squash icount_read patches
- use icount_read_once in the new ihold assert, reported by syzbot
- squash lockless ref acquire patches, rewrite new comments

v3:
- tidy up ihold
- add lockless handling to the hash

Mateusz Guzik (3):
  fs: add icount_read_once() and stop open-coding ->i_count loads
  fs: relocate and tidy up ihold()
  fs: allow lockless ->i_count bumps as long as it does not transition
    0->1

 arch/powerpc/platforms/cell/spufs/file.c |  2 +-
 fs/btrfs/inode.c                         |  2 +-
 fs/ceph/mds_client.c                     |  2 +-
 fs/dcache.c                              |  4 +
 fs/ext4/ialloc.c                         |  4 +-
 fs/hpfs/inode.c                          |  2 +-
 fs/inode.c                               | 96 ++++++++++++++++++++----
 fs/nfs/inode.c                           |  4 +-
 fs/smb/client/inode.c                    |  2 +-
 fs/ubifs/super.c                         |  2 +-
 fs/xfs/xfs_inode.c                       |  2 +-
 fs/xfs/xfs_trace.h                       |  2 +-
 include/linux/fs.h                       | 13 ++++
 include/trace/events/filelock.h          |  2 +-
 security/landlock/fs.c                   |  2 +-
 15 files changed, 112 insertions(+), 29 deletions(-)

-- 
2.48.1
Re: [PATCH v6 0/3] assorted ->i_count changes + extension of lockless handling
Posted by Christian Brauner 1 month, 3 weeks ago
On Tue, 21 Apr 2026 20:25:35 +0200, Mateusz Guzik wrote:
> The stock kernel support partial lockless in handling in that iput() can
> decrement any value > 1. Any ref acquire however requires the spinlock.
> 
> With this patchset ref acquires when the value was already at least 1
> also become lockless. That is, only transitions 0->1 and 1->0 take the
> lock.
> 
> [...]

Applied to the vfs-7.2.inode branch of the vfs/vfs.git tree.
Patches in the vfs-7.2.inode branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: master

[1/3] fs: add icount_read_once() and stop open-coding ->i_count loads
      https://git.kernel.org/vfs/vfs/c/11abd8ebfe89
[2/3] fs: relocate and tidy up ihold()
      https://git.kernel.org/vfs/vfs/c/f16fbfa2a006
[3/3] fs: allow lockless ->i_count bumps as long as it does not transition 0->1
      https://git.kernel.org/vfs/vfs/c/e22934526e6d