Re: [PATCH V3 2/5] ext4: add new helper interface ext4_try_to_trim_range()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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@xxxxxxxxxxxx>
>>
>> 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@xxxxxxxxx>
>> Signed-off-by: Wang Jianchao <wangjianchao@xxxxxxxxxxxx>
>> ---
>>  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
> 



[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux