Btrfs: Add data block hints to SSD mode too
authorChris Mason <chris.mason@oracle.com>
Thu, 31 Jan 2008 21:45:07 +0000 (16:45 -0500)
committerChris Mason <chris.mason@oracle.com>
Thu, 25 Sep 2008 15:04:00 +0000 (11:04 -0400)
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/transaction.c

index 8f93e066bf8b0422ae3eac557165550912d60ec5..35e9a7af10a509dc427a2bd32c9fe8b07f8328cb 100644 (file)
@@ -354,6 +354,7 @@ struct btrfs_fs_info {
        spinlock_t new_trans_lock;
        u64 delalloc_bytes;
        u64 last_alloc;
+       u64 last_data_alloc;
 };
 /*
  * in ram representation of the tree.  extent_root is used for all allocations
index ad72e2192015dd5003897f1c7a6bed706300f6d4..dda8ad6c0077899e7f41d76c0f3c0df5cbe10256 100644 (file)
@@ -688,6 +688,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
        fs_info->closing = 0;
        fs_info->total_pinned = 0;
        fs_info->last_alloc = 0;
+       fs_info->last_data_alloc = 0;
 
 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
        INIT_WORK(&fs_info->trans_work, btrfs_transaction_cleaner, fs_info);
index 90718f77bbc07cfa78452531e05b0226a3d42828..fa54ea5900781ff1cfc13d28205663cae743d57e 100644 (file)
@@ -1410,6 +1410,7 @@ static int noinline find_free_extent(struct btrfs_trans_handle *trans,
        int ret;
        int slot = 0;
        u64 last_byte = 0;
+       u64 *last_ptr = NULL;
        u64 orig_search_start = search_start;
        int start_found;
        struct extent_buffer *l;
@@ -1433,14 +1434,17 @@ static int noinline find_free_extent(struct btrfs_trans_handle *trans,
 
        /* for SSD, cluster allocations together as much as possible */
        if (btrfs_test_opt(root, SSD)) {
-               if (!data) {
-                       if (root->fs_info->last_alloc)
-                               hint_byte = root->fs_info->last_alloc;
-                       else {
-                               hint_byte = hint_byte &
-                                       ~((u64)BTRFS_BLOCK_GROUP_SIZE - 1);
-                               empty_size += 16 * 1024 * 1024;
-                       }
+               if (data)
+                       last_ptr = &root->fs_info->last_data_alloc;
+               else
+                       last_ptr = &root->fs_info->last_alloc;
+               if (*last_ptr) {
+                       hint_byte = *last_ptr;
+               }
+               else {
+                       hint_byte = hint_byte &
+                               ~((u64)BTRFS_BLOCK_GROUP_SIZE - 1);
+                       empty_size += 16 * 1024 * 1024;
                }
        }
 
@@ -1470,8 +1474,8 @@ check_failed:
        search_start = find_search_start(root, &block_group, search_start,
                                         total_needed, data);
 
-       if (!data && btrfs_test_opt(root, SSD) && info->last_alloc &&
-           search_start != info->last_alloc) {
+       if (btrfs_test_opt(root, SSD) && *last_ptr &&
+           search_start != *last_ptr) {
                info->last_alloc = 0;
                if (!empty_size) {
                        empty_size += 16 * 1024 * 1024;
@@ -1609,6 +1613,8 @@ check_pending:
        }
        ins->offset = num_bytes;
        btrfs_free_path(path);
+       if (btrfs_test_opt(root, SSD))
+               *last_ptr = ins->objectid + ins->offset;
        return 0;
 
 new_group:
@@ -1636,8 +1642,6 @@ enospc:
 error:
        btrfs_release_path(root, path);
        btrfs_free_path(path);
-       if (btrfs_test_opt(root, SSD) && !ret && !data)
-               info->last_alloc = ins->objectid + ins->offset;
        return ret;
 }
 /*
index b4a1bc62a784f04dadb609969596cbda40e15d0b..3f64d0c7ddb901cb886305c74adde4d8fad66ab2 100644 (file)
@@ -58,6 +58,7 @@ static int join_transaction(struct btrfs_root *root)
                root->fs_info->generation++;
                root->fs_info->running_transaction = cur_trans;
                root->fs_info->last_alloc = 0;
+               root->fs_info->last_data_alloc = 0;
                cur_trans->num_writers = 1;
                cur_trans->num_joined = 0;
                cur_trans->transid = root->fs_info->generation;