Commit d00aff00 authored by Chris Mason's avatar Chris Mason

Btrfs: Optimize tree log block allocations

Since tree log blocks get freed every transaction, they never really
need to be written to disk.  This skips the step where we update
metadata to record they were allocated.
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 3a5f1d45
...@@ -829,9 +829,8 @@ int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans, ...@@ -829,9 +829,8 @@ int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
WARN_ON(btrfs_header_level(eb) != 0); WARN_ON(btrfs_header_level(eb) != 0);
WARN_ON(btrfs_header_nritems(eb) != 0); WARN_ON(btrfs_header_nritems(eb) != 0);
ret = btrfs_free_extent(trans, fs_info->tree_root, ret = btrfs_free_reserved_extent(fs_info->tree_root,
eb->start, eb->len, eb->start, eb->len);
BTRFS_TREE_LOG_OBJECTID, 0, 0, 0, 1);
BUG_ON(ret); BUG_ON(ret);
free_extent_buffer(eb); free_extent_buffer(eb);
......
...@@ -1872,8 +1872,15 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans, ...@@ -1872,8 +1872,15 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
return 0; return 0;
} }
/* if metadata always pin */ /* if metadata always pin */
if (owner_objectid < BTRFS_FIRST_FREE_OBJECTID) if (owner_objectid < BTRFS_FIRST_FREE_OBJECTID) {
if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) {
/* btrfs_free_reserved_extent */
set_extent_dirty(&root->fs_info->free_space_cache,
bytenr, bytenr + num_bytes - 1, GFP_NOFS);
return 0;
}
pin = 1; pin = 1;
}
/* if data pin when any transaction has committed this */ /* if data pin when any transaction has committed this */
if (ref_generation != trans->transid) if (ref_generation != trans->transid)
...@@ -2361,11 +2368,13 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans, ...@@ -2361,11 +2368,13 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
min_alloc_size, empty_size, hint_byte, min_alloc_size, empty_size, hint_byte,
search_end, ins, data); search_end, ins, data);
BUG_ON(ret); BUG_ON(ret);
if (root_objectid != BTRFS_TREE_LOG_OBJECTID) {
ret = __btrfs_alloc_reserved_extent(trans, root, root_objectid, ret = __btrfs_alloc_reserved_extent(trans, root, root_objectid,
ref_generation, owner, ref_generation, owner,
owner_offset, ins); owner_offset, ins);
BUG_ON(ret); BUG_ON(ret);
}
maybe_unlock_mutex(root); maybe_unlock_mutex(root);
return ret; return ret;
} }
......
...@@ -1728,9 +1728,8 @@ static int noinline walk_down_log_tree(struct btrfs_trans_handle *trans, ...@@ -1728,9 +1728,8 @@ static int noinline walk_down_log_tree(struct btrfs_trans_handle *trans,
WARN_ON(root_owner != WARN_ON(root_owner !=
BTRFS_TREE_LOG_OBJECTID); BTRFS_TREE_LOG_OBJECTID);
ret = btrfs_free_extent(trans, root, bytenr, ret = btrfs_free_reserved_extent(root,
blocksize, root_owner, bytenr, blocksize);
root_gen, 0, 0, 1);
BUG_ON(ret); BUG_ON(ret);
} }
free_extent_buffer(next); free_extent_buffer(next);
...@@ -1775,8 +1774,7 @@ static int noinline walk_down_log_tree(struct btrfs_trans_handle *trans, ...@@ -1775,8 +1774,7 @@ static int noinline walk_down_log_tree(struct btrfs_trans_handle *trans,
BUG_ON(ret); BUG_ON(ret);
} }
WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID); WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID);
ret = btrfs_free_extent(trans, root, bytenr, blocksize, ret = btrfs_free_reserved_extent(root, bytenr, blocksize);
root_owner, root_gen, 0, 0, 1);
BUG_ON(ret); BUG_ON(ret);
} }
free_extent_buffer(path->nodes[*level]); free_extent_buffer(path->nodes[*level]);
...@@ -1837,10 +1835,9 @@ static int noinline walk_up_log_tree(struct btrfs_trans_handle *trans, ...@@ -1837,10 +1835,9 @@ static int noinline walk_up_log_tree(struct btrfs_trans_handle *trans,
} }
WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID); WARN_ON(root_owner != BTRFS_TREE_LOG_OBJECTID);
ret = btrfs_free_extent(trans, root, ret = btrfs_free_reserved_extent(root,
path->nodes[*level]->start, path->nodes[*level]->start,
path->nodes[*level]->len, path->nodes[*level]->len);
root_owner, root_gen, 0, 0, 1);
BUG_ON(ret); BUG_ON(ret);
} }
free_extent_buffer(path->nodes[*level]); free_extent_buffer(path->nodes[*level]);
...@@ -1910,11 +1907,8 @@ static int walk_log_tree(struct btrfs_trans_handle *trans, ...@@ -1910,11 +1907,8 @@ static int walk_log_tree(struct btrfs_trans_handle *trans,
} }
WARN_ON(log->root_key.objectid != WARN_ON(log->root_key.objectid !=
BTRFS_TREE_LOG_OBJECTID); BTRFS_TREE_LOG_OBJECTID);
ret = btrfs_free_extent(trans, log, ret = btrfs_free_reserved_extent(log, next->start,
next->start, next->len, next->len);
log->root_key.objectid,
btrfs_header_generation(next),
0, 0, 1);
BUG_ON(ret); BUG_ON(ret);
} }
} }
......
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