]> err.no Git - linux-2.6/blobdiff - fs/reiserfs/bitmap.c
Pull hp-pci-root into test branch
[linux-2.6] / fs / reiserfs / bitmap.c
index 44d9410e9d6a7bdc00c5ff1a707ce4a9ebe9d060..b286ccb085879172a6bac6f5055c14b4c3cd363a 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/buffer_head.h>
 #include <linux/kernel.h>
 #include <linux/pagemap.h>
+#include <linux/vmalloc.h>
 #include <linux/reiserfs_fs_sb.h>
 #include <linux/reiserfs_fs_i.h>
 #include <linux/quotaops.h>
@@ -59,7 +60,6 @@ static inline void get_bit_address(struct super_block *s,
 int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
 {
        int bmap, offset;
-       struct buffer_head *bh;
 
        if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
                reiserfs_warning(s,
@@ -97,22 +97,6 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
                return 0;
        }
 
-       bh = SB_AP_BITMAP(s)[bmap].bh;
-       get_bh(bh);
-
-       if ((bit_value == 0 && reiserfs_test_le_bit(offset, bh->b_data)) ||
-           (bit_value == 1 && reiserfs_test_le_bit(offset, bh->b_data) == 0)) {
-               reiserfs_warning(s,
-                                "vs-4040: is_reusable: corresponding bit of block %lu does not "
-                                "match required value (bmap==%d, offset==%d) test_bit==%d",
-                                block, bmap, offset,
-                                reiserfs_test_le_bit(offset, bh->b_data));
-
-               brelse(bh);
-               return 0;
-       }
-       brelse(bh);
-
        if (bit_value == 0 && block == SB_ROOT_BLOCK(s)) {
                reiserfs_warning(s,
                                 "vs-4050: is_reusable: this is root block (%u), "
@@ -172,13 +156,10 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
                                 bmap_n);
                return 0;
        }
-       bh = bi->bh;
-       get_bh(bh);
 
-       if (buffer_locked(bh)) {
-               PROC_INFO_INC(s, scan_bitmap.wait);
-               __wait_on_buffer(bh);
-       }
+       bh = reiserfs_read_bitmap_block(s, bmap_n);
+       if (bh == NULL)
+               return 0;
 
        while (1) {
              cont:
@@ -284,9 +265,20 @@ static int bmap_hash_id(struct super_block *s, u32 id)
  */
 static inline int block_group_used(struct super_block *s, u32 id)
 {
-       int bm;
-       bm = bmap_hash_id(s, id);
-       if (SB_AP_BITMAP(s)[bm].free_count > ((s->s_blocksize << 3) * 60 / 100)) {
+       int bm = bmap_hash_id(s, id);
+       struct reiserfs_bitmap_info *info = &SB_AP_BITMAP(s)[bm];
+
+       /* If we don't have cached information on this bitmap block, we're
+        * going to have to load it later anyway. Loading it here allows us
+        * to make a better decision. This favors long-term performace gain
+        * with a better on-disk layout vs. a short term gain of skipping the
+        * read and potentially having a bad placement. */
+       if (info->first_zero_hint == 0) {
+               struct buffer_head *bh = reiserfs_read_bitmap_block(s, bm);
+               brelse(bh);
+       }
+
+       if (info->free_count > ((s->s_blocksize << 3) * 60 / 100)) {
                return 0;
        }
        return 1;
@@ -412,8 +404,9 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
                return;
        }
 
-       bmbh = apbi[nr].bh;
-       get_bh(bmbh);
+       bmbh = reiserfs_read_bitmap_block(s, nr);
+       if (!bmbh)
+               return;
 
        reiserfs_prepare_for_journal(s, bmbh, 1);
 
@@ -715,7 +708,7 @@ static void oid_groups(reiserfs_blocknr_hint_t * hint)
  */
 static int get_left_neighbor(reiserfs_blocknr_hint_t * hint)
 {
-       struct path *path;
+       struct treepath *path;
        struct buffer_head *bh;
        struct item_head *ih;
        int pos_in_item;
@@ -1041,7 +1034,6 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
        b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
        int passno = 0;
        int nr_allocated = 0;
-       int bigalloc = 0;
 
        determine_prealloc_size(hint);
        if (!hint->formatted_node) {
@@ -1068,28 +1060,9 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
                                hint->preallocate = hint->prealloc_size = 0;
                }
                /* for unformatted nodes, force large allocations */
-               bigalloc = amount_needed;
        }
 
        do {
-               /* in bigalloc mode, nr_allocated should stay zero until
-                * the entire allocation is filled
-                */
-               if (unlikely(bigalloc && nr_allocated)) {
-                       reiserfs_warning(s, "bigalloc is %d, nr_allocated %d\n",
-                                        bigalloc, nr_allocated);
-                       /* reset things to a sane value */
-                       bigalloc = amount_needed - nr_allocated;
-               }
-               /*
-                * try pass 0 and pass 1 looking for a nice big
-                * contiguous allocation.  Then reset and look
-                * for anything you can find.
-                */
-               if (passno == 2 && bigalloc) {
-                       passno = 0;
-                       bigalloc = 0;
-               }
                switch (passno++) {
                case 0: /* Search from hint->search_start to end of disk */
                        start = hint->search_start;
@@ -1127,8 +1100,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
                                                                 new_blocknrs +
                                                                 nr_allocated,
                                                                 start, finish,
-                                                                bigalloc ?
-                                                                bigalloc : 1,
+                                                                1,
                                                                 amount_needed -
                                                                 nr_allocated,
                                                                 hint->
@@ -1285,3 +1257,89 @@ int reiserfs_can_fit_pages(struct super_block *sb        /* superblock of filesystem
 
        return space > 0 ? space : 0;
 }
+
+void reiserfs_cache_bitmap_metadata(struct super_block *sb,
+                                    struct buffer_head *bh,
+                                    struct reiserfs_bitmap_info *info)
+{
+       unsigned long *cur = (unsigned long *)(bh->b_data + bh->b_size);
+
+       info->first_zero_hint = 1 << (sb->s_blocksize_bits + 3);
+
+       while (--cur >= (unsigned long *)bh->b_data) {
+               int base = ((char *)cur - bh->b_data) << 3;
+
+               /* 0 and ~0 are special, we can optimize for them */
+               if (*cur == 0) {
+                       info->first_zero_hint = base;
+                       info->free_count += BITS_PER_LONG;
+               } else if (*cur != ~0L) {       /* A mix, investigate */
+                       int b;
+                       for (b = BITS_PER_LONG - 1; b >= 0; b--) {
+                               if (!reiserfs_test_le_bit(b, cur)) {
+                                       info->first_zero_hint = base + b;
+                                       info->free_count++;
+                               }
+                       }
+               }
+       }
+       /* The first bit must ALWAYS be 1 */
+       BUG_ON(info->first_zero_hint == 0);
+}
+
+struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb,
+                                               unsigned int bitmap)
+{
+       b_blocknr_t block = (sb->s_blocksize << 3) * bitmap;
+       struct reiserfs_bitmap_info *info = SB_AP_BITMAP(sb) + bitmap;
+       struct buffer_head *bh;
+
+       /* Way old format filesystems had the bitmaps packed up front.
+        * I doubt there are any of these left, but just in case... */
+       if (unlikely(test_bit(REISERFS_OLD_FORMAT,
+                             &(REISERFS_SB(sb)->s_properties))))
+               block = REISERFS_SB(sb)->s_sbh->b_blocknr + 1 + bitmap;
+       else if (bitmap == 0)
+               block = (REISERFS_DISK_OFFSET_IN_BYTES >> sb->s_blocksize_bits) + 1;
+
+       bh = sb_bread(sb, block);
+       if (bh == NULL)
+               reiserfs_warning(sb, "sh-2029: %s: bitmap block (#%u) "
+                                "reading failed", __FUNCTION__, block);
+       else {
+               if (buffer_locked(bh)) {
+                       PROC_INFO_INC(sb, scan_bitmap.wait);
+                       __wait_on_buffer(bh);
+               }
+               BUG_ON(!buffer_uptodate(bh));
+               BUG_ON(atomic_read(&bh->b_count) == 0);
+
+               if (info->first_zero_hint == 0)
+                       reiserfs_cache_bitmap_metadata(sb, bh, info);
+       }
+
+       return bh;
+}
+
+int reiserfs_init_bitmap_cache(struct super_block *sb)
+{
+       struct reiserfs_bitmap_info *bitmap;
+
+       bitmap = vmalloc(sizeof (*bitmap) * SB_BMAP_NR(sb));
+       if (bitmap == NULL)
+               return -ENOMEM;
+
+       memset(bitmap, 0, sizeof (*bitmap) * SB_BMAP_NR(sb));
+
+       SB_AP_BITMAP(sb) = bitmap;
+
+       return 0;
+}
+
+void reiserfs_free_bitmap_cache(struct super_block *sb)
+{
+       if (SB_AP_BITMAP(sb)) {
+               vfree(SB_AP_BITMAP(sb));
+               SB_AP_BITMAP(sb) = NULL;
+       }
+}