* [Drbd-dev] [PATCH] drbd: use bitmap_weight()
[not found] <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com>
@ 2015-03-14 1:12 ` Akinobu Mita
2015-03-20 15:14 ` Lars Ellenberg
0 siblings, 1 reply; 4+ messages in thread
From: Akinobu Mita @ 2015-03-14 1:12 UTC (permalink / raw)
To: linux-kernel; +Cc: Philipp Reisner, drbd-dev, Akinobu Mita, Lars Ellenberg
Use bitmap_weight to count the total number of bits set in bitmap.
This change just simplifies the code a bit.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Philipp Reisner <lars.ellenberg@linbit.com>
Cc: Lars Ellenberg <philipp.reisner@linbit.com>
Cc: drbd-dev@lists.linbit.com
---
drivers/block/drbd/drbd_bitmap.c | 26 ++++++++++----------------
1 file changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 434c77d..39d31af 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -24,7 +24,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-#include <linux/bitops.h>
+#include <linux/bitmap.h>
#include <linux/vmalloc.h>
#include <linux/string.h>
#include <linux/drbd.h>
@@ -559,21 +559,19 @@ static unsigned long bm_count_bits(struct drbd_bitmap *b)
unsigned long *p_addr;
unsigned long bits = 0;
unsigned long mask = (1UL << (b->bm_bits & BITS_PER_LONG_MASK)) -1;
- int idx, i, last_word;
+ int idx, last_word;
/* all but last page */
for (idx = 0; idx < b->bm_number_of_pages - 1; idx++) {
p_addr = __bm_map_pidx(b, idx);
- for (i = 0; i < LWPP; i++)
- bits += hweight_long(p_addr[i]);
+ bits += bitmap_weight(p_addr, PAGE_SIZE * BITS_PER_BYTE);
__bm_unmap(p_addr);
cond_resched();
}
/* last (or only) page */
last_word = ((b->bm_bits - 1) & BITS_PER_PAGE_MASK) >> LN2_BPL;
p_addr = __bm_map_pidx(b, idx);
- for (i = 0; i < last_word; i++)
- bits += hweight_long(p_addr[i]);
+ bits += bitmap_weight(p_addr, last_word * BITS_PER_LONG);
p_addr[last_word] &= cpu_to_lel(mask);
bits += hweight_long(p_addr[last_word]);
/* 32bit arch, may have an unused padding long */
@@ -1424,15 +1422,12 @@ int drbd_bm_clear_bits(struct drbd_device *device, const unsigned long s, const
static inline void bm_set_full_words_within_one_page(struct drbd_bitmap *b,
int page_nr, int first_word, int last_word)
{
- int i;
- int bits;
- int changed = 0;
unsigned long *paddr = kmap_atomic(b->bm_pages[page_nr]);
- for (i = first_word; i < last_word; i++) {
- bits = hweight_long(paddr[i]);
- paddr[i] = ~0UL;
- changed += BITS_PER_LONG - bits;
- }
+ int nbits = (last_word - first_word) * BITS_PER_LONG;
+ int changed;
+
+ changed = nbits - bitmap_weight(paddr + first_word, nbits);
+ bitmap_fill(paddr + first_word, nbits);
kunmap_atomic(paddr);
if (changed) {
/* We only need lazy writeout, the information is still in the
@@ -1637,8 +1632,7 @@ int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr)
int n = e-s;
p_addr = bm_map_pidx(b, bm_word_to_page_idx(b, s));
bm = p_addr + MLPP(s);
- while (n--)
- count += hweight_long(*bm++);
+ count = bitmap_weight(bm, n * BITS_PER_LONG);
bm_unmap(p_addr);
} else {
drbd_err(device, "start offset (%d) too large in drbd_bm_e_weight\n", s);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Drbd-dev] [PATCH] drbd: use bitmap_weight()
2015-03-14 1:12 ` [Drbd-dev] [PATCH] drbd: use bitmap_weight() Akinobu Mita
@ 2015-03-20 15:14 ` Lars Ellenberg
2015-03-22 2:11 ` Akinobu Mita
0 siblings, 1 reply; 4+ messages in thread
From: Lars Ellenberg @ 2015-03-20 15:14 UTC (permalink / raw)
To: Akinobu Mita; +Cc: linux-kernel, drbd-dev
On Sat, Mar 14, 2015 at 10:12:56AM +0900, Akinobu Mita wrote:
> Use bitmap_weight to count the total number of bits set in bitmap.
> This change just simplifies the code a bit.
"Simplifies", not sure about that, but ok, maybe.
For the "bm_set_full_words_within_one_page", I disagree.
I think it is more cpu cache friendly to hweight_long then set to ~0UL
each word in turn, than to first bitmap_weight() all words, then
bitmap_fill() all words.
Thanks,
Lars Ellenberg
BTW, you swapped names and email addresses of phil and me. Are those
listed incorrectly somewhere, or was that just a mishap on your part?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Drbd-dev] [PATCH] drbd: use bitmap_weight()
2015-03-20 15:14 ` Lars Ellenberg
@ 2015-03-22 2:11 ` Akinobu Mita
0 siblings, 0 replies; 4+ messages in thread
From: Akinobu Mita @ 2015-03-22 2:11 UTC (permalink / raw)
To: Akinobu Mita, LKML, drbd-dev
2015-03-21 0:14 GMT+09:00 Lars Ellenberg <lars.ellenberg@linbit.com>:
> On Sat, Mar 14, 2015 at 10:12:56AM +0900, Akinobu Mita wrote:
>> Use bitmap_weight to count the total number of bits set in bitmap.
>> This change just simplifies the code a bit.
>
> "Simplifies", not sure about that, but ok, maybe.
>
> For the "bm_set_full_words_within_one_page", I disagree.
> I think it is more cpu cache friendly to hweight_long then set to ~0UL
> each word in turn, than to first bitmap_weight() all words, then
> bitmap_fill() all words.
I see. I'll remove the change in bm_set_full_words_within_one_page().
> Thanks,
>
> Lars Ellenberg
>
> BTW, you swapped names and email addresses of phil and me. Are those
> listed incorrectly somewhere, or was that just a mishap on your part?
It's just my mistake. I copied your names from MAINTAINERS, but it
doesn't list your email addresses then I incorrectly swapped while
retrieving email addrsses from git log.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Drbd-dev] [PATCH] drbd: use bitmap_weight()
@ 2015-03-22 7:31 Akinobu Mita
0 siblings, 0 replies; 4+ messages in thread
From: Akinobu Mita @ 2015-03-22 7:31 UTC (permalink / raw)
To: linux-kernel; +Cc: Lars Ellenberg, drbd-dev, Akinobu Mita, Philipp Reisner
Use bitmap_weight to count the total number of bits set in bitmap.
This change just simplifies the code a bit.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Lars Ellenberg <lars.ellenberg@linbit.com>
Cc: drbd-dev@lists.linbit.com
---
drivers/block/drbd/drbd_bitmap.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 434c77d..1e62c49 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -24,7 +24,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-#include <linux/bitops.h>
+#include <linux/bitmap.h>
#include <linux/vmalloc.h>
#include <linux/string.h>
#include <linux/drbd.h>
@@ -559,21 +559,19 @@ static unsigned long bm_count_bits(struct drbd_bitmap *b)
unsigned long *p_addr;
unsigned long bits = 0;
unsigned long mask = (1UL << (b->bm_bits & BITS_PER_LONG_MASK)) -1;
- int idx, i, last_word;
+ int idx, last_word;
/* all but last page */
for (idx = 0; idx < b->bm_number_of_pages - 1; idx++) {
p_addr = __bm_map_pidx(b, idx);
- for (i = 0; i < LWPP; i++)
- bits += hweight_long(p_addr[i]);
+ bits += bitmap_weight(p_addr, PAGE_SIZE * BITS_PER_BYTE);
__bm_unmap(p_addr);
cond_resched();
}
/* last (or only) page */
last_word = ((b->bm_bits - 1) & BITS_PER_PAGE_MASK) >> LN2_BPL;
p_addr = __bm_map_pidx(b, idx);
- for (i = 0; i < last_word; i++)
- bits += hweight_long(p_addr[i]);
+ bits += bitmap_weight(p_addr, last_word * BITS_PER_LONG);
p_addr[last_word] &= cpu_to_lel(mask);
bits += hweight_long(p_addr[last_word]);
/* 32bit arch, may have an unused padding long */
@@ -1637,8 +1635,7 @@ int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr)
int n = e-s;
p_addr = bm_map_pidx(b, bm_word_to_page_idx(b, s));
bm = p_addr + MLPP(s);
- while (n--)
- count += hweight_long(*bm++);
+ count = bitmap_weight(bm, n * BITS_PER_LONG);
bm_unmap(p_addr);
} else {
drbd_err(device, "start offset (%d) too large in drbd_bm_e_weight\n", s);
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-22 14:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com>
2015-03-14 1:12 ` [Drbd-dev] [PATCH] drbd: use bitmap_weight() Akinobu Mita
2015-03-20 15:14 ` Lars Ellenberg
2015-03-22 2:11 ` Akinobu Mita
2015-03-22 7:31 Akinobu Mita
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox