Btrfs: Add mount -o ssd, which includes optimizations for seek free storage
authorChris Mason <chris.mason@oracle.com>
Fri, 18 Jan 2008 15:54:22 +0000 (10:54 -0500)
committerChris Mason <chris.mason@oracle.com>
Thu, 25 Sep 2008 15:03:59 +0000 (11:03 -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/super.c
fs/btrfs/transaction.c
fs/btrfs/tree-defrag.c

index fa65fe027e45ec205c73d99f62f21dde1d9fde32..7a588ba2b74750432f813783590906ea54042b8b 100644 (file)
@@ -351,6 +351,7 @@ struct btrfs_fs_info {
        spinlock_t delalloc_lock;
        spinlock_t new_trans_lock;
        u64 delalloc_bytes;
+       u64 last_alloc;
 };
 /*
  * in ram representation of the tree.  extent_root is used for all allocations
@@ -444,6 +445,7 @@ struct btrfs_root {
 #define BTRFS_MOUNT_NODATASUM          (1 << 0)
 #define BTRFS_MOUNT_NODATACOW          (1 << 1)
 #define BTRFS_MOUNT_NOBARRIER          (1 << 2)
+#define BTRFS_MOUNT_SSD                        (1 << 3)
 
 #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
 #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
index 731a534f81f561de58c6fdd97d14448b2ac8f9d6..5d1f9bca271232d95e36b2e81b4e57f8cdc6d934 100644 (file)
@@ -193,6 +193,7 @@ int csum_dirty_buffer(struct btrfs_root *root, struct page *page)
        }
        eb = alloc_extent_buffer(tree, start, len, page, GFP_NOFS);
        read_extent_buffer_pages(tree, eb, start + PAGE_CACHE_SIZE, 1);
+       btrfs_clear_buffer_defrag(eb);
        found_start = btrfs_header_bytenr(eb);
        if (found_start != start) {
                printk("warning: eb start incorrect %Lu buffer %Lu len %lu\n",
@@ -676,6 +677,8 @@ struct btrfs_root *open_ctree(struct super_block *sb)
        fs_info->do_barriers = 1;
        fs_info->closing = 0;
        fs_info->total_pinned = 0;
+       fs_info->last_alloc = 0;
+
 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18)
        INIT_WORK(&fs_info->trans_work, btrfs_transaction_cleaner, fs_info);
 #else
index 2c569b4d59d44a8eb9b2e85603bf8a68b8821a04..b69a46691a96ccea19017017edfc3da63a9e62a3 100644 (file)
@@ -1431,6 +1431,19 @@ static int noinline find_free_extent(struct btrfs_trans_handle *trans,
                data = BTRFS_BLOCK_GROUP_MIXED;
        }
 
+       /* 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;
+                       }
+               }
+       }
+
        search_end = min(search_end,
                         btrfs_super_total_bytes(&info->super_copy));
        if (hint_byte) {
@@ -1456,6 +1469,19 @@ 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) {
+               info->last_alloc = 0;
+               if (!empty_size) {
+                       empty_size += 16 * 1024 * 1024;
+                       total_needed += empty_size;
+               }
+               search_start = find_search_start(root, &block_group,
+                                                search_start, total_needed,
+                                                data);
+       }
+
        search_start = stripe_align(root, search_start);
        cached_start = search_start;
        btrfs_init_path(path);
@@ -1610,6 +1636,8 @@ 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;
 }
 /*
@@ -1778,7 +1806,8 @@ struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
                        buf->start, buf->start + buf->len - 1,
                        EXTENT_CSUM, GFP_NOFS);
        buf->flags |= EXTENT_CSUM;
-       btrfs_set_buffer_defrag(buf);
+       if (!btrfs_test_opt(root, SSD))
+               btrfs_set_buffer_defrag(buf);
        trans->blocks_used++;
        return buf;
 }
index e506de3168bc5610569fae6c5c1589a3b30ea626..b6982f0133cfbf8ddb966164044f69230fe97f8d 100644 (file)
@@ -64,7 +64,7 @@ static void btrfs_put_super (struct super_block * sb)
 
 enum {
        Opt_subvol, Opt_nodatasum, Opt_nodatacow, Opt_max_extent,
-       Opt_alloc_start, Opt_nobarrier, Opt_err,
+       Opt_alloc_start, Opt_nobarrier, Opt_ssd, Opt_err,
 };
 
 static match_table_t tokens = {
@@ -74,6 +74,7 @@ static match_table_t tokens = {
        {Opt_nobarrier, "nobarrier"},
        {Opt_max_extent, "max_extent=%s"},
        {Opt_alloc_start, "alloc_start=%s"},
+       {Opt_ssd, "ssd"},
        {Opt_err, NULL}
 };
 
@@ -149,6 +150,12 @@ static int parse_options (char * options,
                                btrfs_set_opt(info->mount_opt, NODATASUM);
                        }
                        break;
+               case Opt_ssd:
+                       if (info) {
+                               printk("btrfs: use ssd allocation scheme\n");
+                               btrfs_set_opt(info->mount_opt, SSD);
+                       }
+                       break;
                case Opt_nobarrier:
                        if (info) {
                                printk("btrfs: turning off barriers\n");
index b6bbfc179c29e151f846a8b19cfcb4ad3c7229cc..163c01a244982977ac44745e3366a974888ff72b 100644 (file)
@@ -57,6 +57,7 @@ static int join_transaction(struct btrfs_root *root)
                BUG_ON(!cur_trans);
                root->fs_info->generation++;
                root->fs_info->running_transaction = cur_trans;
+               root->fs_info->last_alloc = 0;
                cur_trans->num_writers = 1;
                cur_trans->num_joined = 0;
                cur_trans->transid = root->fs_info->generation;
index 5c58630dce03e12800e2c3cf52575d65e8d8c96a..5935cbd8f2b83c7646c17f2823d36746b3151be1 100644 (file)
@@ -179,6 +179,9 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
        if (root->ref_cows == 0 && !is_extent)
                goto out;
 
+       if (btrfs_test_opt(root, SSD))
+               goto out;
+
        path = btrfs_alloc_path();
        if (!path)
                return -ENOMEM;