[PATCH 04/10] ext4: use is_power_of_2 helper in ext4_mb_regular_allocator

Kemeng Shi posted 10 patches 2 years, 6 months ago
There is a newer version of this series
[PATCH 04/10] ext4: use is_power_of_2 helper in ext4_mb_regular_allocator
Posted by Kemeng Shi 2 years, 6 months ago
Use intuitive is_power_of_2 helper in ext4_mb_regular_allocator.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/ext4/mballoc.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 4031f8e2a660..b838944b5f09 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2795,10 +2795,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
 	 * requests upto maximum buddy size we have constructed.
 	 */
 	if (i >= sbi->s_mb_order2_reqs && i <= MB_NUM_ORDERS(sb)) {
-		/*
-		 * This should tell if fe_len is exactly power of 2
-		 */
-		if ((ac->ac_g_ex.fe_len & (~(1 << (i - 1)))) == 0)
+		if (is_power_of_2(ac->ac_g_ex.fe_len))
 			ac->ac_2order = array_index_nospec(i - 1,
 							   MB_NUM_ORDERS(sb));
 	}
-- 
2.30.0
Re: [PATCH 04/10] ext4: use is_power_of_2 helper in ext4_mb_regular_allocator
Posted by Ritesh Harjani (IBM) 2 years, 6 months ago
Kemeng Shi <shikemeng@huaweicloud.com> writes:

> Use intuitive is_power_of_2 helper in ext4_mb_regular_allocator.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
>  fs/ext4/mballoc.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>

Looks good to me. Feel free to add:

Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>

> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 4031f8e2a660..b838944b5f09 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -2795,10 +2795,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
>  	 * requests upto maximum buddy size we have constructed.
>  	 */
>  	if (i >= sbi->s_mb_order2_reqs && i <= MB_NUM_ORDERS(sb)) {
> -		/*
> -		 * This should tell if fe_len is exactly power of 2
> -		 */
> -		if ((ac->ac_g_ex.fe_len & (~(1 << (i - 1)))) == 0)
> +		if (is_power_of_2(ac->ac_g_ex.fe_len))
>  			ac->ac_2order = array_index_nospec(i - 1,
>  							   MB_NUM_ORDERS(sb));
>  	}
> -- 
> 2.30.0