From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
Philipp Reisner <lars.ellenberg@linbit.com>,
Lars Ellenberg <philipp.reisner@linbit.com>,
drbd-dev@lists.linbit.com
Subject: [PATCH] drbd: use bitmap_weight()
Date: Sat, 14 Mar 2015 10:12:56 +0900 [thread overview]
Message-ID: <1426295577-10836-4-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1426295577-10836-1-git-send-email-akinobu.mita@gmail.com>
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
next prev parent reply other threads:[~2015-03-14 1:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-14 1:12 [PATCH] hpsa: cleanup bitops usage Akinobu Mita
2015-03-14 1:12 ` [PATCH] cpqarray: simplify bitops usages Akinobu Mita
2015-03-14 1:12 ` [PATCH] pktcdvd: convert char array to bitmap Akinobu Mita
2015-03-14 1:12 ` Akinobu Mita [this message]
2015-03-20 15:14 ` [Drbd-dev] [PATCH] drbd: use bitmap_weight() Lars Ellenberg
2015-03-22 2:11 ` Akinobu Mita
2015-03-14 1:12 ` [PATCH] ia64: Use bitmap_weight Akinobu Mita
2015-03-22 7:31 [PATCH] drbd: use bitmap_weight() Akinobu Mita
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1426295577-10836-4-git-send-email-akinobu.mita@gmail.com \
--to=akinobu.mita@gmail.com \
--cc=drbd-dev@lists.linbit.com \
--cc=lars.ellenberg@linbit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=philipp.reisner@linbit.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).