aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ellenberg <lars.ellenberg@linbit.com>2015-03-20 11:15:24 -0400
committerJens Axboe <axboe@fb.com>2015-11-25 11:22:02 -0500
commit5fb3bc4ddcdda8d2a6b2185075d140b9009f99b5 (patch)
tree01a12b8cc25d87f78bce162e1b3636ace94aa69b
parent2630628b2dbc3fc320aafaf84836119e4e3d62f1 (diff)
drbd: use bitmap_weight() helper, don't open code
Suggested by Akinobu Mita <akinobu.mita@gmail.com> Signed-off-by: Philipp Reisner <philipp.reisner@linbit.com> Signed-off-by: Lars Ellenberg <lars.ellenberg@linbit.com> Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--drivers/block/drbd/drbd_bitmap.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 8bdc34dbaedf..0dabc9b93725 100644
--- a/drivers/block/drbd/drbd_bitmap.c
+++ b/drivers/block/drbd/drbd_bitmap.c
@@ -24,7 +24,7 @@
24 24
25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 25#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
26 26
27#include <linux/bitops.h> 27#include <linux/bitmap.h>
28#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/drbd.h> 30#include <linux/drbd.h>
@@ -565,21 +565,19 @@ static unsigned long bm_count_bits(struct drbd_bitmap *b)
565 unsigned long *p_addr; 565 unsigned long *p_addr;
566 unsigned long bits = 0; 566 unsigned long bits = 0;
567 unsigned long mask = (1UL << (b->bm_bits & BITS_PER_LONG_MASK)) -1; 567 unsigned long mask = (1UL << (b->bm_bits & BITS_PER_LONG_MASK)) -1;
568 int idx, i, last_word; 568 int idx, last_word;
569 569
570 /* all but last page */ 570 /* all but last page */
571 for (idx = 0; idx < b->bm_number_of_pages - 1; idx++) { 571 for (idx = 0; idx < b->bm_number_of_pages - 1; idx++) {
572 p_addr = __bm_map_pidx(b, idx); 572 p_addr = __bm_map_pidx(b, idx);
573 for (i = 0; i < LWPP; i++) 573 bits += bitmap_weight(p_addr, BITS_PER_PAGE);
574 bits += hweight_long(p_addr[i]);
575 __bm_unmap(p_addr); 574 __bm_unmap(p_addr);
576 cond_resched(); 575 cond_resched();
577 } 576 }
578 /* last (or only) page */ 577 /* last (or only) page */
579 last_word = ((b->bm_bits - 1) & BITS_PER_PAGE_MASK) >> LN2_BPL; 578 last_word = ((b->bm_bits - 1) & BITS_PER_PAGE_MASK) >> LN2_BPL;
580 p_addr = __bm_map_pidx(b, idx); 579 p_addr = __bm_map_pidx(b, idx);
581 for (i = 0; i < last_word; i++) 580 bits += bitmap_weight(p_addr, last_word * BITS_PER_LONG);
582 bits += hweight_long(p_addr[i]);
583 p_addr[last_word] &= cpu_to_lel(mask); 581 p_addr[last_word] &= cpu_to_lel(mask);
584 bits += hweight_long(p_addr[last_word]); 582 bits += hweight_long(p_addr[last_word]);
585 /* 32bit arch, may have an unused padding long */ 583 /* 32bit arch, may have an unused padding long */
@@ -1425,6 +1423,9 @@ static inline void bm_set_full_words_within_one_page(struct drbd_bitmap *b,
1425 int bits; 1423 int bits;
1426 int changed = 0; 1424 int changed = 0;
1427 unsigned long *paddr = kmap_atomic(b->bm_pages[page_nr]); 1425 unsigned long *paddr = kmap_atomic(b->bm_pages[page_nr]);
1426
1427 /* I think it is more cache line friendly to hweight_long then set to ~0UL,
1428 * than to first bitmap_weight() all words, then bitmap_fill() all words */
1428 for (i = first_word; i < last_word; i++) { 1429 for (i = first_word; i < last_word; i++) {
1429 bits = hweight_long(paddr[i]); 1430 bits = hweight_long(paddr[i]);
1430 paddr[i] = ~0UL; 1431 paddr[i] = ~0UL;
@@ -1634,8 +1635,7 @@ int drbd_bm_e_weight(struct drbd_device *device, unsigned long enr)
1634 int n = e-s; 1635 int n = e-s;
1635 p_addr = bm_map_pidx(b, bm_word_to_page_idx(b, s)); 1636 p_addr = bm_map_pidx(b, bm_word_to_page_idx(b, s));
1636 bm = p_addr + MLPP(s); 1637 bm = p_addr + MLPP(s);
1637 while (n--) 1638 count += bitmap_weight(bm, n * BITS_PER_LONG);
1638 count += hweight_long(*bm++);
1639 bm_unmap(p_addr); 1639 bm_unmap(p_addr);
1640 } else { 1640 } else {
1641 drbd_err(device, "start offset (%d) too large in drbd_bm_e_weight\n", s); 1641 drbd_err(device, "start offset (%d) too large in drbd_bm_e_weight\n", s);