diff mbox series

[f2fs-dev] f2fs: use inode_lock_shared instead of inode_lock in f2fs_seek_block()

Message ID 20231021121907.2908801-1-xirui.zhang@vivo.com (mailing list archive)
State New
Headers show
Series [f2fs-dev] f2fs: use inode_lock_shared instead of inode_lock in f2fs_seek_block() | expand

Commit Message

zhangxirui Oct. 21, 2023, 12:19 p.m. UTC
inode_lock_shared() -> down_read(&inode->i_rwsem)
       inode_lock() -> down_write(&inode->i_rwsem)

Inode is not updated in f2fs_seek_block(), so there is no need
to hold write lock, use read lock for more efficiency.

Signed-off-by: zhangxirui <xirui.zhang@vivo.com>
---
 fs/f2fs/file.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--
2.39.0

Comments

Chao Yu Nov. 7, 2023, 2:16 p.m. UTC | #1
On 2023/10/21 20:19, zhangxirui wrote:
> inode_lock_shared() -> down_read(&inode->i_rwsem)
>         inode_lock() -> down_write(&inode->i_rwsem)
> 
> Inode is not updated in f2fs_seek_block(), so there is no need
> to hold write lock, use read lock for more efficiency.
> 
> Signed-off-by: zhangxirui <xirui.zhang@vivo.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,
diff mbox series

Patch

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 304d0516d3a4..d600ff48914f 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -418,7 +418,7 @@  static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
        loff_t isize;
        int err = 0;

-       inode_lock(inode);
+       inode_lock_shared(inode);

        isize = i_size_read(inode);
        if (offset >= isize)
@@ -483,10 +483,10 @@  static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
 found:
        if (whence == SEEK_HOLE && data_ofs > isize)
                data_ofs = isize;
-       inode_unlock(inode);
+       inode_unlock_shared(inode);
        return vfs_setpos(file, data_ofs, maxbytes);
 fail:
-       inode_unlock(inode);
+       inode_unlock_shared(inode);
        return -ENXIO;
 }