[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <43615c43-6837-dd84-c5d8-017596a59688@gmail.com>
Date: Thu, 26 Aug 2021 15:19:10 +0800
From: Wang Jianchao <jianchao.wan9@...il.com>
To: Theodore Ts'o <tytso@....edu>
Cc: linux-ext4@...r.kernel.org, linux-kernel@...r.kernel.org,
adilger.kernel@...ger.ca
Subject: Re: [PATCH V3 2/5] ext4: add new helper interface
ext4_try_to_trim_range()
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@...ishou.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@...ger.ca>
>> Signed-off-by: Wang Jianchao <wangjianchao@...ishou.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
>
Powered by blists - more mailing lists