cluster: RHEL56 - Streamline the bitmap code by always using 4-bit size per block

Bob Peterson rpeterso at fedoraproject.org
Sat Apr 10 04:51:59 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=8639e740d7b51c046d2cffd5b96c6319214b839f
Commit:        8639e740d7b51c046d2cffd5b96c6319214b839f
Parent:        d6e3399a259167c1762651586ea062cf7d0c6c30
Author:        Bob Peterson <bob at ganesha.peterson>
AuthorDate:    Wed Nov 25 14:34:55 2009 -0600
Committer:     Bob Peterson <rpeterso at redhat.com>
CommitterDate: Fri Apr 9 22:48:09 2010 -0500

Streamline the bitmap code by always using 4-bit size per block

The block_map code was always using four bits to represent blocks in
the bitmap.  Therefore, it didn't need all the logic to handle bitmaps
with one bit per block.  This should improve performance.

rhbz#455300
---
 gfs2/libgfs2/Makefile     |    2 +-
 gfs2/libgfs2/block_list.c |   85 +++++++--------------------------------------
 2 files changed, 14 insertions(+), 73 deletions(-)

diff --git a/gfs2/libgfs2/Makefile b/gfs2/libgfs2/Makefile
index 05dde0d..7eeb2ac 100644
--- a/gfs2/libgfs2/Makefile
+++ b/gfs2/libgfs2/Makefile
@@ -27,7 +27,7 @@ CFLAGS=-Wall -ggdb -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE \
        -D_GNU_SOURCE -DGFS2_RELEASE_NAME=\"2\" ${INCLUDEPATH}
 
 H=gfs2_disk_hash.h libgfs2.h linux_endian.h ondisk.h osi_list.h
-C=bitmap.c block_list.c buf.c device_geometry.c fs_bits.c fs_geometry.c fs_ops.c gfs1.c locking.c gfs2_log.c misc.c ondisk.c recovery.c size.c structures.c super.c rgrp.c
+C=block_list.c buf.c device_geometry.c fs_bits.c fs_geometry.c fs_ops.c gfs1.c locking.c gfs2_log.c misc.c ondisk.c recovery.c size.c structures.c super.c rgrp.c
 O=$(subst .c,.o,${C})
 
 all: ${LIBGFS2}
diff --git a/gfs2/libgfs2/block_list.c b/gfs2/libgfs2/block_list.c
index 19e91df..208897b 100644
--- a/gfs2/libgfs2/block_list.c
+++ b/gfs2/libgfs2/block_list.c
@@ -29,56 +29,17 @@ static int mark_to_gbmap[16] = {
 	INVALID_META, INVALID_META
 };
 
-#define BITMAP_SIZE(size, cpb) (size / cpb)
-#define BITMAP_SIZE1(size) (size >> 3)
 #define BITMAP_SIZE4(size) (size >> 1)
-
-#define BITMAP_BYTE_OFFSET(x, map) ((x % map->chunks_per_byte) \
-                                    * map->chunksize )
-
-/* BITMAP_BYTE_OFFSET1 is for chunksize==1, which implies chunks_per_byte==8 */
-/* Reducing the math, we get:                                                */
-/* #define BITMAP_BYTE_OFFSET1(x) ((x % 8) * 1)                              */
-/* #define BITMAP_BYTE_OFFSET1(x) (x % 8)                                    */
-/* #define BITMAP_BYTE_OFFSET1(x) (x & 0x0000000000000007)                   */
-#define BITMAP_BYTE_OFFSET1(x) (x & 0x0000000000000007)
-
-/* BITMAP_BYTE_OFFSET4 is for chunksize==4, which implies chunks_per_byte==2 */
-/* Reducing the math, we get:                                                */
-/* #define BITMAP_BYTE_OFFSET4(x) ((x % 2) * 4)                              */
-/* #define BITMAP_BYTE_OFFSET4(x) ((x & 0x0000000000000001) * 4)             */
-/* #define BITMAP_BYTE_OFFSET4(x) ((x & 0x0000000000000001) << 2)            */
 #define BITMAP_BYTE_OFFSET4(x) ((x & 0x0000000000000001) << 2)
+#define BITMAP_MASK4 (0xf)
 
-#define BITMAP_MASK(chunksize) ((2 << (chunksize - 1)) - 1)
-/* BITMAP_MASK1 is  for chunksize==1                                         */
-/* Reducing the math, we get:                                                */
-/* #define BITMAP_MASK1(chunksize) ((2 << (1 - 1)) - 1)                      */
-/* #define BITMAP_MASK1(chunksize) ((2 << 0) - 1)                            */
-/* #define BITMAP_MASK1(chunksize) ((2) - 1)                                 */
-#define BITMAP_MASK1(chunksize) (1)
-
-/* BITMAP_MASK4 is  for chunksize==4                                         */
-/* #define BITMAP_MASK(chunksize) ((2 << (4 - 1)) - 1)                       */
-/* #define BITMAP_MASK(chunksize) ((2 << 3) - 1)                             */
-/* #define BITMAP_MASK(chunksize) (0x10 - 1)                                 */
-#define BITMAP_MASK4(chunksize) (0xf)
-
-static int gfs2_bitmap_create(struct gfs2_bmap *bmap, uint64_t size,
-					   uint8_t chunksize)
+static int gfs2_bitmap_create(struct gfs2_bmap *bmap, uint64_t size)
 {
-	if((((chunksize >> 1) << 1) != chunksize) && chunksize != 1)
-		return -1;
-	if(chunksize > 8)
-		return -1;
-	bmap->chunksize = chunksize;
-	bmap->chunks_per_byte = 8 / chunksize;
-
 	bmap->size = size;
 
 	/* Have to add 1 to BITMAP_SIZE since it's 0-based and mallocs
 	 * must be 1-based */
-	bmap->mapsize = BITMAP_SIZE(size, bmap->chunks_per_byte)+1;
+	bmap->mapsize = BITMAP_SIZE4(size);
 
 	if(!(bmap->map = malloc(sizeof(char) * bmap->mapsize)))
 		return -ENOMEM;
@@ -96,15 +57,9 @@ static int gfs2_bitmap_set(struct gfs2_bmap *bmap, uint64_t offset, uint8_t val)
 	static uint64_t b;
 
 	if(offset < bmap->size) {
-		if (bmap->chunksize == 1) {
-			byte = bmap->map + BITMAP_SIZE1(offset);
-			b = BITMAP_BYTE_OFFSET1(offset);
-			*byte |= (val & BITMAP_MASK1(bmap->chunksize));
-		} else {
-			byte = bmap->map + BITMAP_SIZE4(offset);
-			b = BITMAP_BYTE_OFFSET4(offset);
-			*byte |= (val & BITMAP_MASK4(bmap->chunksize)) << b;
-		}
+		byte = bmap->map + BITMAP_SIZE4(offset);
+		b = BITMAP_BYTE_OFFSET4(offset);
+		*byte |= (val & BITMAP_MASK4) << b;
 		return 0;
 	}
 	return -1;
@@ -116,15 +71,9 @@ static int gfs2_bitmap_get(struct gfs2_bmap *bmap, uint64_t bit, uint8_t *val)
 	static uint64_t b;
 
 	if(bit < bmap->size) {
-		if (bmap->chunksize == 1) {
-			byte = bmap->map + BITMAP_SIZE1(bit);
-			b = BITMAP_BYTE_OFFSET1(bit);
-			*val = (*byte & (BITMAP_MASK1(bmap->chunksize) << b )) >> b;
-		} else {
-			byte = bmap->map + BITMAP_SIZE4(bit);
-			b = BITMAP_BYTE_OFFSET4(bit);
-			*val = (*byte & (BITMAP_MASK4(bmap->chunksize) << b )) >> b;
-		}
+		byte = bmap->map + BITMAP_SIZE4(bit);
+		b = BITMAP_BYTE_OFFSET4(bit);
+		*val = (*byte & (BITMAP_MASK4 << b )) >> b;
 		return 0;
 	}
 	return -1;
@@ -136,15 +85,9 @@ static int gfs2_bitmap_clear(struct gfs2_bmap *bmap, uint64_t offset)
 	static uint64_t b;
 
 	if(offset < bmap->size) {
-		if (bmap->chunksize == 1) {
-			byte = bmap->map + BITMAP_SIZE1(offset);
-			b = BITMAP_BYTE_OFFSET1(offset);
-			*byte &= ~(BITMAP_MASK1(bmap->chunksize) << b);
-		} else {
-			byte = bmap->map + BITMAP_SIZE4(offset);
-			b = BITMAP_BYTE_OFFSET4(offset);
-			*byte &= ~(BITMAP_MASK4(bmap->chunksize) << b);
-		}
+		byte = bmap->map + BITMAP_SIZE4(offset);
+		b = BITMAP_BYTE_OFFSET4(offset);
+		*byte &= ~(BITMAP_MASK4 << b);
 		return 0;
 	}
 	return -1;
@@ -157,8 +100,6 @@ static void gfs2_bitmap_destroy(struct gfs2_bmap *bmap)
 		free(bmap->map);
 	bmap->size = 0;
 	bmap->mapsize = 0;
-	bmap->chunksize = 0;
-	bmap->chunks_per_byte = 0;
 }
 
 struct gfs2_bmap *gfs2_bmap_create(struct gfs2_sbd *sdp, uint64_t size,
@@ -171,7 +112,7 @@ struct gfs2_bmap *gfs2_bmap_create(struct gfs2_sbd *sdp, uint64_t size,
 	if (!il || !memset(il, 0, sizeof(*il)))
 		return NULL;
 
-	if(gfs2_bitmap_create(il, size, 4)) {
+	if(gfs2_bitmap_create(il, size)) {
 		*addl_mem_needed = il->mapsize;
 		free(il);
 		il = NULL;


More information about the cluster-commits mailing list