]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
Merge tag 'vfs-6.15-rc1.file' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 24 Mar 2025 20:19:17 +0000 (13:19 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 24 Mar 2025 20:19:17 +0000 (13:19 -0700)
Pull vfs file handling updates from Christian Brauner:
 "This contains performance improvements for struct file's new refcount
  mechanism and various other performance work:

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

     Add file_ref_put_close() to better handle the common case where
     closing a file descriptor also operates on the last reference and
     build fput_close_sync() and fput_close() on top of it. This brings
     about 1% performance improvement by eliding one atomic in the
     common case.

   - Predict no error in close() since the vast majority of the time
     system call returns 0.

   - Reduce the work done in fdget_pos() by predicting that the file was
     found and by explicitly comparing the reference count to one and
     ignoring the dead zone"

* tag 'vfs-6.15-rc1.file' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
  fs: reduce work in fdget_pos()
  fs: use fput_close() in path_openat()
  fs: use fput_close() in filp_close()
  fs: use fput_close_sync() in close()
  file: add fput and file_ref_put routines optimized for use when closing a fd
  fs: predict no error in close()

1  2 
fs/file.c
fs/file_table.c
fs/internal.h
fs/namei.c
fs/open.c

diff --cc fs/file.c
index 40fed4501aab6d7b468531e334f9a3a0fb66ccdd,134274446bf63b00311bcc947984b3daeb8d6904..dc3f7e120e3e5d51cac2567e431efa62325882e8
+++ b/fs/file.c
@@@ -1179,20 -1183,15 +1184,25 @@@ struct fd fdget_raw(unsigned int fd
   */
  static inline bool file_needs_f_pos_lock(struct file *file)
  {
-       return (file->f_mode & FMODE_ATOMIC_POS) &&
-               (file_count(file) > 1 || file->f_op->iterate_shared);
+       if (!(file->f_mode & FMODE_ATOMIC_POS))
+               return false;
+       if (__file_ref_read_raw(&file->f_ref) != FILE_REF_ONEREF)
+               return true;
+       if (file->f_op->iterate_shared)
+               return true;
+       return false;
  }
  
 +bool file_seek_cur_needs_f_lock(struct file *file)
 +{
 +      if (!(file->f_mode & FMODE_ATOMIC_POS) && !file->f_op->iterate_shared)
 +              return false;
 +
 +      VFS_WARN_ON_ONCE((file_count(file) > 1) &&
 +                       !mutex_is_locked(&file->f_pos_lock));
 +      return true;
 +}
 +
  struct fd fdget_pos(unsigned int fd)
  {
        struct fd f = fdget(fd);
diff --cc fs/file_table.c
Simple merge
diff --cc fs/internal.h
Simple merge
diff --cc fs/namei.c
Simple merge
diff --cc fs/open.c
Simple merge