fuse: add fast path for fuse_range_is_writeback
authoryangyun <yangyun50@huawei.com>
Wed, 14 Aug 2024 09:36:00 +0000 (17:36 +0800)
committerMiklos Szeredi <mszeredi@redhat.com>
Thu, 29 Aug 2024 09:43:12 +0000 (11:43 +0200)
In some cases, the fi->writepages may be empty. And there is no need
to check fi->writepages with spin_lock, which may have an impact on
performance due to lock contention. For example, in scenarios where
multiple readers read the same file without any writers, or where
the page cache is not enabled.

Also remove the outdated comment since commit 6b2fb79963fb ("fuse:
optimize writepages search") has optimize the situation by replacing
list with rb-tree.

Signed-off-by: yangyun <yangyun50@huawei.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/file.c

index ed76121f73f2e0f11067738e9eaa77ad0db4a19c..b41c032d1c6d884403b9b7446548cd70ca4b233e 100644 (file)
@@ -448,9 +448,6 @@ static struct fuse_writepage_args *fuse_find_writeback(struct fuse_inode *fi,
 
 /*
  * Check if any page in a range is under writeback
- *
- * This is currently done by walking the list of writepage requests
- * for the inode, which can be pretty inefficient.
  */
 static bool fuse_range_is_writeback(struct inode *inode, pgoff_t idx_from,
                                   pgoff_t idx_to)
@@ -458,6 +455,9 @@ static bool fuse_range_is_writeback(struct inode *inode, pgoff_t idx_from,
        struct fuse_inode *fi = get_fuse_inode(inode);
        bool found;
 
+       if (RB_EMPTY_ROOT(&fi->writepages))
+               return false;
+
        spin_lock(&fi->lock);
        found = fuse_find_writeback(fi, idx_from, idx_to);
        spin_unlock(&fi->lock);