lkml.org 
[lkml]   [2021]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range()
From
Date


On 2021/8/13 1:44 AM, Theodore Ts'o wrote:
> On Sat, Jul 24, 2021 at 03:41:21PM +0800, Wang Jianchao wrote:
>> From: Wang Jianchao <wangjianchao@kuaishou.com>
>>
>> There is no functional change in this patch but just split the
>> codes, which serachs free block and does trim, into a new function
>> ext4_try_to_trim_range. This is preparing for the following async
>> backgroup discard.
>>
>> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
>> Signed-off-by: Wang Jianchao <wangjianchao@kuaishou.com>
>> ---
>> fs/ext4/mballoc.c | 102 ++++++++++++++++++++++++++--------------------
>> 1 file changed, 57 insertions(+), 45 deletions(-)
>>
>> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
>> index 018d5d3c6eeb..e3844152a643 100644
>> --- a/fs/ext4/mballoc.c
>> +++ b/fs/ext4/mballoc.c
>> @@ -6218,6 +6218,54 @@ __acquires(bitlock)
>> return ret;
>> }
>>
>> +static int ext4_try_to_trim_range(struct super_block *sb,
>> + struct ext4_buddy *e4b, ext4_grpblk_t start,
>> + ext4_grpblk_t max, ext4_grpblk_t minblocks)
>> +{
>> + ext4_grpblk_t next, count, free_count;
>> + void *bitmap;
>> + int ret = 0;
>> +
>> + bitmap = e4b->bd_bitmap;
>> + start = (e4b->bd_info->bb_first_free > start) ?
>> + e4b->bd_info->bb_first_free : start;
>> + count = 0;
>> + free_count = 0;
>> +
>> + while (start <= max) {
>> + start = mb_find_next_zero_bit(bitmap, max + 1, start);
>> + if (start > max)
>> + break;
>> + next = mb_find_next_bit(bitmap, max + 1, start);
>> +
>> + if ((next - start) >= minblocks) {
>> + ret = ext4_trim_extent(sb, start, next - start, e4b);
>> + if (ret && ret != -EOPNOTSUPP)
>> + break;
>> + ret = 0;
>> + count += next - start;
>> + }
>
> "ret" is only used inside the if statement, so this might be better as:
>
>> + if ((next - start) >= minblocks) {
>> + int ret = ext4_trim_extent(sb, start, next - start, e4b);
>> +
>> + if (ret && ret != -EOPNOTSUPP)
>> + break;
>> + count += next - start;
>> + }
>
> ... and then drop the "int ret = 0" above.
>
> Otherwise, looks good.
>

OK, I'll do it in next version

Thanks so much
Jianchao
> - Ted
>

\
 
 \ /
  Last update: 2021-08-26 09:19    [W:0.381 / U:0.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site