From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v3 7/7] btrfs: qgroup: Only trace data extents in leaves if we're relocating data block group
Date: Tue, 11 Sep 2018 13:38:18 +0800 [thread overview]
Message-ID: <20180911053818.10191-8-wqu@suse.com> (raw)
In-Reply-To: <20180911053818.10191-1-wqu@suse.com>
For qgroup_trace_extent_swap(), if we find one leaf needs to be traced,
btrfs will also iterate all file extents and trace them.
This is OK if we're relocating data block groups, but if we're
relocating metadata block groups, balance code itself has ensured that
both subtree of file tree and reloc tree contain the same contents.
That's to say, if we're relocating metadata block groups, all file
extents in reloc and file tree should match, thus no need to trace them.
This should reduce the total number of dirty extents processed in metadata
block group balance.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/qgroup.c | 21 +++++++++++++++------
fs/btrfs/qgroup.h | 1 +
fs/btrfs/relocation.c | 10 +++++-----
3 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index a94027b2620e..f58350a37c2d 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -1725,7 +1725,8 @@ static int adjust_slots_upwards(struct btrfs_path *path, int root_level)
static int qgroup_trace_extent_swap(struct btrfs_trans_handle* trans,
struct extent_buffer *src_eb,
struct btrfs_path *dst_path,
- int dst_level, int root_level)
+ int dst_level, int root_level,
+ bool trace_leaf)
{
struct btrfs_key key;
struct btrfs_path *src_path;
@@ -1828,7 +1829,7 @@ static int qgroup_trace_extent_swap(struct btrfs_trans_handle* trans,
goto out;
/* Record leaf file extents */
- if (dst_level == 0) {
+ if (dst_level == 0 && trace_leaf) {
ret = btrfs_qgroup_trace_leaf_items(trans, src_path->nodes[0]);
if (ret < 0)
goto out;
@@ -1865,7 +1866,7 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans,
struct extent_buffer *src_eb,
struct btrfs_path *dst_path,
int cur_level, int root_level,
- u64 last_snapshot)
+ u64 last_snapshot, bool trace_leaf)
{
struct btrfs_fs_info *fs_info = trans->fs_info;
struct extent_buffer *eb;
@@ -1916,7 +1917,7 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans,
/* Now record this tree block and its counter part for qgroups */
ret = qgroup_trace_extent_swap(trans, src_eb, dst_path, cur_level,
- root_level);
+ root_level, trace_leaf);
if (ret < 0)
goto cleanup;
@@ -1933,7 +1934,7 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans,
/* Recursive call (at most 7 times) */
ret = qgroup_trace_new_subtree_blocks(trans, src_eb,
dst_path, cur_level - 1, root_level,
- last_snapshot);
+ last_snapshot, trace_leaf);
if (ret < 0)
goto cleanup;
}
@@ -1969,6 +1970,7 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans,
* @dst_parent, @dst_slot: pointer to dst (tree reloc tree) eb.
*/
int btrfs_qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans,
+ struct btrfs_block_group_cache *bg_cache,
struct extent_buffer *src_parent, int src_slot,
struct extent_buffer *dst_parent, int dst_slot,
u64 last_snapshot)
@@ -1978,6 +1980,7 @@ int btrfs_qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans,
struct btrfs_key first_key;
struct extent_buffer *src_eb = NULL;
struct extent_buffer *dst_eb = NULL;
+ bool trace_leaf = false;
u64 child_gen;
u64 child_bytenr;
int level;
@@ -1990,6 +1993,12 @@ int btrfs_qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans,
BUG_ON(btrfs_node_ptr_generation(src_parent, src_slot) >
btrfs_node_ptr_generation(dst_parent, dst_slot));
+ /*
+ * Only trace leaf if we're relocating data block groups, this could
+ * reduce tons of data extents tracing for meta/sys bg relocation.
+ */
+ if (bg_cache->flags & BTRFS_BLOCK_GROUP_DATA)
+ trace_leaf = true;
/* Read out real @src_eb, pointed by @src_parent and @src_slot */
child_bytenr = btrfs_node_blockptr(src_parent, src_slot);
child_gen = btrfs_node_ptr_generation(src_parent, src_slot);
@@ -2033,7 +2042,7 @@ int btrfs_qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans,
/* Do the generation aware breadth-first search */
ret = qgroup_trace_new_subtree_blocks(trans, src_eb, dst_path, level,
- level, last_snapshot);
+ level, last_snapshot, trace_leaf);
if (ret < 0)
goto out;
ret = 0;
diff --git a/fs/btrfs/qgroup.h b/fs/btrfs/qgroup.h
index 9f9943dfd493..5289cf0e5e6b 100644
--- a/fs/btrfs/qgroup.h
+++ b/fs/btrfs/qgroup.h
@@ -243,6 +243,7 @@ int btrfs_qgroup_trace_subtree(struct btrfs_trans_handle *trans,
* new tree blocks whose generation is equal to (or larger than) @last_snapshot.
*/
int btrfs_qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans,
+ struct btrfs_block_group_cache *bg_cache,
struct extent_buffer *src_parent, int src_slot,
struct extent_buffer *dst_parent, int dst_slot,
u64 last_snapshot);
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 07ab61a740ae..44efde9886fc 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1735,7 +1735,7 @@ int memcmp_node_keys(struct extent_buffer *eb, int slot,
* errors, a negative error number is returned.
*/
static noinline_for_stack
-int replace_path(struct btrfs_trans_handle *trans,
+int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
struct btrfs_root *dest, struct btrfs_root *src,
struct btrfs_path *path, struct btrfs_key *next_key,
int lowest_level, int max_level)
@@ -1879,9 +1879,9 @@ int replace_path(struct btrfs_trans_handle *trans,
* and tree block numbers, if current trans doesn't free
* data reloc tree inode.
*/
- ret = btrfs_qgroup_trace_subtree_swap(trans, parent, slot,
- path->nodes[level], path->slots[level],
- last_snapshot);
+ ret = btrfs_qgroup_trace_subtree_swap(trans, rc->block_group,
+ parent, slot, path->nodes[level],
+ path->slots[level], last_snapshot);
if (ret < 0)
break;
@@ -2200,7 +2200,7 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
btrfs_comp_cpu_keys(&next_key, &key) >= 0) {
ret = 0;
} else {
- ret = replace_path(trans, root, reloc_root, path,
+ ret = replace_path(trans, rc, root, reloc_root, path,
&next_key, level, max_level);
}
if (ret < 0) {
--
2.18.0
next prev parent reply other threads:[~2018-09-11 10:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-11 5:38 [PATCH v3 0/7] btrfs: qgroup: Reduce dirty extents for metadata Qu Wenruo
2018-09-11 5:38 ` [PATCH v3 1/7] btrfs: qgroup: Introduce trace event to analyse the number of dirty extents accounted Qu Wenruo
2018-09-26 14:06 ` David Sterba
2018-09-11 5:38 ` [PATCH v3 2/7] btrfs: qgroup: Introduce function to trace two swaped extents Qu Wenruo
2018-09-11 5:38 ` [PATCH v3 3/7] btrfs: qgroup: Introduce function to find all new tree blocks of reloc tree Qu Wenruo
2018-09-26 14:29 ` David Sterba
2018-09-26 14:40 ` Qu Wenruo
2018-09-11 5:38 ` [PATCH v3 4/7] btrfs: qgroup: Use generation aware subtree swap to mark dirty extents Qu Wenruo
2018-09-26 14:35 ` David Sterba
2018-09-26 14:43 ` Qu Wenruo
2018-09-11 5:38 ` [PATCH v3 5/7] btrfs: qgroup: Don't trace subtree if we're dropping reloc tree Qu Wenruo
2018-09-26 14:35 ` David Sterba
2018-09-11 5:38 ` [PATCH v3 6/7] btrfs: delayed-ref: Introduce new parameter for btrfs_add_delayed_tree_ref() to reduce unnecessary qgroup tracing Qu Wenruo
2018-09-26 14:40 ` David Sterba
2018-09-27 5:31 ` Qu Wenruo
2018-09-11 5:38 ` Qu Wenruo [this message]
2018-09-26 14:06 ` [PATCH v3 0/7] btrfs: qgroup: Reduce dirty extents for metadata David Sterba
2018-09-26 14:17 ` Qu Wenruo
2018-09-26 14:25 ` Qu Wenruo
2018-09-26 14:26 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180911053818.10191-8-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).