gfs2-utils: master - Streamline the bitmap code by always using 4-bit size per block

Bob Peterson rpeterso at fedoraproject.org
Tue Jan 26 21:08:27 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=daf60a863e9295f8d8ac9d9b7a780c5d0e522b59
Commit:        daf60a863e9295f8d8ac9d9b7a780c5d0e522b59
Parent:        366d4b92a6dc67f5297a02767eec2878be270d23
Author:        Bob Peterson <bob at ganesha.peterson>
AuthorDate:    Wed Nov 25 14:34:55 2009 -0600
Committer:     Bob Peterson <rpeterso at redhat.com>
CommitterDate: Tue Jan 26 15:09:40 2010 -0600

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/block_list.c |   85 +++++++--------------------------------------
 gfs2/libgfs2/libgfs2.h    |    2 -
 2 files changed, 13 insertions(+), 74 deletions(-)

diff --git a/gfs2/libgfs2/block_list.c b/gfs2/libgfs2/block_list.c
index d978f12..04acdc6 100644
--- a/gfs2/libgfs2/block_list.c
+++ b/gfs2/libgfs2/block_list.c
@@ -18,56 +18,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;
@@ -85,15 +46,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;
@@ -105,15 +60,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;
@@ -125,15 +74,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;
@@ -146,8 +89,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,
@@ -160,7 +101,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;
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 38100d3..27035e8 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -289,8 +289,6 @@ enum update_flags {
 struct gfs2_bmap {
         uint64_t size;
         uint64_t mapsize;
-        int chunksize;
-        int chunks_per_byte;
         char *map;
 };
 


More information about the cluster-commits mailing list