FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

 
 
LinkBack Thread Tools
 
Old 08-15-2011, 06:52 PM
Mikulas Patocka
 
Default dm-space-map-disk: improve bit testing

dm-space-map-disk: improve bit testing

This patch improves bit testing in bitmap_word_used:
* replace three tests with just one condition.
* make the test accurate --- the function returns 0 only if there exists
a pair of two zeroed bits. Previously, the function returned 0 in some other
cases too.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
drivers/md/persistent-data/dm-space-map-disk.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

Index: linux-3.0-fast/drivers/md/persistent-data/dm-space-map-disk.c
================================================== =================
--- linux-3.0-fast.orig/drivers/md/persistent-data/dm-space-map-disk.c 2011-08-15 20:39:38.000000000 +0200
+++ linux-3.0-fast/drivers/md/persistent-data/dm-space-map-disk.c 2011-08-15 20:44:34.000000000 +0200
@@ -70,7 +70,6 @@ void *dm_bitmap_data(struct dm_block *b)

#define WORD_MASK_LOW 0x5555555555555555ULL
#define WORD_MASK_HIGH 0xAAAAAAAAAAAAAAAAULL
-#define WORD_MASK_ALL 0xFFFFFFFFFFFFFFFFULL

static unsigned bitmap_word_used(void *addr, unsigned b)
{
@@ -78,10 +77,9 @@ static unsigned bitmap_word_used(void *a
__le64 *w_le = words_le + (b >> ENTRIES_SHIFT);

uint64_t bits = le64_to_cpu(*w_le);
+ uint64_t mask = (bits - WORD_MASK_LOW) & WORD_MASK_HIGH;

- return ((bits & WORD_MASK_LOW) == WORD_MASK_LOW ||
- (bits & WORD_MASK_HIGH) == WORD_MASK_HIGH ||
- (bits & WORD_MASK_ALL) == WORD_MASK_ALL);
+ return !(~bits & mask);
}

unsigned sm_lookup_bitmap(void *addr, unsigned b)

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 08-16-2011, 10:08 AM
Joe Thornber
 
Default dm-space-map-disk: improve bit testing

On Mon, Aug 15, 2011 at 02:52:14PM -0400, Mikulas Patocka wrote:
> dm-space-map-disk: improve bit testing

Very nice, thanks. btw, you can get rid of WORD_MASK_LOW too:

diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
index 8d2c4c2..fbfa6f3 100644
--- a/drivers/md/persistent-data/dm-space-map-disk.c
+++ b/drivers/md/persistent-data/dm-space-map-disk.c
@@ -69,7 +69,6 @@ void *dm_bitmap_data(struct dm_block *b)
return dm_block_data(b) + sizeof(struct disk_bitmap_header);
}

-#define WORD_MASK_LOW 0x5555555555555555ULL
#define WORD_MASK_HIGH 0xAAAAAAAAAAAAAAAAULL

static unsigned bitmap_word_used(void *addr, unsigned b)
@@ -78,7 +77,7 @@ static unsigned bitmap_word_used(void *addr, unsigned b)
__le64 *w_le = words_le + (b >> ENTRIES_SHIFT);

uint64_t bits = le64_to_cpu(*w_le);
- uint64_t mask = (bits - WORD_MASK_LOW) & WORD_MASK_HIGH;
+ uint64_t mask = (bits + WORD_MASK_HIGH + 1) & WORD_MASK_HIGH;

return !(~bits & mask);
}

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 

Thread Tools




All times are GMT. The time now is 08:42 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org