public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] f2fs: add a fast path in finish_preallocate_blocks()
@ 2025-03-25  8:13 Chao Yu
  2025-03-25  8:59 ` [f2fs-dev] " Zhiguo Niu
  2025-04-10  4:10 ` patchwork-bot+f2fs
  0 siblings, 2 replies; 3+ messages in thread
From: Chao Yu @ 2025-03-25  8:13 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, Chao Yu

This patch uses i_sem to protect access/update on f2fs_inode_info.flag
in finish_preallocate_blocks(), it avoids grabbing inode_lock() in
each open().

Signed-off-by: Chao Yu <chao@kernel.org>
---
v2:
- get rid of read lock during querying FI_OPENED_FILE once we held
inode lock.
 fs/f2fs/file.c | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index abbcbb5865a3..a71946976761 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -554,19 +554,21 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
 
 static int finish_preallocate_blocks(struct inode *inode)
 {
-	int ret;
+	int ret = 0;
+	bool opened;
 
-	inode_lock(inode);
-	if (is_inode_flag_set(inode, FI_OPENED_FILE)) {
-		inode_unlock(inode);
+	f2fs_down_read(&F2FS_I(inode)->i_sem);
+	opened = is_inode_flag_set(inode, FI_OPENED_FILE);
+	f2fs_up_read(&F2FS_I(inode)->i_sem);
+	if (opened)
 		return 0;
-	}
 
-	if (!file_should_truncate(inode)) {
-		set_inode_flag(inode, FI_OPENED_FILE);
-		inode_unlock(inode);
-		return 0;
-	}
+	inode_lock(inode);
+	if (is_inode_flag_set(inode, FI_OPENED_FILE))
+		goto out_unlock;
+
+	if (!file_should_truncate(inode))
+		goto out_update;
 
 	f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
 	filemap_invalidate_lock(inode->i_mapping);
@@ -576,16 +578,17 @@ static int finish_preallocate_blocks(struct inode *inode)
 
 	filemap_invalidate_unlock(inode->i_mapping);
 	f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
-
-	if (!ret)
-		set_inode_flag(inode, FI_OPENED_FILE);
-
-	inode_unlock(inode);
 	if (ret)
-		return ret;
+		goto out_unlock;
 
 	file_dont_truncate(inode);
-	return 0;
+out_update:
+	f2fs_down_write(&F2FS_I(inode)->i_sem);
+	set_inode_flag(inode, FI_OPENED_FILE);
+	f2fs_up_write(&F2FS_I(inode)->i_sem);
+out_unlock:
+	inode_unlock(inode);
+	return ret;
 }
 
 static int f2fs_file_open(struct inode *inode, struct file *filp)
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs: add a fast path in finish_preallocate_blocks()
  2025-03-25  8:13 [PATCH v2] f2fs: add a fast path in finish_preallocate_blocks() Chao Yu
@ 2025-03-25  8:59 ` Zhiguo Niu
  2025-04-10  4:10 ` patchwork-bot+f2fs
  1 sibling, 0 replies; 3+ messages in thread
From: Zhiguo Niu @ 2025-03-25  8:59 UTC (permalink / raw)
  To: Chao Yu; +Cc: jaegeuk, linux-kernel, linux-f2fs-devel

Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
于2025年3月25日周二 16:15写道:
>
> This patch uses i_sem to protect access/update on f2fs_inode_info.flag
> in finish_preallocate_blocks(), it avoids grabbing inode_lock() in
> each open().
>
> Signed-off-by: Chao Yu <chao@kernel.org>

Reviewed-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
thanks!
> ---
> v2:
> - get rid of read lock during querying FI_OPENED_FILE once we held
> inode lock.
>  fs/f2fs/file.c | 37 ++++++++++++++++++++-----------------
>  1 file changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index abbcbb5865a3..a71946976761 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -554,19 +554,21 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
>
>  static int finish_preallocate_blocks(struct inode *inode)
>  {
> -       int ret;
> +       int ret = 0;
> +       bool opened;
>
> -       inode_lock(inode);
> -       if (is_inode_flag_set(inode, FI_OPENED_FILE)) {
> -               inode_unlock(inode);
> +       f2fs_down_read(&F2FS_I(inode)->i_sem);
> +       opened = is_inode_flag_set(inode, FI_OPENED_FILE);
> +       f2fs_up_read(&F2FS_I(inode)->i_sem);
> +       if (opened)
>                 return 0;
> -       }
>
> -       if (!file_should_truncate(inode)) {
> -               set_inode_flag(inode, FI_OPENED_FILE);
> -               inode_unlock(inode);
> -               return 0;
> -       }
> +       inode_lock(inode);
> +       if (is_inode_flag_set(inode, FI_OPENED_FILE))
> +               goto out_unlock;
> +
> +       if (!file_should_truncate(inode))
> +               goto out_update;
>
>         f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
>         filemap_invalidate_lock(inode->i_mapping);
> @@ -576,16 +578,17 @@ static int finish_preallocate_blocks(struct inode *inode)
>
>         filemap_invalidate_unlock(inode->i_mapping);
>         f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
> -
> -       if (!ret)
> -               set_inode_flag(inode, FI_OPENED_FILE);
> -
> -       inode_unlock(inode);
>         if (ret)
> -               return ret;
> +               goto out_unlock;
>
>         file_dont_truncate(inode);
> -       return 0;
> +out_update:
> +       f2fs_down_write(&F2FS_I(inode)->i_sem);
> +       set_inode_flag(inode, FI_OPENED_FILE);
> +       f2fs_up_write(&F2FS_I(inode)->i_sem);
> +out_unlock:
> +       inode_unlock(inode);
> +       return ret;
>  }
>
>  static int f2fs_file_open(struct inode *inode, struct file *filp)
> --
> 2.48.1
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs: add a fast path in finish_preallocate_blocks()
  2025-03-25  8:13 [PATCH v2] f2fs: add a fast path in finish_preallocate_blocks() Chao Yu
  2025-03-25  8:59 ` [f2fs-dev] " Zhiguo Niu
@ 2025-04-10  4:10 ` patchwork-bot+f2fs
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+f2fs @ 2025-04-10  4:10 UTC (permalink / raw)
  To: Chao Yu; +Cc: jaegeuk, linux-kernel, linux-f2fs-devel

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Tue, 25 Mar 2025 16:13:21 +0800 you wrote:
> This patch uses i_sem to protect access/update on f2fs_inode_info.flag
> in finish_preallocate_blocks(), it avoids grabbing inode_lock() in
> each open().
> 
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> v2:
> - get rid of read lock during querying FI_OPENED_FILE once we held
> inode lock.
>  fs/f2fs/file.c | 37 ++++++++++++++++++++-----------------
>  1 file changed, 20 insertions(+), 17 deletions(-)

Here is the summary with links:
  - [f2fs-dev,v2] f2fs: add a fast path in finish_preallocate_blocks()
    https://git.kernel.org/jaegeuk/f2fs/c/ecf68ffee7be

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-10  4:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-25  8:13 [PATCH v2] f2fs: add a fast path in finish_preallocate_blocks() Chao Yu
2025-03-25  8:59 ` [f2fs-dev] " Zhiguo Niu
2025-04-10  4:10 ` patchwork-bot+f2fs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox