Skip to contentSkip to conversation

lib/find: optimize find_*_bit_wrap

PATCH In review Yury Norov 1 participant 3 messages Oct 28, 2023 – Dec 3, 2023 Bitmap API

lore
Share & tools
lore

Yury Norov

author maintainer
#0 lore raw

PATCH 1/1 lib/find: optimize find_*_bit_wrap

When an offset is 0, there's no need to search a bitmap from the beginning after the 1st search failed, because each bit has already been tested.

---
 include/linux/find.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/find.h +2 -2
index 5e4f39ef2e72..241b6d028eda 100644
@@ -405,7 +405,7 @@ unsigned long find_next_and_bit_wrap(const unsigned long *addr1,
 {
 	unsigned long bit = find_next_and_bit(addr1, addr2, size, offset);
 
-	if (bit < size)
+	if (bit < size || offset == 0)
 		return bit;
 
 	bit = find_first_and_bit(addr1, addr2, offset);
@@ -427,7 +427,7 @@ unsigned long find_next_bit_wrap(const unsigned long *addr,
 {
 	unsigned long bit = find_next_bit(addr, size, offset);
 
-	if (bit < size)
+	if (bit < size || offset == 0)
 		return bit;
 
 	bit = find_first_bit(addr, offset);
Signature · 1 line
2.39.2
author maintainer
#1 lore raw

Ping?

Quoted 33 lines · Yury Norov

When an offset is 0, there's no need to search a bitmap from the beginning after the 1st search failed, because each bit has already been tested.

---
 include/linux/find.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/find.h +2 -2
index 5e4f39ef2e72..241b6d028eda 100644
@@ -405,7 +405,7 @@ unsigned long find_next_and_bit_wrap(const unsigned long *addr1,
 {
 	unsigned long bit = find_next_and_bit(addr1, addr2, size, offset);
 
-	if (bit < size)
+	if (bit < size || offset == 0)
 		return bit;
 
 	bit = find_first_and_bit(addr1, addr2, offset);
@@ -427,7 +427,7 @@ unsigned long find_next_bit_wrap(const unsigned long *addr,
 {
 	unsigned long bit = find_next_bit(addr, size, offset);
 
-	if (bit < size)
+	if (bit < size || offset == 0)
 		return bit;
 
 	bit = find_first_bit(addr, offset);
Signature · 1 line
2.39.2
author maintainer
#2 lore raw

OK, taking in bitmap-for-next

Quoted 36 lines · Yury Norov

Ping?

Quoted 33 lines · Yury Norov

When an offset is 0, there's no need to search a bitmap from the beginning after the 1st search failed, because each bit has already been tested.

---
 include/linux/find.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/find.h +2 -2
index 5e4f39ef2e72..241b6d028eda 100644
@@ -405,7 +405,7 @@ unsigned long find_next_and_bit_wrap(const unsigned long *addr1,
 {
 	unsigned long bit = find_next_and_bit(addr1, addr2, size, offset);
 
-	if (bit < size)
+	if (bit < size || offset == 0)
 		return bit;
 
 	bit = find_first_and_bit(addr1, addr2, offset);
@@ -427,7 +427,7 @@ unsigned long find_next_bit_wrap(const unsigned long *addr,
 {
 	unsigned long bit = find_next_bit(addr, size, offset);
 
-	if (bit < size)
+	if (bit < size || offset == 0)
 		return bit;
 
 	bit = find_first_bit(addr, offset);
Signature · 1 line
2.39.2