diff mbox series

[f2fs-dev] resize.f2fs: get value from new sb during rebuilding cp

Message ID 20240408131157.4100204-1-shengyong@oppo.com (mailing list archive)
State New
Headers show
Series [f2fs-dev] resize.f2fs: get value from new sb during rebuilding cp | expand

Commit Message

Sheng Yong April 8, 2024, 1:11 p.m. UTC
Althrough old and new sb have the same value for now, it would be better
to build new checkpoint according to new sb.

Signed-off-by: Sheng Yong <shengyong@oppo.com>
---
 fsck/resize.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Jaegeuk Kim April 8, 2024, 6:34 p.m. UTC | #1
On 04/08, Sheng Yong wrote:
> Althrough old and new sb have the same value for now, it would be better
> to build new checkpoint according to new sb.

May need to add assert, if they're different?

> 
> Signed-off-by: Sheng Yong <shengyong@oppo.com>
> ---
>  fsck/resize.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/fsck/resize.c b/fsck/resize.c
> index 049ddd3..1b4ae85 100644
> --- a/fsck/resize.c
> +++ b/fsck/resize.c
> @@ -481,7 +481,7 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
>  		set_cp(overprov_segment_count, get_cp(rsvd_segment_count));
>  
>  	set_cp(overprov_segment_count, get_cp(overprov_segment_count) +
> -						2 * get_sb(segs_per_sec));
> +						2 * get_newsb(segs_per_sec));
>  
>  	DBG(0, "Info: Overprovision ratio = %.3lf%%\n", c.new_overprovision);
>  	DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
> @@ -551,11 +551,12 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
>  							cpu_to_le32(crc);
>  
>  	/* Write a new checkpoint in the other set */
> -	new_cp_blk_no = old_cp_blk_no = get_sb(cp_blkaddr);
> +	old_cp_blk_no = get_sb(cp_blkaddr);
> +	new_cp_blk_no = get_newsb(cp_blkaddr);
>  	if (sbi->cur_cp == 2)
>  		old_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
>  	else
> -		new_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
> +		new_cp_blk_no += 1 << get_newsb(log_blocks_per_seg);
>  
>  	/* write first cp */
>  	ret = dev_write_block(new_cp, new_cp_blk_no++);
> -- 
> 2.40.1
Sheng Yong April 9, 2024, 1:54 a.m. UTC | #2
On 2024/4/9 2:34, Jaegeuk Kim wrote:
> On 04/08, Sheng Yong wrote:
>> Althrough old and new sb have the same value for now, it would be better
>> to build new checkpoint according to new sb.
> 
> May need to add assert, if they're different?
> 
We could add assert here, but I think it's not that necessary:
1. rebuild_checkpoint is only called by resize, and new_sb is copied directly
    from original sb without any changes of these basic attributes.
2. for now, new_sb has the same attributes/members with the original one. If
    those attributes are allowed to get changed in the future, the assert needs
    to be removed.
So how about adding a new helper to check and show the difference between the
new and original sb?

many thanks,
shengyong
>>
>> Signed-off-by: Sheng Yong <shengyong@oppo.com>
>> ---
>>   fsck/resize.c | 7 ++++---
>>   1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/fsck/resize.c b/fsck/resize.c
>> index 049ddd3..1b4ae85 100644
>> --- a/fsck/resize.c
>> +++ b/fsck/resize.c
>> @@ -481,7 +481,7 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
>>   		set_cp(overprov_segment_count, get_cp(rsvd_segment_count));
>>   
>>   	set_cp(overprov_segment_count, get_cp(overprov_segment_count) +
>> -						2 * get_sb(segs_per_sec));
>> +						2 * get_newsb(segs_per_sec));
>>   
>>   	DBG(0, "Info: Overprovision ratio = %.3lf%%\n", c.new_overprovision);
>>   	DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
>> @@ -551,11 +551,12 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
>>   							cpu_to_le32(crc);
>>   
>>   	/* Write a new checkpoint in the other set */
>> -	new_cp_blk_no = old_cp_blk_no = get_sb(cp_blkaddr);
>> +	old_cp_blk_no = get_sb(cp_blkaddr);
>> +	new_cp_blk_no = get_newsb(cp_blkaddr);
>>   	if (sbi->cur_cp == 2)
>>   		old_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
>>   	else
>> -		new_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
>> +		new_cp_blk_no += 1 << get_newsb(log_blocks_per_seg);
>>   
>>   	/* write first cp */
>>   	ret = dev_write_block(new_cp, new_cp_blk_no++);
>> -- 
>> 2.40.1
Jaegeuk Kim April 10, 2024, 12:38 a.m. UTC | #3
On 04/09, Sheng Yong wrote:
> 
> 
> On 2024/4/9 2:34, Jaegeuk Kim wrote:
> > On 04/08, Sheng Yong wrote:
> > > Althrough old and new sb have the same value for now, it would be better
> > > to build new checkpoint according to new sb.
> > 
> > May need to add assert, if they're different?
> > 
> We could add assert here, but I think it's not that necessary:
> 1. rebuild_checkpoint is only called by resize, and new_sb is copied directly
>    from original sb without any changes of these basic attributes.
> 2. for now, new_sb has the same attributes/members with the original one. If
>    those attributes are allowed to get changed in the future, the assert needs
>    to be removed.
> So how about adding a new helper to check and show the difference between the
> new and original sb?

So, why do we need to change this?

> 
> many thanks,
> shengyong
> > > 
> > > Signed-off-by: Sheng Yong <shengyong@oppo.com>
> > > ---
> > >   fsck/resize.c | 7 ++++---
> > >   1 file changed, 4 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/fsck/resize.c b/fsck/resize.c
> > > index 049ddd3..1b4ae85 100644
> > > --- a/fsck/resize.c
> > > +++ b/fsck/resize.c
> > > @@ -481,7 +481,7 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
> > >   		set_cp(overprov_segment_count, get_cp(rsvd_segment_count));
> > >   	set_cp(overprov_segment_count, get_cp(overprov_segment_count) +
> > > -						2 * get_sb(segs_per_sec));
> > > +						2 * get_newsb(segs_per_sec));
> > >   	DBG(0, "Info: Overprovision ratio = %.3lf%%\n", c.new_overprovision);
> > >   	DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
> > > @@ -551,11 +551,12 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
> > >   							cpu_to_le32(crc);
> > >   	/* Write a new checkpoint in the other set */
> > > -	new_cp_blk_no = old_cp_blk_no = get_sb(cp_blkaddr);
> > > +	old_cp_blk_no = get_sb(cp_blkaddr);
> > > +	new_cp_blk_no = get_newsb(cp_blkaddr);
> > >   	if (sbi->cur_cp == 2)
> > >   		old_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
> > >   	else
> > > -		new_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
> > > +		new_cp_blk_no += 1 << get_newsb(log_blocks_per_seg);
> > >   	/* write first cp */
> > >   	ret = dev_write_block(new_cp, new_cp_blk_no++);
> > > -- 
> > > 2.40.1
Sheng Yong April 10, 2024, 2:11 a.m. UTC | #4
On 2024/4/10 8:38, Jaegeuk Kim wrote:
> On 04/09, Sheng Yong wrote:
>>
>>
>> On 2024/4/9 2:34, Jaegeuk Kim wrote:
>>> On 04/08, Sheng Yong wrote:
>>>> Althrough old and new sb have the same value for now, it would be better
>>>> to build new checkpoint according to new sb.
>>>
>>> May need to add assert, if they're different?
>>>
>> We could add assert here, but I think it's not that necessary:
>> 1. rebuild_checkpoint is only called by resize, and new_sb is copied directly
>>     from original sb without any changes of these basic attributes.
>> 2. for now, new_sb has the same attributes/members with the original one. If
>>     those attributes are allowed to get changed in the future, the assert needs
>>     to be removed.
>> So how about adding a new helper to check and show the difference between the
>> new and original sb?
> 
> So, why do we need to change this?
Semantically, IMO, these fields belonging to new cp should be calculated based
on new sb, although the results are equal. That is found when I am trying to
make resize.f2fs support resizing with different attributes.

thanks,
shengyong
> 
>>
>> many thanks,
>> shengyong
>>>>
>>>> Signed-off-by: Sheng Yong <shengyong@oppo.com>
>>>> ---
>>>>    fsck/resize.c | 7 ++++---
>>>>    1 file changed, 4 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/fsck/resize.c b/fsck/resize.c
>>>> index 049ddd3..1b4ae85 100644
>>>> --- a/fsck/resize.c
>>>> +++ b/fsck/resize.c
>>>> @@ -481,7 +481,7 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
>>>>    		set_cp(overprov_segment_count, get_cp(rsvd_segment_count));
>>>>    	set_cp(overprov_segment_count, get_cp(overprov_segment_count) +
>>>> -						2 * get_sb(segs_per_sec));
>>>> +						2 * get_newsb(segs_per_sec));
>>>>    	DBG(0, "Info: Overprovision ratio = %.3lf%%\n", c.new_overprovision);
>>>>    	DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
>>>> @@ -551,11 +551,12 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
>>>>    							cpu_to_le32(crc);
>>>>    	/* Write a new checkpoint in the other set */
>>>> -	new_cp_blk_no = old_cp_blk_no = get_sb(cp_blkaddr);
>>>> +	old_cp_blk_no = get_sb(cp_blkaddr);
>>>> +	new_cp_blk_no = get_newsb(cp_blkaddr);
>>>>    	if (sbi->cur_cp == 2)
>>>>    		old_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
>>>>    	else
>>>> -		new_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
>>>> +		new_cp_blk_no += 1 << get_newsb(log_blocks_per_seg);
>>>>    	/* write first cp */
>>>>    	ret = dev_write_block(new_cp, new_cp_blk_no++);
>>>> -- 
>>>> 2.40.1
diff mbox series

Patch

diff --git a/fsck/resize.c b/fsck/resize.c
index 049ddd3..1b4ae85 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -481,7 +481,7 @@  static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
 		set_cp(overprov_segment_count, get_cp(rsvd_segment_count));
 
 	set_cp(overprov_segment_count, get_cp(overprov_segment_count) +
-						2 * get_sb(segs_per_sec));
+						2 * get_newsb(segs_per_sec));
 
 	DBG(0, "Info: Overprovision ratio = %.3lf%%\n", c.new_overprovision);
 	DBG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
@@ -551,11 +551,12 @@  static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
 							cpu_to_le32(crc);
 
 	/* Write a new checkpoint in the other set */
-	new_cp_blk_no = old_cp_blk_no = get_sb(cp_blkaddr);
+	old_cp_blk_no = get_sb(cp_blkaddr);
+	new_cp_blk_no = get_newsb(cp_blkaddr);
 	if (sbi->cur_cp == 2)
 		old_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
 	else
-		new_cp_blk_no += 1 << get_sb(log_blocks_per_seg);
+		new_cp_blk_no += 1 << get_newsb(log_blocks_per_seg);
 
 	/* write first cp */
 	ret = dev_write_block(new_cp, new_cp_blk_no++);