All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Sheng Yong <shengyong@oppo.com>
Cc: daehojeong@google.com, linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v2] f2fs: only fragment segment in the same section
Date: Tue, 9 Jul 2024 21:37:51 +0000	[thread overview]
Message-ID: <Zo2tr92oxPEuKBFm@google.com> (raw)
In-Reply-To: <20240625121512.3877754-1-shengyong@oppo.com>

On 06/25, Sheng Yong wrote:
> When new_curseg() is allocating a new segment, if mode=fragment:xxx is
> switched on in large section scenario, __get_next_segno() will select
> the next segno randomly in the range of [0, maxsegno] in order to
> fragment segments.
> 
> If the candidate segno is free, get_new_segment() will use it directly
> as the new segment.
> 
> However, if the section of the candidate is not empty, and some other
> segments have already been used, and have a different type (e.g NODE)
> with the candidate (e.g DATA), GC will complain inconsistent segment
> type later.
> 
> This could be reproduced by the following steps:
> 
>   dd if=/dev/zero of=test.img bs=1M count=10240
>   mkfs.f2fs -s 128 test.img
>   mount -t f2fs test.img /mnt -o mode=fragment:block
>   echo 1 > /sys/fs/f2fs/loop0/max_fragment_chunk
>   echo 512 > /sys/fs/f2fs/loop0/max_fragment_hole
>   dd if=/dev/zero of=/mnt/testfile bs=4K count=100
>   umount /mnt
> 
>   F2FS-fs (loop0): Inconsistent segment (4377) type [0, 1] in SSA and SIT
> 
> In order to allow simulating segment fragmentation in large section
> scenario, this patch reduces the candidate range:
>  * if curseg is the last segment in the section, return curseg->segno
>    to make get_new_segment() itself find the next free segment.
>  * if curseg is in the middle of the secion, select candicate randomly in
>    the range of [curseg + 1, last_seg_in_the_same_section] to keep type
>    consistent.
> 
> Signed-off-by: Sheng Yong <shengyong@oppo.com>
> ---
> v2: update commit msg
> ---
>  fs/f2fs/segment.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index a0ce3d080f80a..55d474f5c2103 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -2782,10 +2782,21 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)
>  {
>  	struct curseg_info *curseg = CURSEG_I(sbi, type);
>  	unsigned short seg_type = curseg->seg_type;
> +	unsigned int hint;
>  
>  	sanity_check_seg_type(sbi, seg_type);
> -	if (f2fs_need_rand_seg(sbi))
> -		return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi));
> +	if (f2fs_need_rand_seg(sbi)) {
> +		if (__is_large_section(sbi)) {
> +			hint = GET_SEC_FROM_SEG(sbi, curseg->segno);
> +			if (GET_SEC_FROM_SEG(sbi, curseg->segno + 1) != hint)
> +				return curseg->segno;
> +			return get_random_u32_inclusive(curseg->segno + 1,
> +					GET_SEG_FROM_SEC(sbi, hint + 1) - 1);
> +		} else {
> +			return get_random_u32_below(MAIN_SECS(sbi) *
> +						SEGS_PER_SEC(sbi));
> +		}
> +	}
>  
>  	if (__is_large_section(sbi))
>  		return curseg->segno;

	if (__is_large_section(sbi)) {
		if (f2fs_need_rand_seg(sbi)) {
			unsigned int hint = GET_SEC_FROM_SEG(sbi, curseg->segno);
			if (GET_SEC_FROM_SEG(sbi, curseg->segno + 1) != hint)
				return curseg->segno;
			return get_random_u32_inclusive(curseg->segno + 1,
					GET_SEG_FROM_SEC(sbi, hint + 1) - 1);
		}
		return curseg->segno;
	} else if (f2fs_need_rand_seg(sbi)) {
		return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi));
	}

> -- 
> 2.40.1


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

WARNING: multiple messages have this Message-ID (diff)
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Sheng Yong <shengyong@oppo.com>
Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, daehojeong@google.com
Subject: Re: [PATCH v2] f2fs: only fragment segment in the same section
Date: Tue, 9 Jul 2024 21:37:51 +0000	[thread overview]
Message-ID: <Zo2tr92oxPEuKBFm@google.com> (raw)
In-Reply-To: <20240625121512.3877754-1-shengyong@oppo.com>

On 06/25, Sheng Yong wrote:
> When new_curseg() is allocating a new segment, if mode=fragment:xxx is
> switched on in large section scenario, __get_next_segno() will select
> the next segno randomly in the range of [0, maxsegno] in order to
> fragment segments.
> 
> If the candidate segno is free, get_new_segment() will use it directly
> as the new segment.
> 
> However, if the section of the candidate is not empty, and some other
> segments have already been used, and have a different type (e.g NODE)
> with the candidate (e.g DATA), GC will complain inconsistent segment
> type later.
> 
> This could be reproduced by the following steps:
> 
>   dd if=/dev/zero of=test.img bs=1M count=10240
>   mkfs.f2fs -s 128 test.img
>   mount -t f2fs test.img /mnt -o mode=fragment:block
>   echo 1 > /sys/fs/f2fs/loop0/max_fragment_chunk
>   echo 512 > /sys/fs/f2fs/loop0/max_fragment_hole
>   dd if=/dev/zero of=/mnt/testfile bs=4K count=100
>   umount /mnt
> 
>   F2FS-fs (loop0): Inconsistent segment (4377) type [0, 1] in SSA and SIT
> 
> In order to allow simulating segment fragmentation in large section
> scenario, this patch reduces the candidate range:
>  * if curseg is the last segment in the section, return curseg->segno
>    to make get_new_segment() itself find the next free segment.
>  * if curseg is in the middle of the secion, select candicate randomly in
>    the range of [curseg + 1, last_seg_in_the_same_section] to keep type
>    consistent.
> 
> Signed-off-by: Sheng Yong <shengyong@oppo.com>
> ---
> v2: update commit msg
> ---
>  fs/f2fs/segment.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index a0ce3d080f80a..55d474f5c2103 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -2782,10 +2782,21 @@ static unsigned int __get_next_segno(struct f2fs_sb_info *sbi, int type)
>  {
>  	struct curseg_info *curseg = CURSEG_I(sbi, type);
>  	unsigned short seg_type = curseg->seg_type;
> +	unsigned int hint;
>  
>  	sanity_check_seg_type(sbi, seg_type);
> -	if (f2fs_need_rand_seg(sbi))
> -		return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi));
> +	if (f2fs_need_rand_seg(sbi)) {
> +		if (__is_large_section(sbi)) {
> +			hint = GET_SEC_FROM_SEG(sbi, curseg->segno);
> +			if (GET_SEC_FROM_SEG(sbi, curseg->segno + 1) != hint)
> +				return curseg->segno;
> +			return get_random_u32_inclusive(curseg->segno + 1,
> +					GET_SEG_FROM_SEC(sbi, hint + 1) - 1);
> +		} else {
> +			return get_random_u32_below(MAIN_SECS(sbi) *
> +						SEGS_PER_SEC(sbi));
> +		}
> +	}
>  
>  	if (__is_large_section(sbi))
>  		return curseg->segno;

	if (__is_large_section(sbi)) {
		if (f2fs_need_rand_seg(sbi)) {
			unsigned int hint = GET_SEC_FROM_SEG(sbi, curseg->segno);
			if (GET_SEC_FROM_SEG(sbi, curseg->segno + 1) != hint)
				return curseg->segno;
			return get_random_u32_inclusive(curseg->segno + 1,
					GET_SEG_FROM_SEC(sbi, hint + 1) - 1);
		}
		return curseg->segno;
	} else if (f2fs_need_rand_seg(sbi)) {
		return get_random_u32_below(MAIN_SECS(sbi) * SEGS_PER_SEC(sbi));
	}

> -- 
> 2.40.1

  parent reply	other threads:[~2024-07-09 21:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25  7:58 [f2fs-dev] [PATCH] f2fs: only fragment segment in the same section Sheng Yong via Linux-f2fs-devel
2024-06-25  7:58 ` Sheng Yong
2024-06-25 12:15 ` [f2fs-dev] [PATCH v2] " Sheng Yong via Linux-f2fs-devel
2024-06-25 12:15   ` Sheng Yong
2024-06-25 14:12   ` [f2fs-dev] " Chao Yu
2024-06-25 14:12     ` Chao Yu
2024-07-09 21:37   ` Jaegeuk Kim [this message]
2024-07-09 21:37     ` Jaegeuk Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zo2tr92oxPEuKBFm@google.com \
    --to=jaegeuk@kernel.org \
    --cc=daehojeong@google.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shengyong@oppo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.