]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
md/bitmap: optimise scanning of empty bitmaps.
authorNeilBrown <neilb@suse.de>
Tue, 1 Jun 2010 09:37:33 +0000 (19:37 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 26 Jul 2010 03:21:32 +0000 (13:21 +1000)
A bitmap is stored as one page per 2048 bits.
If none of the bits are set, the page is not allocated.

When bitmap_get_counter finds that a page isn't allocate,
it just reports that one bit work of space isn't flagged,
rather than reporting that 2048 bits worth of space are
unflagged.
This can cause searches for flagged bits (e.g. bitmap_close_sync)
to do more work than is really necessary.

So change bitmap_get_counter (when creating) to report a number of
blocks that more accurately reports the range of the device for which
no counter currently exists.

Signed-off-by: NeilBrown <neilb@suse.de>
drivers/md/bitmap.c

index 3f04699725db4de742d55bde8342fb2b6e7523c8..29a3c864e6b0601b1102e8cf626696320f66e0b4 100644 (file)
@@ -1235,29 +1235,32 @@ __acquires(bitmap->lock)
        unsigned long page = chunk >> PAGE_COUNTER_SHIFT;
        unsigned long pageoff = (chunk & PAGE_COUNTER_MASK) << COUNTER_BYTE_SHIFT;
        sector_t csize;
+       int err;
+
+       err = bitmap_checkpage(bitmap, page, create);
 
-       if (bitmap_checkpage(bitmap, page, create) < 0) {
+       if (bitmap->bp[page].hijacked ||
+           bitmap->bp[page].map == NULL)
+               csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap) +
+                                         PAGE_COUNTER_SHIFT - 1);
+       else
                csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap));
-               *blocks = csize - (offset & (csize - 1));
+       *blocks = csize - (offset & (csize - 1));
+
+       if (err < 0)
                return NULL;
-       }
+
        /* now locked ... */
 
        if (bitmap->bp[page].hijacked) { /* hijacked pointer */
                /* should we use the first or second counter field
                 * of the hijacked pointer? */
                int hi = (pageoff > PAGE_COUNTER_MASK);
-               csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap) +
-                                         PAGE_COUNTER_SHIFT - 1);
-               *blocks = csize - (offset & (csize - 1));
                return  &((bitmap_counter_t *)
                          &bitmap->bp[page].map)[hi];
-       } else { /* page is allocated */
-               csize = ((sector_t)1) << (CHUNK_BLOCK_SHIFT(bitmap));
-               *blocks = csize - (offset & (csize - 1));
+       } else /* page is allocated */
                return (bitmap_counter_t *)
                        &(bitmap->bp[page].map[pageoff]);
-       }
 }
 
 int bitmap_startwrite(struct bitmap *bitmap, sector_t offset, unsigned long sectors, int behind)