Commit 3f7de037 authored by Josef Bacik's avatar Josef Bacik Committed by Chris Mason

Btrfs: add allocator tracepoints

I used these tracepoints when figuring out what the cluster stuff was doing, so
add them to mainline in case we need to profile this stuff again.  Thanks,
Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
parent 45a8090e
...@@ -5256,6 +5256,8 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, ...@@ -5256,6 +5256,8 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,
ins->objectid = 0; ins->objectid = 0;
ins->offset = 0; ins->offset = 0;
trace_find_free_extent(orig_root, num_bytes, empty_size, data);
space_info = __find_space_info(root->fs_info, data); space_info = __find_space_info(root->fs_info, data);
if (!space_info) { if (!space_info) {
printk(KERN_ERR "No space info for %llu\n", data); printk(KERN_ERR "No space info for %llu\n", data);
...@@ -5432,6 +5434,8 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, ...@@ -5432,6 +5434,8 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,
if (offset) { if (offset) {
/* we have a block, we're done */ /* we have a block, we're done */
spin_unlock(&last_ptr->refill_lock); spin_unlock(&last_ptr->refill_lock);
trace_btrfs_reserve_extent_cluster(root,
block_group, search_start, num_bytes);
goto checks; goto checks;
} }
...@@ -5490,6 +5494,9 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, ...@@ -5490,6 +5494,9 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,
if (offset) { if (offset) {
/* we found one, proceed */ /* we found one, proceed */
spin_unlock(&last_ptr->refill_lock); spin_unlock(&last_ptr->refill_lock);
trace_btrfs_reserve_extent_cluster(root,
block_group, search_start,
num_bytes);
goto checks; goto checks;
} }
} else if (!cached && loop > LOOP_CACHING_NOWAIT } else if (!cached && loop > LOOP_CACHING_NOWAIT
...@@ -5576,6 +5583,8 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, ...@@ -5576,6 +5583,8 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans,
ins->objectid = search_start; ins->objectid = search_start;
ins->offset = num_bytes; ins->offset = num_bytes;
trace_btrfs_reserve_extent(orig_root, block_group,
search_start, num_bytes);
if (offset < search_start) if (offset < search_start)
btrfs_add_free_space(used_block_group, offset, btrfs_add_free_space(used_block_group, offset,
search_start - offset); search_start - offset);
......
...@@ -2346,6 +2346,8 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group, ...@@ -2346,6 +2346,8 @@ static int btrfs_bitmap_cluster(struct btrfs_block_group_cache *block_group,
&entry->offset_index, 1); &entry->offset_index, 1);
BUG_ON(ret); BUG_ON(ret);
trace_btrfs_setup_cluster(block_group, cluster,
total_found * block_group->sectorsize, 1);
return 0; return 0;
} }
...@@ -2368,6 +2370,7 @@ setup_cluster_no_bitmap(struct btrfs_block_group_cache *block_group, ...@@ -2368,6 +2370,7 @@ setup_cluster_no_bitmap(struct btrfs_block_group_cache *block_group,
u64 window_start; u64 window_start;
u64 window_free; u64 window_free;
u64 max_extent; u64 max_extent;
u64 total_size = 0;
entry = tree_search_offset(ctl, offset, 0, 1); entry = tree_search_offset(ctl, offset, 0, 1);
if (!entry) if (!entry)
...@@ -2433,11 +2436,12 @@ setup_cluster_no_bitmap(struct btrfs_block_group_cache *block_group, ...@@ -2433,11 +2436,12 @@ setup_cluster_no_bitmap(struct btrfs_block_group_cache *block_group,
rb_erase(&entry->offset_index, &ctl->free_space_offset); rb_erase(&entry->offset_index, &ctl->free_space_offset);
ret = tree_insert_offset(&cluster->root, entry->offset, ret = tree_insert_offset(&cluster->root, entry->offset,
&entry->offset_index, 0); &entry->offset_index, 0);
total_size += entry->bytes;
BUG_ON(ret); BUG_ON(ret);
} while (node && entry != last); } while (node && entry != last);
cluster->max_size = max_extent; cluster->max_size = max_extent;
trace_btrfs_setup_cluster(block_group, cluster, total_size, 0);
return 0; return 0;
} }
...@@ -2542,6 +2546,10 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans, ...@@ -2542,6 +2546,10 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
goto out; goto out;
} }
trace_btrfs_find_cluster(block_group, offset, bytes, empty_size,
min_bytes);
INIT_LIST_HEAD(&bitmaps);
ret = setup_cluster_no_bitmap(block_group, cluster, &bitmaps, offset, ret = setup_cluster_no_bitmap(block_group, cluster, &bitmaps, offset,
bytes + empty_size, bytes + empty_size,
cont1_bytes, min_bytes); cont1_bytes, min_bytes);
...@@ -2559,6 +2567,8 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans, ...@@ -2559,6 +2567,8 @@ int btrfs_find_space_cluster(struct btrfs_trans_handle *trans,
list_add_tail(&cluster->block_group_list, list_add_tail(&cluster->block_group_list,
&block_group->cluster_list); &block_group->cluster_list);
cluster->block_group = block_group; cluster->block_group = block_group;
} else {
trace_btrfs_failed_cluster_setup(block_group);
} }
out: out:
spin_unlock(&cluster->lock); spin_unlock(&cluster->lock);
......
...@@ -16,6 +16,8 @@ struct btrfs_delayed_ref_node; ...@@ -16,6 +16,8 @@ struct btrfs_delayed_ref_node;
struct btrfs_delayed_tree_ref; struct btrfs_delayed_tree_ref;
struct btrfs_delayed_data_ref; struct btrfs_delayed_data_ref;
struct btrfs_delayed_ref_head; struct btrfs_delayed_ref_head;
struct btrfs_block_group_cache;
struct btrfs_free_cluster;
struct map_lookup; struct map_lookup;
struct extent_buffer; struct extent_buffer;
...@@ -44,6 +46,15 @@ struct extent_buffer; ...@@ -44,6 +46,15 @@ struct extent_buffer;
obj, ((obj >= BTRFS_DATA_RELOC_TREE_OBJECTID) || \ obj, ((obj >= BTRFS_DATA_RELOC_TREE_OBJECTID) || \
(obj <= BTRFS_CSUM_TREE_OBJECTID )) ? __show_root_type(obj) : "-" (obj <= BTRFS_CSUM_TREE_OBJECTID )) ? __show_root_type(obj) : "-"
#define BTRFS_GROUP_FLAGS \
{ BTRFS_BLOCK_GROUP_DATA, "DATA"}, \
{ BTRFS_BLOCK_GROUP_SYSTEM, "SYSTEM"}, \
{ BTRFS_BLOCK_GROUP_METADATA, "METADATA"}, \
{ BTRFS_BLOCK_GROUP_RAID0, "RAID0"}, \
{ BTRFS_BLOCK_GROUP_RAID1, "RAID1"}, \
{ BTRFS_BLOCK_GROUP_DUP, "DUP"}, \
{ BTRFS_BLOCK_GROUP_RAID10, "RAID10"}
TRACE_EVENT(btrfs_transaction_commit, TRACE_EVENT(btrfs_transaction_commit,
TP_PROTO(struct btrfs_root *root), TP_PROTO(struct btrfs_root *root),
...@@ -659,6 +670,168 @@ DEFINE_EVENT(btrfs__reserved_extent, btrfs_reserved_extent_free, ...@@ -659,6 +670,168 @@ DEFINE_EVENT(btrfs__reserved_extent, btrfs_reserved_extent_free,
TP_ARGS(root, start, len) TP_ARGS(root, start, len)
); );
TRACE_EVENT(find_free_extent,
TP_PROTO(struct btrfs_root *root, u64 num_bytes, u64 empty_size,
u64 data),
TP_ARGS(root, num_bytes, empty_size, data),
TP_STRUCT__entry(
__field( u64, root_objectid )
__field( u64, num_bytes )
__field( u64, empty_size )
__field( u64, data )
),
TP_fast_assign(
__entry->root_objectid = root->root_key.objectid;
__entry->num_bytes = num_bytes;
__entry->empty_size = empty_size;
__entry->data = data;
),
TP_printk("root = %Lu(%s), len = %Lu, empty_size = %Lu, "
"flags = %Lu(%s)", show_root_type(__entry->root_objectid),
__entry->num_bytes, __entry->empty_size, __entry->data,
__print_flags((unsigned long)__entry->data, "|",
BTRFS_GROUP_FLAGS))
);
DECLARE_EVENT_CLASS(btrfs__reserve_extent,
TP_PROTO(struct btrfs_root *root,
struct btrfs_block_group_cache *block_group, u64 start,
u64 len),
TP_ARGS(root, block_group, start, len),
TP_STRUCT__entry(
__field( u64, root_objectid )
__field( u64, bg_objectid )
__field( u64, flags )
__field( u64, start )
__field( u64, len )
),
TP_fast_assign(
__entry->root_objectid = root->root_key.objectid;
__entry->bg_objectid = block_group->key.objectid;
__entry->flags = block_group->flags;
__entry->start = start;
__entry->len = len;
),
TP_printk("root = %Lu(%s), block_group = %Lu, flags = %Lu(%s), "
"start = %Lu, len = %Lu",
show_root_type(__entry->root_objectid), __entry->bg_objectid,
__entry->flags, __print_flags((unsigned long)__entry->flags,
"|", BTRFS_GROUP_FLAGS),
__entry->start, __entry->len)
);
DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent,
TP_PROTO(struct btrfs_root *root,
struct btrfs_block_group_cache *block_group, u64 start,
u64 len),
TP_ARGS(root, block_group, start, len)
);
DEFINE_EVENT(btrfs__reserve_extent, btrfs_reserve_extent_cluster,
TP_PROTO(struct btrfs_root *root,
struct btrfs_block_group_cache *block_group, u64 start,
u64 len),
TP_ARGS(root, block_group, start, len)
);
TRACE_EVENT(btrfs_find_cluster,
TP_PROTO(struct btrfs_block_group_cache *block_group, u64 start,
u64 bytes, u64 empty_size, u64 min_bytes),
TP_ARGS(block_group, start, bytes, empty_size, min_bytes),
TP_STRUCT__entry(
__field( u64, bg_objectid )
__field( u64, flags )
__field( u64, start )
__field( u64, bytes )
__field( u64, empty_size )
__field( u64, min_bytes )
),
TP_fast_assign(
__entry->bg_objectid = block_group->key.objectid;
__entry->flags = block_group->flags;
__entry->start = start;
__entry->bytes = bytes;
__entry->empty_size = empty_size;
__entry->min_bytes = min_bytes;
),
TP_printk("block_group = %Lu, flags = %Lu(%s), start = %Lu, len = %Lu,"
" empty_size = %Lu, min_bytes = %Lu", __entry->bg_objectid,
__entry->flags,
__print_flags((unsigned long)__entry->flags, "|",
BTRFS_GROUP_FLAGS), __entry->start,
__entry->bytes, __entry->empty_size, __entry->min_bytes)
);
TRACE_EVENT(btrfs_failed_cluster_setup,
TP_PROTO(struct btrfs_block_group_cache *block_group),
TP_ARGS(block_group),
TP_STRUCT__entry(
__field( u64, bg_objectid )
),
TP_fast_assign(
__entry->bg_objectid = block_group->key.objectid;
),
TP_printk("block_group = %Lu", __entry->bg_objectid)
);
TRACE_EVENT(btrfs_setup_cluster,
TP_PROTO(struct btrfs_block_group_cache *block_group,
struct btrfs_free_cluster *cluster, u64 size, int bitmap),
TP_ARGS(block_group, cluster, size, bitmap),
TP_STRUCT__entry(
__field( u64, bg_objectid )
__field( u64, flags )
__field( u64, start )
__field( u64, max_size )
__field( u64, size )
__field( int, bitmap )
),
TP_fast_assign(
__entry->bg_objectid = block_group->key.objectid;
__entry->flags = block_group->flags;
__entry->start = cluster->window_start;
__entry->max_size = cluster->max_size;
__entry->size = size;
__entry->bitmap = bitmap;
),
TP_printk("block_group = %Lu, flags = %Lu(%s), window_start = %Lu, "
"size = %Lu, max_size = %Lu, bitmap = %d",
__entry->bg_objectid,
__entry->flags,
__print_flags((unsigned long)__entry->flags, "|",
BTRFS_GROUP_FLAGS), __entry->start,
__entry->size, __entry->max_size, __entry->bitmap)
);
#endif /* _TRACE_BTRFS_H */ #endif /* _TRACE_BTRFS_H */
/* This part must be outside protection */ /* This part must be outside protection */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment