Browse Source

Cleaned up a bit the bitmap implementation

The most important change is the following: bmap_array2 and bmap_array3 are only
used temporarily in order to save the results of the shift-add operations. As a
result, I removed them from the raw block's header and put them inside the scope
of bitmap_malloc().

In any way, the bitmap-organized raw block implementation is still not working.
Ioannis Koutras 12 years ago
parent
commit
65913f64f8
2 changed files with 15 additions and 17 deletions
  1. 0 2
      private-include/bitmap/bitmap_rb.h
  2. 15 15
      src/bitmap/bitmap_malloc.c

+ 0 - 2
private-include/bitmap/bitmap_rb.h

@@ -37,8 +37,6 @@
 /** Bitmap-organized raw block header data structure */
 typedef struct bitmap_rb_s {
     BMAP_EL_TYPE bmap_array[BMAP_INDEX_NUM];
-    BMAP_EL_TYPE bmap_array2[BMAP_INDEX_NUM];
-    BMAP_EL_TYPE bmap_array3[BMAP_INDEX_NUM];
     size_t bytes_per_cell; /* FIXME - As long as the bitmap arrays are
                               fixed-sized, this is also fixed */
 } bitmap_rb_t;

+ 15 - 15
src/bitmap/bitmap_malloc.c

@@ -42,6 +42,7 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
     bitmap_rb_t *rb_header;
     size_t cells, stop, i, found;
     void *ret;
+    BMAP_EL_TYPE temp1[BMAP_INDEX_NUM], temp2[BMAP_INDEX_NUM];
     BMAP_EL_TYPE mask1, mask2;
     chunk_header_t *chunk_address;
 
@@ -57,42 +58,41 @@ void * bitmap_malloc(raw_block_header_t *raw_block, size_t req_size) {
         cells = req_size / rb_header->bytes_per_cell;
     }
 
+    // perform bitwise shift & and operations in the BMAP_EL_TYPE arrays
+    stop = prev_pow2(cells);
+
 #ifdef HAVE_LOCKS
     pthread_mutex_lock(&raw_block->mutex);
 #endif /* HAVE_LOCKS */
 
-    // perform bitwise shift & and operations in the BMAP_EL_TYPE arrays
-    stop = prev_pow2(cells);
-
-    copy_array(rb_header->bmap_array2, rb_header->bmap_array);
+    copy_array(temp1, rb_header->bmap_array);
     for(i = 1; i < stop; i <<= 1) {
-        copy_array(rb_header->bmap_array3, rb_header->bmap_array2);
-        shift_array(rb_header->bmap_array3, i);
-        add_arrays(rb_header->bmap_array2, rb_header->bmap_array3);
+        copy_array(temp2, temp1);
+        shift_array(temp2, i);
+        add_arrays(temp1, temp2);
     }
     if(stop < cells) {
-        copy_array(rb_header->bmap_array3, rb_header->bmap_array2);
-        shift_array(rb_header->bmap_array3, cells - stop);
-        add_arrays(rb_header->bmap_array2, rb_header->bmap_array3);
+        copy_array(temp2, temp1);
+        shift_array(temp2, cells - stop);
+        add_arrays(temp1, temp2);
     }
 
     found = 0;
     ret = NULL;
 
     for(i = 0; i < BMAP_INDEX_NUM; ++i) {
-        found = __builtin_ffsl(rb_header->bmap_array2[i]);
+        found = __builtin_ffsl(temp1[i]);
         if(found) {
-            int ext = BMAP_EL_SIZE_BITS - found - (cells - 1);
-            if(ext >= 0) {
+            // Check if one or two elements have to be modified
+            if(found + (cells - 1) <= BMAP_EL_SIZE_BITS) {
                 mask1 = ~make_bit_mask(found, cells);
-                rb_header->bmap_array[i] &= mask1;
             } else {
                 mask1 = ~make_bit_mask(found, BMAP_EL_SIZE_BITS - found + 1);
                 mask2 = ~make_bit_mask((size_t) 1,
                         cells - (BMAP_EL_SIZE_BITS - found) - 1);
-                rb_header->bmap_array[i] &= mask1;
                 rb_header->bmap_array[i + 1] &= mask2;
             }
+                rb_header->bmap_array[i] &= mask1;
 
             // Calculate the pointer to the chunk to be retrieved
             chunk_address = (chunk_header_t *)((char *)rb_header + (i *