[13/21] ext4: remove dead check in mb_buddy_mark_free

Message ID 20230209194825.511043-14-shikemeng@huaweicloud.com
State New
Headers
Series Some bugfix and cleanup to mballoc |

Commit Message

Kemeng Shi Feb. 9, 2023, 7:48 p.m. UTC
  We always adjust first to even number and adjust last to odd number, so
first == last will never happen. Remove this dead check.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/ext4/mballoc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Ojaswin Mujoo Feb. 13, 2023, 7:50 p.m. UTC | #1
On Fri, Feb 10, 2023 at 03:48:17AM +0800, Kemeng Shi wrote:
> We always adjust first to even number and adjust last to odd number, so
> first == last will never happen. Remove this dead check.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
>  fs/ext4/mballoc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index bdabe0d81d4a..0fdbf16ac180 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -1718,7 +1718,8 @@ static void mb_buddy_mark_free(struct ext4_buddy *e4b, int first, int last)
>  			break;
>  		order++;
>  
> -		if (first == last || !(buddy2 = mb_find_buddy(e4b, order, &max))) {
> +		buddy2 = mb_find_buddy(e4b, order, &max);
> +		if (!buddy2) {
>  			mb_clear_bits(buddy, first, last - first + 1);
>  			e4b->bd_info->bb_counters[order - 1] += last - first + 1;
>  			break;
> -- 
> 2.30.0
> 
Okay, so I checked the code and seems like you are right. There is can't be any
scenario where (first == last) after the calls to mb_buddy_adjust_border().

However, I'm a bit hesitant to give my Reviewed by since buddy algo is still a
bit confusing to me and I might be missing some weird edge case.  Maybe someone
can help double check this.
  
Kemeng Shi Feb. 17, 2023, 1:24 a.m. UTC | #2
on 2/14/2023 3:50 AM, Ojaswin Mujoo wrote:
> On Fri, Feb 10, 2023 at 03:48:17AM +0800, Kemeng Shi wrote:
>> We always adjust first to even number and adjust last to odd number, so
>> first == last will never happen. Remove this dead check.
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
>> ---
>>  fs/ext4/mballoc.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
>> index bdabe0d81d4a..0fdbf16ac180 100644
>> --- a/fs/ext4/mballoc.c
>> +++ b/fs/ext4/mballoc.c
>> @@ -1718,7 +1718,8 @@ static void mb_buddy_mark_free(struct ext4_buddy *e4b, int first, int last)
>>  			break;
>>  		order++;
>>  
>> -		if (first == last || !(buddy2 = mb_find_buddy(e4b, order, &max))) {
>> +		buddy2 = mb_find_buddy(e4b, order, &max);
>> +		if (!buddy2) {
>>  			mb_clear_bits(buddy, first, last - first + 1);
>>  			e4b->bd_info->bb_counters[order - 1] += last - first + 1;
>>  			break;
>> -- 
>> 2.30.0
>>
> Okay, so I checked the code and seems like you are right. There is can't be any
> scenario where (first == last) after the calls to mb_buddy_adjust_border().
> 
> However, I'm a bit hesitant to give my Reviewed by since buddy algo is still a
> bit confusing to me and I might be missing some weird edge case.  Maybe someone
> can help double check this.
Hi, could anyone help double check this patch and patch 18/21 "ext4: remove
unnecessary goto in ext4_mb_mark_diskspace_used" in the same patchset. Thanks.
  

Patch

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index bdabe0d81d4a..0fdbf16ac180 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -1718,7 +1718,8 @@  static void mb_buddy_mark_free(struct ext4_buddy *e4b, int first, int last)
 			break;
 		order++;
 
-		if (first == last || !(buddy2 = mb_find_buddy(e4b, order, &max))) {
+		buddy2 = mb_find_buddy(e4b, order, &max);
+		if (!buddy2) {
 			mb_clear_bits(buddy, first, last - first + 1);
 			e4b->bd_info->bb_counters[order - 1] += last - first + 1;
 			break;