OSDN Git Service

btrfs: add more find_free_extent tracepoints
[tomoyo/tomoyo-test1.git] / fs / btrfs / extent-tree.c
index 72ba13b..203c8cb 100644 (file)
@@ -16,7 +16,8 @@
 #include <linux/percpu_counter.h>
 #include <linux/lockdep.h>
 #include <linux/crc32c.h>
 #include <linux/percpu_counter.h>
 #include <linux/lockdep.h>
 #include <linux/crc32c.h>
-#include "misc.h"
+#include "ctree.h"
+#include "extent-tree.h"
 #include "tree-log.h"
 #include "disk-io.h"
 #include "print-tree.h"
 #include "tree-log.h"
 #include "disk-io.h"
 #include "print-tree.h"
@@ -31,7 +32,6 @@
 #include "space-info.h"
 #include "block-rsv.h"
 #include "delalloc-space.h"
 #include "space-info.h"
 #include "block-rsv.h"
 #include "delalloc-space.h"
-#include "block-group.h"
 #include "discard.h"
 #include "rcu-string.h"
 #include "zoned.h"
 #include "discard.h"
 #include "rcu-string.h"
 #include "zoned.h"
@@ -1966,7 +1966,7 @@ static int btrfs_run_delayed_refs_for_head(struct btrfs_trans_handle *trans,
                cond_resched();
 
                spin_lock(&locked_ref->lock);
                cond_resched();
 
                spin_lock(&locked_ref->lock);
-               btrfs_merge_delayed_refs(trans, delayed_refs, locked_ref);
+               btrfs_merge_delayed_refs(fs_info, delayed_refs, locked_ref);
        }
 
        return 0;
        }
 
        return 0;
@@ -2013,7 +2013,7 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
                 * insert_inline_extent_backref()).
                 */
                spin_lock(&locked_ref->lock);
                 * insert_inline_extent_backref()).
                 */
                spin_lock(&locked_ref->lock);
-               btrfs_merge_delayed_refs(trans, delayed_refs, locked_ref);
+               btrfs_merge_delayed_refs(fs_info, delayed_refs, locked_ref);
 
                ret = btrfs_run_delayed_refs_for_head(trans, locked_ref,
                                                      &actual_count);
 
                ret = btrfs_run_delayed_refs_for_head(trans, locked_ref,
                                                      &actual_count);
@@ -3453,81 +3453,6 @@ btrfs_release_block_group(struct btrfs_block_group *cache,
        btrfs_put_block_group(cache);
 }
 
        btrfs_put_block_group(cache);
 }
 
-enum btrfs_extent_allocation_policy {
-       BTRFS_EXTENT_ALLOC_CLUSTERED,
-       BTRFS_EXTENT_ALLOC_ZONED,
-};
-
-/*
- * Structure used internally for find_free_extent() function.  Wraps needed
- * parameters.
- */
-struct find_free_extent_ctl {
-       /* Basic allocation info */
-       u64 ram_bytes;
-       u64 num_bytes;
-       u64 min_alloc_size;
-       u64 empty_size;
-       u64 flags;
-       int delalloc;
-
-       /* Where to start the search inside the bg */
-       u64 search_start;
-
-       /* For clustered allocation */
-       u64 empty_cluster;
-       struct btrfs_free_cluster *last_ptr;
-       bool use_cluster;
-
-       bool have_caching_bg;
-       bool orig_have_caching_bg;
-
-       /* Allocation is called for tree-log */
-       bool for_treelog;
-
-       /* Allocation is called for data relocation */
-       bool for_data_reloc;
-
-       /* RAID index, converted from flags */
-       int index;
-
-       /*
-        * Current loop number, check find_free_extent_update_loop() for details
-        */
-       int loop;
-
-       /*
-        * Whether we're refilling a cluster, if true we need to re-search
-        * current block group but don't try to refill the cluster again.
-        */
-       bool retry_clustered;
-
-       /*
-        * Whether we're updating free space cache, if true we need to re-search
-        * current block group but don't try updating free space cache again.
-        */
-       bool retry_unclustered;
-
-       /* If current block group is cached */
-       int cached;
-
-       /* Max contiguous hole found */
-       u64 max_extent_size;
-
-       /* Total free space from free space cache, not always contiguous */
-       u64 total_free_space;
-
-       /* Found result */
-       u64 found_offset;
-
-       /* Hint where to start looking for an empty space */
-       u64 hint_byte;
-
-       /* Allocation policy */
-       enum btrfs_extent_allocation_policy policy;
-};
-
-
 /*
  * Helper function for find_free_extent().
  *
 /*
  * Helper function for find_free_extent().
  *
@@ -3559,8 +3484,7 @@ static int find_free_extent_clustered(struct btrfs_block_group *bg,
        if (offset) {
                /* We have a block, we're done */
                spin_unlock(&last_ptr->refill_lock);
        if (offset) {
                /* We have a block, we're done */
                spin_unlock(&last_ptr->refill_lock);
-               trace_btrfs_reserve_extent_cluster(cluster_bg,
-                               ffe_ctl->search_start, ffe_ctl->num_bytes);
+               trace_btrfs_reserve_extent_cluster(cluster_bg, ffe_ctl);
                *cluster_bg_ret = cluster_bg;
                ffe_ctl->found_offset = offset;
                return 0;
                *cluster_bg_ret = cluster_bg;
                ffe_ctl->found_offset = offset;
                return 0;
@@ -3610,10 +3534,8 @@ refill_cluster:
                if (offset) {
                        /* We found one, proceed */
                        spin_unlock(&last_ptr->refill_lock);
                if (offset) {
                        /* We found one, proceed */
                        spin_unlock(&last_ptr->refill_lock);
-                       trace_btrfs_reserve_extent_cluster(bg,
-                                       ffe_ctl->search_start,
-                                       ffe_ctl->num_bytes);
                        ffe_ctl->found_offset = offset;
                        ffe_ctl->found_offset = offset;
+                       trace_btrfs_reserve_extent_cluster(bg, ffe_ctl);
                        return 0;
                }
        } else if (!ffe_ctl->cached && ffe_ctl->loop > LOOP_CACHING_NOWAIT &&
                        return 0;
                }
        } else if (!ffe_ctl->cached && ffe_ctl->loop > LOOP_CACHING_NOWAIT &&
@@ -4296,8 +4218,7 @@ static noinline int find_free_extent(struct btrfs_root *root,
        ins->objectid = 0;
        ins->offset = 0;
 
        ins->objectid = 0;
        ins->offset = 0;
 
-       trace_find_free_extent(root, ffe_ctl->num_bytes, ffe_ctl->empty_size,
-                              ffe_ctl->flags);
+       trace_find_free_extent(root, ffe_ctl);
 
        space_info = btrfs_find_space_info(fs_info, ffe_ctl->flags);
        if (!space_info) {
 
        space_info = btrfs_find_space_info(fs_info, ffe_ctl->flags);
        if (!space_info) {
@@ -4340,6 +4261,7 @@ static noinline int find_free_extent(struct btrfs_root *root,
                                                        block_group->flags);
                                btrfs_lock_block_group(block_group,
                                                       ffe_ctl->delalloc);
                                                        block_group->flags);
                                btrfs_lock_block_group(block_group,
                                                       ffe_ctl->delalloc);
+                               ffe_ctl->hinted = true;
                                goto have_block_group;
                        }
                } else if (block_group) {
                                goto have_block_group;
                        }
                } else if (block_group) {
@@ -4347,6 +4269,7 @@ static noinline int find_free_extent(struct btrfs_root *root,
                }
        }
 search:
                }
        }
 search:
+       trace_find_free_extent_search_loop(root, ffe_ctl);
        ffe_ctl->have_caching_bg = false;
        if (ffe_ctl->index == btrfs_bg_flags_to_raid_index(ffe_ctl->flags) ||
            ffe_ctl->index == 0)
        ffe_ctl->have_caching_bg = false;
        if (ffe_ctl->index == btrfs_bg_flags_to_raid_index(ffe_ctl->flags) ||
            ffe_ctl->index == 0)
@@ -4356,6 +4279,7 @@ search:
                            &space_info->block_groups[ffe_ctl->index], list) {
                struct btrfs_block_group *bg_ret;
 
                            &space_info->block_groups[ffe_ctl->index], list) {
                struct btrfs_block_group *bg_ret;
 
+               ffe_ctl->hinted = false;
                /* If the block group is read-only, we can skip it entirely. */
                if (unlikely(block_group->ro)) {
                        if (ffe_ctl->for_treelog)
                /* If the block group is read-only, we can skip it entirely. */
                if (unlikely(block_group->ro)) {
                        if (ffe_ctl->for_treelog)
@@ -4397,6 +4321,7 @@ search:
                }
 
 have_block_group:
                }
 
 have_block_group:
+               trace_find_free_extent_have_block_group(root, ffe_ctl, block_group);
                ffe_ctl->cached = btrfs_block_group_done(block_group);
                if (unlikely(!ffe_ctl->cached)) {
                        ffe_ctl->have_caching_bg = true;
                ffe_ctl->cached = btrfs_block_group_done(block_group);
                if (unlikely(!ffe_ctl->cached)) {
                        ffe_ctl->have_caching_bg = true;
@@ -4468,8 +4393,7 @@ have_block_group:
                ins->objectid = ffe_ctl->search_start;
                ins->offset = ffe_ctl->num_bytes;
 
                ins->objectid = ffe_ctl->search_start;
                ins->offset = ffe_ctl->num_bytes;
 
-               trace_btrfs_reserve_extent(block_group, ffe_ctl->search_start,
-                                          ffe_ctl->num_bytes);
+               trace_btrfs_reserve_extent(block_group, ffe_ctl);
                btrfs_release_block_group(block_group, ffe_ctl->delalloc);
                break;
 loop:
                btrfs_release_block_group(block_group, ffe_ctl->delalloc);
                break;
 loop: