Skip to contentSkip to conversation

bitmap.h: add const modifier to bitmap_next_[set/clear]_region() argument

PATCH In review Andrea Merello 4 participants 6 messages Jul 27, 2021 – Jul 28, 2021 Bitmap API

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitmap.h: add const modifier to bitmap_next_[set/clear]_region() argument

Those two functions don't modify the bitmap, so their bitmap argument should be const. This patch add this.

---
 include/linux/bitmap.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/bitmap.h +2 -2
index a36cfcec4e77..ea4a8f1a2545 100644
@@ -458,7 +458,7 @@ static inline void bitmap_replace(unsigned long *dst,
 		__bitmap_replace(dst, old, new, mask, nbits);
 }
 
-static inline void bitmap_next_clear_region(unsigned long *bitmap,
+static inline void bitmap_next_clear_region(const unsigned long *bitmap,
 					    unsigned int *rs, unsigned int *re,
 					    unsigned int end)
 {
@@ -466,7 +466,7 @@ static inline void bitmap_next_clear_region(unsigned long *bitmap,
 	*re = find_next_bit(bitmap, end, *rs + 1);
 }
 
-static inline void bitmap_next_set_region(unsigned long *bitmap,
+static inline void bitmap_next_set_region(const unsigned long *bitmap,
 					  unsigned int *rs, unsigned int *re,
 					  unsigned int end)
 {
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Andrea Merello

Those two functions don't modify the bitmap, so their bitmap argument should be const. This patch add this.

Constification is always a good thing. No objections from me, although Yuri is doing something with them in one of his patch series.

Yuri, do you have a public repo / branch that people can base their changes to bitmap stuff against of?

Quoted 30 lines
---
 include/linux/bitmap.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/bitmap.h +2 -2
index a36cfcec4e77..ea4a8f1a2545 100644
@@ -458,7 +458,7 @@ static inline void bitmap_replace(unsigned long *dst,
 		__bitmap_replace(dst, old, new, mask, nbits);
 }
 
-static inline void bitmap_next_clear_region(unsigned long *bitmap,
+static inline void bitmap_next_clear_region(const unsigned long *bitmap,
 					    unsigned int *rs, unsigned int *re,
 					    unsigned int end)
 {
@@ -466,7 +466,7 @@ static inline void bitmap_next_clear_region(unsigned long *bitmap,
 	*re = find_next_bit(bitmap, end, *rs + 1);
 }
 
-static inline void bitmap_next_set_region(unsigned long *bitmap,
+static inline void bitmap_next_set_region(const unsigned long *bitmap,
 					  unsigned int *rs, unsigned int *re,
 					  unsigned int end)
 {
Signature · 1 line
2.17.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Acked-by
#2 lore raw
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Andrea Merello

Those two functions don't modify the bitmap, so their bitmap argument should be const. This patch add this.

Thanks Andrea.

Quoted 2 lines

Constification is always a good thing. No objections from me, although Yuri is doing something with them in one of his patch series.

I try to remove those two because in practice they bring more mess than good. All real use-cases for bitmap_next_{set,clear}_region relate to iterating the whole bitmap, ie nobody just wants to find a next region. Untill recently there was only a single user of the API, so I easily reworked the code to use find_first_bit/find_next bit and by chance return faster.

https://github.com/norov/linux/commit/1c870b5c3fcd2eea9b351a1e0af8d1e93be78e1e

Recently in next-20210716, there appeared another user in fs/btrfs/extent_io.c:
find_next_dirty_byte(). The fun is that in that case the length of bitmap is 16 bit, so it's probably simpler to return the bitmap by value, instead of calling prologue code up to 8 times. Anyways, I'll contact authors of the find_next_dirty_byte() and ask if it's possible to rework their code.

Quoted 2 lines

Yuri, do you have a public repo / branch that people can base their changes to bitmap stuff against of?

I collected not yet upstreamed bitmap patches here:

https://github.com/norov/linux/commits/bitmap-20210716

Please let me know if you believe we need a more official branch for bitmaps. I'd encourage people to review what we already have and upstream it.

Thanks,
Yury

Quoted 37 lines
Quoted 30 lines
---
 include/linux/bitmap.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/bitmap.h +2 -2
index a36cfcec4e77..ea4a8f1a2545 100644
@@ -458,7 +458,7 @@ static inline void bitmap_replace(unsigned long *dst,
 		__bitmap_replace(dst, old, new, mask, nbits);
 }
 
-static inline void bitmap_next_clear_region(unsigned long *bitmap,
+static inline void bitmap_next_clear_region(const unsigned long *bitmap,
 					    unsigned int *rs, unsigned int *re,
 					    unsigned int end)
 {
@@ -466,7 +466,7 @@ static inline void bitmap_next_clear_region(unsigned long *bitmap,
 	*re = find_next_bit(bitmap, end, *rs + 1);
 }
 
-static inline void bitmap_next_set_region(unsigned long *bitmap,
+static inline void bitmap_next_set_region(const unsigned long *bitmap,
 					  unsigned int *rs, unsigned int *re,
 					  unsigned int end)
 {
Signature · 1 line
2.17.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw

Il giorno mar 27 lug 2021 alle ore 17:26 Yury Norov <[email protected]> ha scritto:

Quoted 13 lines · Andy Shevchenko
Quoted 3 lines · Andrea Merello
Quoted 2 lines

Those two functions don't modify the bitmap, so their bitmap argument should be const. This patch add this.

Thanks Andrea.

Quoted 2 lines

Constification is always a good thing. No objections from me, although Yuri is doing something with them in one of his patch series.

Quoted 6 lines

I try to remove those two because in practice they bring more mess than good. All real use-cases for bitmap_next_{set,clear}_region relate to iterating the whole bitmap, ie nobody just wants to find a next region. Untill recently there was only a single user of the API, so I easily reworked the code to use find_first_bit/find_next bit and by chance return faster.

Ah, that's interesting to know: I'm working on a new driver that used find_next_zero_bit() and find_next_bit() [0]; Andy told me that my algorithm could be rewritten exploiting some bitmap_* helpers, so I rewrote my code using bitmap_for_each_set_region(), which in turn uses bitmap_next_set_region().

Should I revert to my previous implementation that uses find_next_zero_bit() and find_next_bit() ?

[0] https://lore.kernel.org/linux-iio/[email protected]/

Quoted 9 lines

https://github.com/norov/linux/commit/1c870b5c3fcd2eea9b351a1e0af8d1e93be78e1e

Recently in next-20210716, there appeared another user in fs/btrfs/extent_io.c:
find_next_dirty_byte(). The fun is that in that case the length of bitmap is 16 bit, so it's probably simpler to return the bitmap by value, instead of calling prologue code up to 8 times. Anyways, I'll contact authors of the find_next_dirty_byte() and ask if it's possible to rework their code.

Quoted 6 lines
Quoted 2 lines

Yuri, do you have a public repo / branch that people can base their changes to bitmap stuff against of?

I collected not yet upstreamed bitmap patches here:

https://github.com/norov/linux/commits/bitmap-20210716

Looks like also bitmap_for_each_set_region() went away indeed ?

Quoted 44 lines

Please let me know if you believe we need a more official branch for bitmaps. I'd encourage people to review what we already have and upstream it.

Thanks,
Yury

Quoted 37 lines
Quoted 28 lines
---
 include/linux/bitmap.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/bitmap.h +2 -3
index a36cfcec4e77..ea4a8f1a2545 100644
@@ -458,7 +458,7 @@ static inline void bitmap_replace(unsigned long *dst,
            __bitmap_replace(dst, old, new, mask, nbits);
 }
 
-static inline void bitmap_next_clear_region(unsigned long *bitmap,
+static inline void bitmap_next_clear_region(const unsigned long *bitmap,
                                        unsigned int *rs, unsigned int *re,
                                        unsigned int end)
 {
@@ -466,7 +466,7 @@ static inline void bitmap_next_clear_region(unsigned long *bitmap,
    *re = find_next_bit(bitmap, end, *rs + 1);
 }
 
-static inline void bitmap_next_set_region(unsigned long *bitmap,
+static inline void bitmap_next_set_region(const unsigned long *bitmap,
                                      unsigned int *rs, unsigned int *re,
                                      unsigned int end)
 {
--
Quoted 2 lines

2.17.1

--
With Best Regards,
Andy Shevchenko

#4 lore raw
Quoted 3 lines · Andrea Merello

Il giorno mar 27 lug 2021 alle ore 17:26 Yury Norov <[email protected]> ha scritto:

Quoted 1 line · Andy Shevchenko

...

Quoted 7 lines
Quoted 6 lines

I try to remove those two because in practice they bring more mess than good. All real use-cases for bitmap_next_{set,clear}_region relate to iterating the whole bitmap, ie nobody just wants to find a next region. Untill recently there was only a single user of the API, so I easily reworked the code to use find_first_bit/find_next bit and by chance return faster.

Quoted 8 lines

Ah, that's interesting to know: I'm working on a new driver that used find_next_zero_bit() and find_next_bit() [0]; Andy told me that my algorithm could be rewritten exploiting some bitmap_* helpers, so I rewrote my code using bitmap_for_each_set_region(), which in turn uses bitmap_next_set_region().

Should I revert to my previous implementation that uses find_next_zero_bit() and find_next_bit() ?

According to the

https://github.com/norov/linux/commit/a2d6e02d19450a49a55f08c151d1f704723bec1a

they are transformed to for_each_bitrange(), etc.

...

Quoted 1 line

Looks like also bitmap_for_each_set_region() went away indeed ?

See above.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw
In reply to Andrea Merello
Quoted 28 lines · Andrea Merello

Il giorno mar 27 lug 2021 alle ore 17:26 Yury Norov <[email protected]> ha scritto:

Quoted 13 lines · Andy Shevchenko
Quoted 3 lines · Andrea Merello
Quoted 2 lines

Those two functions don't modify the bitmap, so their bitmap argument should be const. This patch add this.

Thanks Andrea.

Quoted 2 lines

Constification is always a good thing. No objections from me, although Yuri is doing something with them in one of his patch series.

Quoted 6 lines

I try to remove those two because in practice they bring more mess than good. All real use-cases for bitmap_next_{set,clear}_region relate to iterating the whole bitmap, ie nobody just wants to find a next region. Untill recently there was only a single user of the API, so I easily reworked the code to use find_first_bit/find_next bit and by chance return faster.

Ah, that's interesting to know: I'm working on a new driver that used find_next_zero_bit() and find_next_bit() [0]; Andy told me that my algorithm could be rewritten exploiting some bitmap_* helpers, so I rewrote my code using bitmap_for_each_set_region(), which in turn uses bitmap_next_set_region().

Quoted 4 lines

Should I revert to my previous implementation that uses find_next_zero_bit() and find_next_bit() ?

[0] https://lore.kernel.org/linux-iio/[email protected]/

No, you're doing right. I just reimplemented and renamed bitmap_for_each_set_region to unify with other similar functions. The transition is very stragthforward, so you have nothing to worry on.

https://patchwork.kernel.org/project/linux-mmc/patch/[email protected]/

Quoted 10 lines
Quoted 10 lines

https://github.com/norov/linux/commit/1c870b5c3fcd2eea9b351a1e0af8d1e93be78e1e

Recently in next-20210716, there appeared another user in fs/btrfs/extent_io.c:
find_next_dirty_byte(). The fun is that in that case the length of bitmap is 16 bit, so it's probably simpler to return the bitmap by value, instead of calling prologue code up to 8 times. Anyways, I'll contact authors of the find_next_dirty_byte() and ask if it's possible to rework their code.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Yuri, do you have a public repo / branch that people can base their changes to bitmap stuff against of?

I collected not yet upstreamed bitmap patches here:

https://github.com/norov/linux/commits/bitmap-20210716

Looks like also bitmap_for_each_set_region() went away indeed ?

Just replaced with for_each_{set,clear}_bitrange.

Thanks,
Yury