diff mbox series

[1/4] mm/percpu: micro-optimize pcpu_is_populated()

Message ID 20210719021755.883182-2-yury.norov@gmail.com (mailing list archive)
State New, archived
Headers show
Series bitmap: unify for_each_bit() macros | expand

Commit Message

Yury Norov July 19, 2021, 2:17 a.m. UTC
bitmap_next_clear_region() calls find_next_zero_bit() and find_next_bit()
sequentially to find a range of clear bits. In case of pcpu_is_populated()
there's a chance to return earlier if bitmap has all bits set.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 mm/percpu.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

Dennis Zhou July 21, 2021, 9:07 p.m. UTC | #1
Hello,

On Sun, Jul 18, 2021 at 07:17:52PM -0700, Yury Norov wrote:
> bitmap_next_clear_region() calls find_next_zero_bit() and find_next_bit()
> sequentially to find a range of clear bits. In case of pcpu_is_populated()
> there's a chance to return earlier if bitmap has all bits set.
> 
> Signed-off-by: Yury Norov <yury.norov@gmail.com>
> ---
>  mm/percpu.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/mm/percpu.c b/mm/percpu.c
> index 7f2e0151c4e2..25461571dcc5 100644
> --- a/mm/percpu.c
> +++ b/mm/percpu.c
> @@ -1071,17 +1071,18 @@ static void pcpu_block_update_hint_free(struct pcpu_chunk *chunk, int bit_off,
>  static bool pcpu_is_populated(struct pcpu_chunk *chunk, int bit_off, int bits,
>  			      int *next_off)
>  {
> -	unsigned int page_start, page_end, rs, re;
> +	unsigned int start, end;
>  
> -	page_start = PFN_DOWN(bit_off * PCPU_MIN_ALLOC_SIZE);
> -	page_end = PFN_UP((bit_off + bits) * PCPU_MIN_ALLOC_SIZE);
> +	start = PFN_DOWN(bit_off * PCPU_MIN_ALLOC_SIZE);
> +	end = PFN_UP((bit_off + bits) * PCPU_MIN_ALLOC_SIZE);
>  
> -	rs = page_start;
> -	bitmap_next_clear_region(chunk->populated, &rs, &re, page_end);
> -	if (rs >= page_end)
> +	start = find_next_zero_bit(chunk->populated, end, start);
> +	if (start >= end)
>  		return true;
>  
> -	*next_off = re * PAGE_SIZE / PCPU_MIN_ALLOC_SIZE;
> +	end = find_next_bit(chunk->populated, end, start + 1);
> +
> +	*next_off = end * PAGE_SIZE / PCPU_MIN_ALLOC_SIZE;
>  	return false;
>  }
>  
> -- 
> 2.30.2
> 

Sorry for the delay.

Acked-by: Dennis Zhou <dennis@kernel.org>

Thanks,
Dennis
diff mbox series

Patch

diff --git a/mm/percpu.c b/mm/percpu.c
index 7f2e0151c4e2..25461571dcc5 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1071,17 +1071,18 @@  static void pcpu_block_update_hint_free(struct pcpu_chunk *chunk, int bit_off,
 static bool pcpu_is_populated(struct pcpu_chunk *chunk, int bit_off, int bits,
 			      int *next_off)
 {
-	unsigned int page_start, page_end, rs, re;
+	unsigned int start, end;
 
-	page_start = PFN_DOWN(bit_off * PCPU_MIN_ALLOC_SIZE);
-	page_end = PFN_UP((bit_off + bits) * PCPU_MIN_ALLOC_SIZE);
+	start = PFN_DOWN(bit_off * PCPU_MIN_ALLOC_SIZE);
+	end = PFN_UP((bit_off + bits) * PCPU_MIN_ALLOC_SIZE);
 
-	rs = page_start;
-	bitmap_next_clear_region(chunk->populated, &rs, &re, page_end);
-	if (rs >= page_end)
+	start = find_next_zero_bit(chunk->populated, end, start);
+	if (start >= end)
 		return true;
 
-	*next_off = re * PAGE_SIZE / PCPU_MIN_ALLOC_SIZE;
+	end = find_next_bit(chunk->populated, end, start + 1);
+
+	*next_off = end * PAGE_SIZE / PCPU_MIN_ALLOC_SIZE;
 	return false;
 }