lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 12 Aug 2021 13:44:16 -0400
From:   "Theodore Ts'o" <tytso@....edu>
To:     Wang Jianchao <jianchao.wan9@...il.com>
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 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.

						- Ted

Powered by blists - more mailing lists