diff mbox series

[f2fs-dev,v2,1/2] f2fs: use per-log target_bitmap to improve lookup performace of ssr allocation

Message ID 20240411082354.1691820-1-chao@kernel.org (mailing list archive)
State New
Headers show
Series [f2fs-dev,v2,1/2] f2fs: use per-log target_bitmap to improve lookup performace of ssr allocation | expand

Commit Message

Chao Yu April 11, 2024, 8:23 a.m. UTC
After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by
forbidding SSR overwrite"), valid block bitmap of current openned
segment is fixed, let's introduce a per-log bitmap instead of temp
bitmap to avoid unnecessary calculation overhead whenever allocating
free slot w/ SSR allocator.

Signed-off-by: Chao Yu <chao@kernel.org>
---
v2:
- rebase to last dev-test branch.
 fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
 fs/f2fs/segment.h |  1 +
 2 files changed, 23 insertions(+), 8 deletions(-)

Comments

Chao Yu April 23, 2024, 2:07 a.m. UTC | #1
Jaegeuk, any comments for this serials?

On 2024/4/11 16:23, Chao Yu wrote:
> After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by
> forbidding SSR overwrite"), valid block bitmap of current openned
> segment is fixed, let's introduce a per-log bitmap instead of temp
> bitmap to avoid unnecessary calculation overhead whenever allocating
> free slot w/ SSR allocator.
> 
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> v2:
> - rebase to last dev-test branch.
>   fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
>   fs/f2fs/segment.h |  1 +
>   2 files changed, 23 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 6474b7338e81..af716925db19 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
>   	return 0;
>   }
>   
> -static int __next_free_blkoff(struct f2fs_sb_info *sbi,
> -					int segno, block_t start)
> +static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
> +					unsigned long *target_map,
> +					int segno)
>   {
>   	struct seg_entry *se = get_seg_entry(sbi, segno);
>   	int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
> -	unsigned long *target_map = SIT_I(sbi)->tmp_map;
>   	unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
>   	unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
>   	int i;
>   
>   	for (i = 0; i < entries; i++)
>   		target_map[i] = ckpt_map[i] | cur_map[i];
> +}
> +
> +static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
> +					int segno, block_t start)
> +{
> +	__get_segment_bitmap(sbi, bitmap, segno);
>   
> -	return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
> +	return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
>   }
>   
>   static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
> -		struct curseg_info *seg)
> +					struct curseg_info *seg)
>   {
> -	return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
> +	return __find_rev_next_zero_bit(seg->target_map,
> +				BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
>   }
>   
>   bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
>   {
> -	return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
> +	return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
> +							BLKS_PER_SEG(sbi);
>   }
>   
>   /*
> @@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
>   
>   	reset_curseg(sbi, type, 1);
>   	curseg->alloc_type = SSR;
> -	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
> +	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
> +							curseg->segno, 0);
>   
>   	sum_page = f2fs_get_sum_page(sbi, new_segno);
>   	if (IS_ERR(sum_page)) {
> @@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
>   				sizeof(struct f2fs_journal), GFP_KERNEL);
>   		if (!array[i].journal)
>   			return -ENOMEM;
> +		array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
> +								GFP_KERNEL);
> +		if (!array[i].target_map)
> +			return -ENOMEM;
>   		if (i < NR_PERSISTENT_LOG)
>   			array[i].seg_type = CURSEG_HOT_DATA + i;
>   		else if (i == CURSEG_COLD_DATA_PINNED)
> @@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
>   	for (i = 0; i < NR_CURSEG_TYPE; i++) {
>   		kfree(array[i].sum_blk);
>   		kfree(array[i].journal);
> +		kfree(array[i].target_map);
>   	}
>   	kfree(array);
>   }
> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
> index e1c0f418aa11..10f3e44f036f 100644
> --- a/fs/f2fs/segment.h
> +++ b/fs/f2fs/segment.h
> @@ -292,6 +292,7 @@ struct curseg_info {
>   	struct f2fs_summary_block *sum_blk;	/* cached summary block */
>   	struct rw_semaphore journal_rwsem;	/* protect journal area */
>   	struct f2fs_journal *journal;		/* cached journal info */
> +	unsigned long *target_map;		/* bitmap for SSR allocator */
>   	unsigned char alloc_type;		/* current allocation type */
>   	unsigned short seg_type;		/* segment type like CURSEG_XXX_TYPE */
>   	unsigned int segno;			/* current segment number */
Chao Yu May 29, 2024, 11:13 a.m. UTC | #2
Ping,

On 2024/4/23 10:07, Chao Yu wrote:
> Jaegeuk, any comments for this serials?
> 
> On 2024/4/11 16:23, Chao Yu wrote:
>> After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by
>> forbidding SSR overwrite"), valid block bitmap of current openned
>> segment is fixed, let's introduce a per-log bitmap instead of temp
>> bitmap to avoid unnecessary calculation overhead whenever allocating
>> free slot w/ SSR allocator.
>>
>> Signed-off-by: Chao Yu <chao@kernel.org>
>> ---
>> v2:
>> - rebase to last dev-test branch.
>>   fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
>>   fs/f2fs/segment.h |  1 +
>>   2 files changed, 23 insertions(+), 8 deletions(-)
>>
>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>> index 6474b7338e81..af716925db19 100644
>> --- a/fs/f2fs/segment.c
>> +++ b/fs/f2fs/segment.c
>> @@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
>>       return 0;
>>   }
>> -static int __next_free_blkoff(struct f2fs_sb_info *sbi,
>> -                    int segno, block_t start)
>> +static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
>> +                    unsigned long *target_map,
>> +                    int segno)
>>   {
>>       struct seg_entry *se = get_seg_entry(sbi, segno);
>>       int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
>> -    unsigned long *target_map = SIT_I(sbi)->tmp_map;
>>       unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
>>       unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
>>       int i;
>>       for (i = 0; i < entries; i++)
>>           target_map[i] = ckpt_map[i] | cur_map[i];
>> +}
>> +
>> +static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
>> +                    int segno, block_t start)
>> +{
>> +    __get_segment_bitmap(sbi, bitmap, segno);
>> -    return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
>> +    return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
>>   }
>>   static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
>> -        struct curseg_info *seg)
>> +                    struct curseg_info *seg)
>>   {
>> -    return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
>> +    return __find_rev_next_zero_bit(seg->target_map,
>> +                BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
>>   }
>>   bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
>>   {
>> -    return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
>> +    return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
>> +                            BLKS_PER_SEG(sbi);
>>   }
>>   /*
>> @@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
>>       reset_curseg(sbi, type, 1);
>>       curseg->alloc_type = SSR;
>> -    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
>> +    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
>> +                            curseg->segno, 0);
>>       sum_page = f2fs_get_sum_page(sbi, new_segno);
>>       if (IS_ERR(sum_page)) {
>> @@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
>>                   sizeof(struct f2fs_journal), GFP_KERNEL);
>>           if (!array[i].journal)
>>               return -ENOMEM;
>> +        array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
>> +                                GFP_KERNEL);
>> +        if (!array[i].target_map)
>> +            return -ENOMEM;
>>           if (i < NR_PERSISTENT_LOG)
>>               array[i].seg_type = CURSEG_HOT_DATA + i;
>>           else if (i == CURSEG_COLD_DATA_PINNED)
>> @@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
>>       for (i = 0; i < NR_CURSEG_TYPE; i++) {
>>           kfree(array[i].sum_blk);
>>           kfree(array[i].journal);
>> +        kfree(array[i].target_map);
>>       }
>>       kfree(array);
>>   }
>> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
>> index e1c0f418aa11..10f3e44f036f 100644
>> --- a/fs/f2fs/segment.h
>> +++ b/fs/f2fs/segment.h
>> @@ -292,6 +292,7 @@ struct curseg_info {
>>       struct f2fs_summary_block *sum_blk;    /* cached summary block */
>>       struct rw_semaphore journal_rwsem;    /* protect journal area */
>>       struct f2fs_journal *journal;        /* cached journal info */
>> +    unsigned long *target_map;        /* bitmap for SSR allocator */
>>       unsigned char alloc_type;        /* current allocation type */
>>       unsigned short seg_type;        /* segment type like CURSEG_XXX_TYPE */
>>       unsigned int segno;            /* current segment number */
> 
> 
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim May 30, 2024, 11:39 p.m. UTC | #3
On 05/29, Chao Yu wrote:
> Ping,

Chao, sorry, I might need some time to take a look at the change cautiously.

> 
> On 2024/4/23 10:07, Chao Yu wrote:
> > Jaegeuk, any comments for this serials?
> > 
> > On 2024/4/11 16:23, Chao Yu wrote:
> > > After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by
> > > forbidding SSR overwrite"), valid block bitmap of current openned
> > > segment is fixed, let's introduce a per-log bitmap instead of temp
> > > bitmap to avoid unnecessary calculation overhead whenever allocating
> > > free slot w/ SSR allocator.
> > > 
> > > Signed-off-by: Chao Yu <chao@kernel.org>
> > > ---
> > > v2:
> > > - rebase to last dev-test branch.
> > >   fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
> > >   fs/f2fs/segment.h |  1 +
> > >   2 files changed, 23 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> > > index 6474b7338e81..af716925db19 100644
> > > --- a/fs/f2fs/segment.c
> > > +++ b/fs/f2fs/segment.c
> > > @@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
> > >       return 0;
> > >   }
> > > -static int __next_free_blkoff(struct f2fs_sb_info *sbi,
> > > -                    int segno, block_t start)
> > > +static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
> > > +                    unsigned long *target_map,
> > > +                    int segno)
> > >   {
> > >       struct seg_entry *se = get_seg_entry(sbi, segno);
> > >       int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
> > > -    unsigned long *target_map = SIT_I(sbi)->tmp_map;
> > >       unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
> > >       unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
> > >       int i;
> > >       for (i = 0; i < entries; i++)
> > >           target_map[i] = ckpt_map[i] | cur_map[i];
> > > +}
> > > +
> > > +static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
> > > +                    int segno, block_t start)
> > > +{
> > > +    __get_segment_bitmap(sbi, bitmap, segno);
> > > -    return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
> > > +    return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
> > >   }
> > >   static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
> > > -        struct curseg_info *seg)
> > > +                    struct curseg_info *seg)
> > >   {
> > > -    return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
> > > +    return __find_rev_next_zero_bit(seg->target_map,
> > > +                BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
> > >   }
> > >   bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
> > >   {
> > > -    return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
> > > +    return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
> > > +                            BLKS_PER_SEG(sbi);
> > >   }
> > >   /*
> > > @@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
> > >       reset_curseg(sbi, type, 1);
> > >       curseg->alloc_type = SSR;
> > > -    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
> > > +    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
> > > +                            curseg->segno, 0);
> > >       sum_page = f2fs_get_sum_page(sbi, new_segno);
> > >       if (IS_ERR(sum_page)) {
> > > @@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
> > >                   sizeof(struct f2fs_journal), GFP_KERNEL);
> > >           if (!array[i].journal)
> > >               return -ENOMEM;
> > > +        array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
> > > +                                GFP_KERNEL);
> > > +        if (!array[i].target_map)
> > > +            return -ENOMEM;
> > >           if (i < NR_PERSISTENT_LOG)
> > >               array[i].seg_type = CURSEG_HOT_DATA + i;
> > >           else if (i == CURSEG_COLD_DATA_PINNED)
> > > @@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
> > >       for (i = 0; i < NR_CURSEG_TYPE; i++) {
> > >           kfree(array[i].sum_blk);
> > >           kfree(array[i].journal);
> > > +        kfree(array[i].target_map);
> > >       }
> > >       kfree(array);
> > >   }
> > > diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
> > > index e1c0f418aa11..10f3e44f036f 100644
> > > --- a/fs/f2fs/segment.h
> > > +++ b/fs/f2fs/segment.h
> > > @@ -292,6 +292,7 @@ struct curseg_info {
> > >       struct f2fs_summary_block *sum_blk;    /* cached summary block */
> > >       struct rw_semaphore journal_rwsem;    /* protect journal area */
> > >       struct f2fs_journal *journal;        /* cached journal info */
> > > +    unsigned long *target_map;        /* bitmap for SSR allocator */
> > >       unsigned char alloc_type;        /* current allocation type */
> > >       unsigned short seg_type;        /* segment type like CURSEG_XXX_TYPE */
> > >       unsigned int segno;            /* current segment number */
> > 
> > 
> > _______________________________________________
> > Linux-f2fs-devel mailing list
> > Linux-f2fs-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu May 31, 2024, 1:10 a.m. UTC | #4
On 2024/5/31 7:39, Jaegeuk Kim wrote:
> On 05/29, Chao Yu wrote:
>> Ping,

Jaegeuk,

> 
> Chao, sorry, I might need some time to take a look at the change cautiously.

No problem, I've done some tests on this patch, though, I will keeping this in
my queue, and do test base on the queue whenever it comes new patches.

Thanks,

> 
>>
>> On 2024/4/23 10:07, Chao Yu wrote:
>>> Jaegeuk, any comments for this serials?
>>>
>>> On 2024/4/11 16:23, Chao Yu wrote:
>>>> After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by
>>>> forbidding SSR overwrite"), valid block bitmap of current openned
>>>> segment is fixed, let's introduce a per-log bitmap instead of temp
>>>> bitmap to avoid unnecessary calculation overhead whenever allocating
>>>> free slot w/ SSR allocator.
>>>>
>>>> Signed-off-by: Chao Yu <chao@kernel.org>
>>>> ---
>>>> v2:
>>>> - rebase to last dev-test branch.
>>>>    fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
>>>>    fs/f2fs/segment.h |  1 +
>>>>    2 files changed, 23 insertions(+), 8 deletions(-)
>>>>
>>>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>>>> index 6474b7338e81..af716925db19 100644
>>>> --- a/fs/f2fs/segment.c
>>>> +++ b/fs/f2fs/segment.c
>>>> @@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
>>>>        return 0;
>>>>    }
>>>> -static int __next_free_blkoff(struct f2fs_sb_info *sbi,
>>>> -                    int segno, block_t start)
>>>> +static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
>>>> +                    unsigned long *target_map,
>>>> +                    int segno)
>>>>    {
>>>>        struct seg_entry *se = get_seg_entry(sbi, segno);
>>>>        int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
>>>> -    unsigned long *target_map = SIT_I(sbi)->tmp_map;
>>>>        unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
>>>>        unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
>>>>        int i;
>>>>        for (i = 0; i < entries; i++)
>>>>            target_map[i] = ckpt_map[i] | cur_map[i];
>>>> +}
>>>> +
>>>> +static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
>>>> +                    int segno, block_t start)
>>>> +{
>>>> +    __get_segment_bitmap(sbi, bitmap, segno);
>>>> -    return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
>>>> +    return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
>>>>    }
>>>>    static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
>>>> -        struct curseg_info *seg)
>>>> +                    struct curseg_info *seg)
>>>>    {
>>>> -    return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
>>>> +    return __find_rev_next_zero_bit(seg->target_map,
>>>> +                BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
>>>>    }
>>>>    bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
>>>>    {
>>>> -    return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
>>>> +    return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
>>>> +                            BLKS_PER_SEG(sbi);
>>>>    }
>>>>    /*
>>>> @@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
>>>>        reset_curseg(sbi, type, 1);
>>>>        curseg->alloc_type = SSR;
>>>> -    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
>>>> +    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
>>>> +                            curseg->segno, 0);
>>>>        sum_page = f2fs_get_sum_page(sbi, new_segno);
>>>>        if (IS_ERR(sum_page)) {
>>>> @@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
>>>>                    sizeof(struct f2fs_journal), GFP_KERNEL);
>>>>            if (!array[i].journal)
>>>>                return -ENOMEM;
>>>> +        array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
>>>> +                                GFP_KERNEL);
>>>> +        if (!array[i].target_map)
>>>> +            return -ENOMEM;
>>>>            if (i < NR_PERSISTENT_LOG)
>>>>                array[i].seg_type = CURSEG_HOT_DATA + i;
>>>>            else if (i == CURSEG_COLD_DATA_PINNED)
>>>> @@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
>>>>        for (i = 0; i < NR_CURSEG_TYPE; i++) {
>>>>            kfree(array[i].sum_blk);
>>>>            kfree(array[i].journal);
>>>> +        kfree(array[i].target_map);
>>>>        }
>>>>        kfree(array);
>>>>    }
>>>> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
>>>> index e1c0f418aa11..10f3e44f036f 100644
>>>> --- a/fs/f2fs/segment.h
>>>> +++ b/fs/f2fs/segment.h
>>>> @@ -292,6 +292,7 @@ struct curseg_info {
>>>>        struct f2fs_summary_block *sum_blk;    /* cached summary block */
>>>>        struct rw_semaphore journal_rwsem;    /* protect journal area */
>>>>        struct f2fs_journal *journal;        /* cached journal info */
>>>> +    unsigned long *target_map;        /* bitmap for SSR allocator */
>>>>        unsigned char alloc_type;        /* current allocation type */
>>>>        unsigned short seg_type;        /* segment type like CURSEG_XXX_TYPE */
>>>>        unsigned int segno;            /* current segment number */
>>>
>>>
>>> _______________________________________________
>>> Linux-f2fs-devel mailing list
>>> Linux-f2fs-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu Sept. 18, 2024, 2:17 a.m. UTC | #5
On 2024/5/31 9:10, Chao Yu wrote:
> On 2024/5/31 7:39, Jaegeuk Kim wrote:
>> On 05/29, Chao Yu wrote:
>>> Ping,
> 
> Jaegeuk,
> 
>>
>> Chao, sorry, I might need some time to take a look at the change cautiously.
> 
> No problem, I've done some tests on this patch, though, I will keeping this in
> my queue, and do test base on the queue whenever it comes new patches.

Jaegeuk,

Any progress on this patchset?

Thanks,

> 
> Thanks,
> 
>>
>>>
>>> On 2024/4/23 10:07, Chao Yu wrote:
>>>> Jaegeuk, any comments for this serials?
>>>>
>>>> On 2024/4/11 16:23, Chao Yu wrote:
>>>>> After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by
>>>>> forbidding SSR overwrite"), valid block bitmap of current openned
>>>>> segment is fixed, let's introduce a per-log bitmap instead of temp
>>>>> bitmap to avoid unnecessary calculation overhead whenever allocating
>>>>> free slot w/ SSR allocator.
>>>>>
>>>>> Signed-off-by: Chao Yu <chao@kernel.org>
>>>>> ---
>>>>> v2:
>>>>> - rebase to last dev-test branch.
>>>>>    fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
>>>>>    fs/f2fs/segment.h |  1 +
>>>>>    2 files changed, 23 insertions(+), 8 deletions(-)
>>>>>
>>>>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>>>>> index 6474b7338e81..af716925db19 100644
>>>>> --- a/fs/f2fs/segment.c
>>>>> +++ b/fs/f2fs/segment.c
>>>>> @@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
>>>>>        return 0;
>>>>>    }
>>>>> -static int __next_free_blkoff(struct f2fs_sb_info *sbi,
>>>>> -                    int segno, block_t start)
>>>>> +static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
>>>>> +                    unsigned long *target_map,
>>>>> +                    int segno)
>>>>>    {
>>>>>        struct seg_entry *se = get_seg_entry(sbi, segno);
>>>>>        int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
>>>>> -    unsigned long *target_map = SIT_I(sbi)->tmp_map;
>>>>>        unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
>>>>>        unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
>>>>>        int i;
>>>>>        for (i = 0; i < entries; i++)
>>>>>            target_map[i] = ckpt_map[i] | cur_map[i];
>>>>> +}
>>>>> +
>>>>> +static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
>>>>> +                    int segno, block_t start)
>>>>> +{
>>>>> +    __get_segment_bitmap(sbi, bitmap, segno);
>>>>> -    return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
>>>>> +    return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
>>>>>    }
>>>>>    static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
>>>>> -        struct curseg_info *seg)
>>>>> +                    struct curseg_info *seg)
>>>>>    {
>>>>> -    return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
>>>>> +    return __find_rev_next_zero_bit(seg->target_map,
>>>>> +                BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
>>>>>    }
>>>>>    bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
>>>>>    {
>>>>> -    return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
>>>>> +    return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
>>>>> +                            BLKS_PER_SEG(sbi);
>>>>>    }
>>>>>    /*
>>>>> @@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
>>>>>        reset_curseg(sbi, type, 1);
>>>>>        curseg->alloc_type = SSR;
>>>>> -    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
>>>>> +    curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
>>>>> +                            curseg->segno, 0);
>>>>>        sum_page = f2fs_get_sum_page(sbi, new_segno);
>>>>>        if (IS_ERR(sum_page)) {
>>>>> @@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
>>>>>                    sizeof(struct f2fs_journal), GFP_KERNEL);
>>>>>            if (!array[i].journal)
>>>>>                return -ENOMEM;
>>>>> +        array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
>>>>> +                                GFP_KERNEL);
>>>>> +        if (!array[i].target_map)
>>>>> +            return -ENOMEM;
>>>>>            if (i < NR_PERSISTENT_LOG)
>>>>>                array[i].seg_type = CURSEG_HOT_DATA + i;
>>>>>            else if (i == CURSEG_COLD_DATA_PINNED)
>>>>> @@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
>>>>>        for (i = 0; i < NR_CURSEG_TYPE; i++) {
>>>>>            kfree(array[i].sum_blk);
>>>>>            kfree(array[i].journal);
>>>>> +        kfree(array[i].target_map);
>>>>>        }
>>>>>        kfree(array);
>>>>>    }
>>>>> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
>>>>> index e1c0f418aa11..10f3e44f036f 100644
>>>>> --- a/fs/f2fs/segment.h
>>>>> +++ b/fs/f2fs/segment.h
>>>>> @@ -292,6 +292,7 @@ struct curseg_info {
>>>>>        struct f2fs_summary_block *sum_blk;    /* cached summary block */
>>>>>        struct rw_semaphore journal_rwsem;    /* protect journal area */
>>>>>        struct f2fs_journal *journal;        /* cached journal info */
>>>>> +    unsigned long *target_map;        /* bitmap for SSR allocator */
>>>>>        unsigned char alloc_type;        /* current allocation type */
>>>>>        unsigned short seg_type;        /* segment type like CURSEG_XXX_TYPE */
>>>>>        unsigned int segno;            /* current segment number */
>>>>
>>>>
>>>> _______________________________________________
>>>> Linux-f2fs-devel mailing list
>>>> Linux-f2fs-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> 
> 
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Jaegeuk Kim Oct. 7, 2024, 4:52 p.m. UTC | #6
Hi Chao,

This introduces another bitmap increasing memory footprint. Do we know how
much performance benefit with this?

On 04/11, Chao Yu wrote:
> After commit 899fee36fac0 ("f2fs: fix to avoid data corruption by
> forbidding SSR overwrite"), valid block bitmap of current openned
> segment is fixed, let's introduce a per-log bitmap instead of temp
> bitmap to avoid unnecessary calculation overhead whenever allocating
> free slot w/ SSR allocator.
> 
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> v2:
> - rebase to last dev-test branch.
>  fs/f2fs/segment.c | 30 ++++++++++++++++++++++--------
>  fs/f2fs/segment.h |  1 +
>  2 files changed, 23 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index 6474b7338e81..af716925db19 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -2840,31 +2840,39 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
>  	return 0;
>  }
>  
> -static int __next_free_blkoff(struct f2fs_sb_info *sbi,
> -					int segno, block_t start)
> +static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
> +					unsigned long *target_map,
> +					int segno)
>  {
>  	struct seg_entry *se = get_seg_entry(sbi, segno);
>  	int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
> -	unsigned long *target_map = SIT_I(sbi)->tmp_map;
>  	unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
>  	unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
>  	int i;
>  
>  	for (i = 0; i < entries; i++)
>  		target_map[i] = ckpt_map[i] | cur_map[i];
> +}
> +
> +static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
> +					int segno, block_t start)
> +{
> +	__get_segment_bitmap(sbi, bitmap, segno);
>  
> -	return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
> +	return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
>  }
>  
>  static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
> -		struct curseg_info *seg)
> +					struct curseg_info *seg)
>  {
> -	return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
> +	return __find_rev_next_zero_bit(seg->target_map,
> +				BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
>  }
>  
>  bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
>  {
> -	return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
> +	return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
> +							BLKS_PER_SEG(sbi);
>  }
>  
>  /*
> @@ -2890,7 +2898,8 @@ static int change_curseg(struct f2fs_sb_info *sbi, int type)
>  
>  	reset_curseg(sbi, type, 1);
>  	curseg->alloc_type = SSR;
> -	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
> +	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
> +							curseg->segno, 0);
>  
>  	sum_page = f2fs_get_sum_page(sbi, new_segno);
>  	if (IS_ERR(sum_page)) {
> @@ -4635,6 +4644,10 @@ static int build_curseg(struct f2fs_sb_info *sbi)
>  				sizeof(struct f2fs_journal), GFP_KERNEL);
>  		if (!array[i].journal)
>  			return -ENOMEM;
> +		array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
> +								GFP_KERNEL);
> +		if (!array[i].target_map)
> +			return -ENOMEM;
>  		if (i < NR_PERSISTENT_LOG)
>  			array[i].seg_type = CURSEG_HOT_DATA + i;
>  		else if (i == CURSEG_COLD_DATA_PINNED)
> @@ -5453,6 +5466,7 @@ static void destroy_curseg(struct f2fs_sb_info *sbi)
>  	for (i = 0; i < NR_CURSEG_TYPE; i++) {
>  		kfree(array[i].sum_blk);
>  		kfree(array[i].journal);
> +		kfree(array[i].target_map);
>  	}
>  	kfree(array);
>  }
> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
> index e1c0f418aa11..10f3e44f036f 100644
> --- a/fs/f2fs/segment.h
> +++ b/fs/f2fs/segment.h
> @@ -292,6 +292,7 @@ struct curseg_info {
>  	struct f2fs_summary_block *sum_blk;	/* cached summary block */
>  	struct rw_semaphore journal_rwsem;	/* protect journal area */
>  	struct f2fs_journal *journal;		/* cached journal info */
> +	unsigned long *target_map;		/* bitmap for SSR allocator */
>  	unsigned char alloc_type;		/* current allocation type */
>  	unsigned short seg_type;		/* segment type like CURSEG_XXX_TYPE */
>  	unsigned int segno;			/* current segment number */
> -- 
> 2.40.1
diff mbox series

Patch

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 6474b7338e81..af716925db19 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2840,31 +2840,39 @@  static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
 	return 0;
 }
 
-static int __next_free_blkoff(struct f2fs_sb_info *sbi,
-					int segno, block_t start)
+static void __get_segment_bitmap(struct f2fs_sb_info *sbi,
+					unsigned long *target_map,
+					int segno)
 {
 	struct seg_entry *se = get_seg_entry(sbi, segno);
 	int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
-	unsigned long *target_map = SIT_I(sbi)->tmp_map;
 	unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
 	unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
 	int i;
 
 	for (i = 0; i < entries; i++)
 		target_map[i] = ckpt_map[i] | cur_map[i];
+}
+
+static int __next_free_blkoff(struct f2fs_sb_info *sbi, unsigned long *bitmap,
+					int segno, block_t start)
+{
+	__get_segment_bitmap(sbi, bitmap, segno);
 
-	return __find_rev_next_zero_bit(target_map, BLKS_PER_SEG(sbi), start);
+	return __find_rev_next_zero_bit(bitmap, BLKS_PER_SEG(sbi), start);
 }
 
 static int f2fs_find_next_ssr_block(struct f2fs_sb_info *sbi,
-		struct curseg_info *seg)
+					struct curseg_info *seg)
 {
-	return __next_free_blkoff(sbi, seg->segno, seg->next_blkoff + 1);
+	return __find_rev_next_zero_bit(seg->target_map,
+				BLKS_PER_SEG(sbi), seg->next_blkoff + 1);
 }
 
 bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
 {
-	return __next_free_blkoff(sbi, segno, 0) < BLKS_PER_SEG(sbi);
+	return __next_free_blkoff(sbi, SIT_I(sbi)->tmp_map, segno, 0) <
+							BLKS_PER_SEG(sbi);
 }
 
 /*
@@ -2890,7 +2898,8 @@  static int change_curseg(struct f2fs_sb_info *sbi, int type)
 
 	reset_curseg(sbi, type, 1);
 	curseg->alloc_type = SSR;
-	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
+	curseg->next_blkoff = __next_free_blkoff(sbi, curseg->target_map,
+							curseg->segno, 0);
 
 	sum_page = f2fs_get_sum_page(sbi, new_segno);
 	if (IS_ERR(sum_page)) {
@@ -4635,6 +4644,10 @@  static int build_curseg(struct f2fs_sb_info *sbi)
 				sizeof(struct f2fs_journal), GFP_KERNEL);
 		if (!array[i].journal)
 			return -ENOMEM;
+		array[i].target_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
+								GFP_KERNEL);
+		if (!array[i].target_map)
+			return -ENOMEM;
 		if (i < NR_PERSISTENT_LOG)
 			array[i].seg_type = CURSEG_HOT_DATA + i;
 		else if (i == CURSEG_COLD_DATA_PINNED)
@@ -5453,6 +5466,7 @@  static void destroy_curseg(struct f2fs_sb_info *sbi)
 	for (i = 0; i < NR_CURSEG_TYPE; i++) {
 		kfree(array[i].sum_blk);
 		kfree(array[i].journal);
+		kfree(array[i].target_map);
 	}
 	kfree(array);
 }
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index e1c0f418aa11..10f3e44f036f 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -292,6 +292,7 @@  struct curseg_info {
 	struct f2fs_summary_block *sum_blk;	/* cached summary block */
 	struct rw_semaphore journal_rwsem;	/* protect journal area */
 	struct f2fs_journal *journal;		/* cached journal info */
+	unsigned long *target_map;		/* bitmap for SSR allocator */
 	unsigned char alloc_type;		/* current allocation type */
 	unsigned short seg_type;		/* segment type like CURSEG_XXX_TYPE */
 	unsigned int segno;			/* current segment number */