[3/4] f2fs: clean up new_curseg()

Message ID 20240226013208.2389246-3-chao@kernel.org
State New
Headers
Series [1/4] f2fs: fix blkofs_end correctly in f2fs_migrate_blocks() |

Commit Message

Chao Yu Feb. 26, 2024, 1:32 a.m. UTC
  Move f2fs_valid_pinned_area() check logic from new_curseg() to
get_new_segment(), it can avoid calling __set_free() if it fails
to find free segment in conventional zone for pinned file.

Signed-off-by: Chao Yu <chao@kernel.org>
---
 fs/f2fs/segment.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
  

Comments

Daeho Jeong Feb. 29, 2024, 5:58 p.m. UTC | #1
Reviewed-by: Daeho Jeong <daehojeong@google.com>

Thanks,

On Sun, Feb 25, 2024 at 5:33 PM Chao Yu <chao@kernel.org> wrote:
>
> Move f2fs_valid_pinned_area() check logic from new_curseg() to
> get_new_segment(), it can avoid calling __set_free() if it fails
> to find free segment in conventional zone for pinned file.
>
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
>  fs/f2fs/segment.c | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 847fe0b7f29f..c159b0985596 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -2715,12 +2715,19 @@ static int get_new_segment(struct f2fs_sb_info *sbi,
>  got_it:
>         /* set it as dirty segment in free segmap */
>         f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
> +
> +       /* no free section in conventional zone */
> +       if (new_sec && pinning &&
> +               !f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) {
> +               ret = -EAGAIN;
> +               goto out_unlock;
> +       }
>         __set_inuse(sbi, segno);
>         *newseg = segno;
>  out_unlock:
>         spin_unlock(&free_i->segmap_lock);
>
> -       if (ret) {
> +       if (ret == -ENOSPC) {
>                 f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT);
>                 f2fs_bug_on(sbi, 1);
>         }
> @@ -2796,19 +2803,17 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
>         struct curseg_info *curseg = CURSEG_I(sbi, type);
>         unsigned int segno = curseg->segno;
>         bool pinning = type == CURSEG_COLD_DATA_PINNED;
> +       int ret;
>
>         if (curseg->inited)
>                 write_sum_page(sbi, curseg->sum_blk, GET_SUM_BLOCK(sbi, segno));
>
>         segno = __get_next_segno(sbi, type);
> -       if (get_new_segment(sbi, &segno, new_sec, pinning)) {
> -               curseg->segno = NULL_SEGNO;
> -               return -ENOSPC;
> -       }
> -       if (new_sec && pinning &&
> -           !f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) {
> -               __set_free(sbi, segno);
> -               return -EAGAIN;
> +       ret = get_new_segment(sbi, &segno, new_sec, pinning);
> +       if (ret) {
> +               if (ret == -ENOSPC)
> +                       curseg->segno = NULL_SEGNO;
> +               return ret;
>         }
>
>         curseg->next_segno = segno;
> --
> 2.40.1
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
  

Patch

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 847fe0b7f29f..c159b0985596 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2715,12 +2715,19 @@  static int get_new_segment(struct f2fs_sb_info *sbi,
 got_it:
 	/* set it as dirty segment in free segmap */
 	f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
+
+	/* no free section in conventional zone */
+	if (new_sec && pinning &&
+		!f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) {
+		ret = -EAGAIN;
+		goto out_unlock;
+	}
 	__set_inuse(sbi, segno);
 	*newseg = segno;
 out_unlock:
 	spin_unlock(&free_i->segmap_lock);
 
-	if (ret) {
+	if (ret == -ENOSPC) {
 		f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT);
 		f2fs_bug_on(sbi, 1);
 	}
@@ -2796,19 +2803,17 @@  static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
 	struct curseg_info *curseg = CURSEG_I(sbi, type);
 	unsigned int segno = curseg->segno;
 	bool pinning = type == CURSEG_COLD_DATA_PINNED;
+	int ret;
 
 	if (curseg->inited)
 		write_sum_page(sbi, curseg->sum_blk, GET_SUM_BLOCK(sbi, segno));
 
 	segno = __get_next_segno(sbi, type);
-	if (get_new_segment(sbi, &segno, new_sec, pinning)) {
-		curseg->segno = NULL_SEGNO;
-		return -ENOSPC;
-	}
-	if (new_sec && pinning &&
-	    !f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) {
-		__set_free(sbi, segno);
-		return -EAGAIN;
+	ret = get_new_segment(sbi, &segno, new_sec, pinning);
+	if (ret) {
+		if (ret == -ENOSPC)
+			curseg->segno = NULL_SEGNO;
+		return ret;
 	}
 
 	curseg->next_segno = segno;