Distributed Replicated Block Device (DRBD) development
 help / color / mirror / Atom feed
From: Philipp Reisner <philipp.reisner@linbit.com>
To: linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>
Cc: drbd-dev@lists.linbit.com
Subject: [Drbd-dev] [PATCH 07/19] drbd: use bitmap_weight() helper, don't open code
Date: Tue,  4 Aug 2015 14:56:31 +0200	[thread overview]
Message-ID: <1438693003-17554-8-git-send-email-philipp.reisner@linbit.com> (raw)
In-Reply-To: <1438693003-17554-1-git-send-email-philipp.reisner@linbit.com>

From: Lars Ellenberg <lars.ellenberg@linbit.com>

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>
---
 drivers/block/drbd/drbd_bitmap.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
index 227deb0..c09c571 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>
@@ -565,21 +565,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, BITS_PER_PAGE);
 		__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 */
@@ -1434,6 +1432,9 @@ static inline void bm_set_full_words_within_one_page(struct drbd_bitmap *b,
 	int bits;
 	int changed = 0;
 	unsigned long *paddr = kmap_atomic(b->bm_pages[page_nr]);
+
+	/* I think it is more cache line friendly to hweight_long then set to ~0UL,
+	 * than to first bitmap_weight() all words, then bitmap_fill() all words */
 	for (i = first_word; i < last_word; i++) {
 		bits = hweight_long(paddr[i]);
 		paddr[i] = ~0UL;
@@ -1643,8 +1644,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


  parent reply	other threads:[~2015-08-04 12:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-04 12:56 [Drbd-dev] [PATCH 00/19] RFC DRBD updates for the 4.3 merge window (part II) Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 01/19] drbd: Rename asender to ack_receiver Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 02/19] drbd: Create a dedicated workqueue for sending acks on the control connection Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 03/19] drbd: prevent NULL pointer deref when resuming diskless primary Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 04/19] drbd: debugfs: expose ed_data_gen_id Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 05/19] drbd: use resource name in workqueue Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 06/19] drbd: avoid redefinition of BITS_PER_PAGE Philipp Reisner
2015-08-04 12:56 ` Philipp Reisner [this message]
2015-08-04 12:56 ` [Drbd-dev] [PATCH 08/19] drbd: fix spurious alert level printk Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 09/19] drbd: fix queue limit setup for discard Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 10/19] drbd: make drbd known to lsblk: use bd_link_disk_holder Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 11/19] lru_cache: Converted lc_seq_printf_status to return void Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 12/19] drbd: don't block forever in disconnect during resync if fencing=r-a-stonith Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 13/19] drbd: fix memory leak in drbd_adm_resize Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 14/19] drbd: fix "endless" transfer log walk in protocol A Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 15/19] drbd: make suspend_io() / resume_io() must be thread and recursion safe Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 16/19] drbd: separate out __al_write_transaction helper function Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 17/19] drbd: avoid potential deadlock during handshake Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 18/19] drbd: fix error path during resize Philipp Reisner
2015-08-04 12:56 ` [Drbd-dev] [PATCH 19/19] MAINTAINERS: Updated information for DRBD DRIVER Philipp Reisner

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=1438693003-17554-8-git-send-email-philipp.reisner@linbit.com \
    --to=philipp.reisner@linbit.com \
    --cc=axboe@kernel.dk \
    --cc=drbd-dev@lists.linbit.com \
    --cc=linux-kernel@vger.kernel.org \
    /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