btrfs: qgroup: Delay subtree scan to reduce overhead
v2 cover btrfs: qgroup: Delay subtree scan to reduce overhead
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebased
Which is based on v4.20-rc1.
This patch address the heavy load subtree scan, but delaying it until we're going to modify the swapped tree block.
The overall workflow is:
1) Record the subtree root block get swapped.
During subtree swap:
O = Old tree blocks
N = New tree blocks
reloc tree file tree X
Root Root
/ \ / \
NA OB OA OB
/ | | \ / | | \
NC ND OE OF OC OD OE OF
In these case, NA and OA is going to be swapped, record (NA, OA) into file tree X.
2) After subtree swap.
reloc tree file tree X
Root Root
/ \ / \
OA OB NA OB
/ | | \ / | | \
OC OD OE OF NC ND OE OF
3a) CoW happens for OB
If we are going to CoW tree block OB, we check OB's bytenr against tree X's swapped_blocks structure.
It doesn't fit any one, nothing will happen.
3b) CoW happens for NA
Check NA's bytenr against tree X's swapped_blocks, and get a hit. Then we do subtree scan on both subtree OA and NA. Resulting 6 tree blocks to be scanned (OA, OC, OD, NA, NC, ND).
Then no matter what we do to file tree X, qgroup numbers will still be correct.
Then NA's record get removed from X's swapped_blocks.
4) Transaction commit
Any record in X's swapped_blocks get removed, since there is no modification to swapped subtrees, no need to trigger heavy qgroup subtree rescan for them.
[[Benchmark]]
Hardware:
VM 4G vRAM, 8 vCPUs,
disk is using 'unsafe' cache mode,
backing device is SAMSUNG 850 evo SSD.
Host has 16G ram.
Mkfs parameter:
--nodesize 4K (To bump up tree size)
Initial subvolume contents:
4G data copied from /usr and /lib.
(With enough regular small files)
Snapshots:
16 snapshots of the original subvolume. each snapshot has 3 random files modified.
balance parameter:
-m
So the content should be pretty similar to a real world root fs layout.
And after file system population, there is no other activity, so it should be the best case scenario.
| v4.20-rc1 | w/ patchset | diff
-----------------------------------------------------------------------
relocated extents | 22615 | 22457 | -0.1% qgroup dirty extents | 163457 | 121606 | -25.6% time (sys) | 22.884s | 18.842s | -17.6% time (real) | 27.724s | 22.884s | -17.5%
changelog:
v2:
Rebase to v4.20-rc1.
Instead commit transaction after each reloc tree merge, delay it until merge_reloc_roots() finishes.
This provides a more natural behavior, and reduce the unnecessary transaction commits.
Qu Wenruo (6):
btrfs: qgroup: Allow btrfs_qgroup_extent_record::old_roots unpopulated
at insert time
btrfs: relocation: Delay reloc tree deletion after merge_reloc_roots()
btrfs: qgroup: Refactor btrfs_qgroup_trace_subtree_swap()
btrfs: qgroup: Introduce per-root swapped blocks infrastructure
btrfs: qgroup: Use delayed subtree rescan for balance
btrfs: qgroup: Cleanup old subtree swap code
fs/btrfs/ctree.c | 8 + fs/btrfs/ctree.h | 14 ++ fs/btrfs/disk-io.c | 1 + fs/btrfs/qgroup.c | 376 +++++++++++++++++++++++++++++++---------- fs/btrfs/qgroup.h | 107 +++++++++++- fs/btrfs/relocation.c | 140 ++++++++++++--- fs/btrfs/transaction.c | 1 + 7 files changed, 527 insertions(+), 120 deletions(-)
Signature · 1 line
2.19.1
PATCH v2 1/6 btrfs: qgroup: Allow btrfs_qgroup_extent_record::old_roots unpopulated at insert time
Commit fb235dc06fac ("btrfs: qgroup: Move half of the qgroup accounting time out of commit trans") makes btrfs_qgroup_extent_record::old_roots populated at insert time.
It's OK for most cases as btrfs_qgroup_extent_record is inserted at delayed ref head insert time, which has a less restrict lock context.
But later delayed subtree scan optimization will need to insert btrfs_qgroup_extent_record with path write lock hold, where triggering a backref walk can easily lead to dead lock.
So this patch introduces two new internal functions, qgroup_trace_extent() and qgroup_trace_leaf_items(), with new @exec_post parameter to info whether we need to initialize the backref walk right now.
Also modifies btrfs_qgroup_account_extents() not to trigger kernel warning.
--- fs/btrfs/qgroup.c | 51 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-)
fs/btrfs/qgroup.c +41 -10
@@ -1580,8 +1580,16 @@ int btrfs_qgroup_trace_extent_post(struct btrfs_fs_info *fs_info,return 0 ; } -int btrfs_qgroup_trace_extent (struct btrfs_trans_handle *trans,u64 bytenr, -u64 num_bytes,gfp_t gfp_flag) +/* +* Insert qgroup extent record for extent at @bytenr, @num_bytes. +* +* @bytenr: bytenr of the extent +* @num_bytes: length of the extent +* @exec_post: whether to exec the post insert work +* will init backref walk if set to true. +*/ +static int qgroup_trace_extent (struct btrfs_trans_handle *trans,u64 bytenr, +u64 num_bytes,gfp_t gfp_flag,bool exec_post) {struct btrfs_fs_info *fs_info = trans->fs_info;struct btrfs_qgroup_extent_record *record;
@@ -1607,11 +1615,27 @@ int btrfs_qgroup_trace_extent(struct btrfs_trans_handle *trans, u64 bytenr,kfree (record);return 0 ; } -return btrfs_qgroup_trace_extent_post (fs_info, record); +if (exec_post) +return btrfs_qgroup_trace_extent_post (fs_info, record); +return 0 ; } -int btrfs_qgroup_trace_leaf_items (struct btrfs_trans_handle *trans, -struct extent_buffer *eb) +int btrfs_qgroup_trace_extent (struct btrfs_trans_handle *trans,u64 bytenr, +u64 num_bytes,gfp_t gfp_flag) +{ +return qgroup_trace_extent (trans, bytenr, num_bytes, gfp_flag, true); +} + +/* +* Insert qgroup extent record for leaf and all file extents in it +* +* @bytenr: bytenr of the leaf +* @num_bytes: length of the leaf +* @exec_post: whether to exec the post insert work +* will init backref walk if set to true. +*/ +static int qgroup_trace_leaf_items (struct btrfs_trans_handle *trans, +struct extent_buffer *eb,bool exec_post) {struct btrfs_fs_info *fs_info = trans->fs_info;int nr =btrfs_header_nritems (eb);
@@ -1643,8 +1667,8 @@ int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans, num_bytes =btrfs_file_extent_disk_num_bytes (eb, fi); - ret =btrfs_qgroup_trace_extent (trans, bytenr, num_bytes, -GFP_NOFS ); + ret =qgroup_trace_extent (trans, bytenr, num_bytes,GFP_NOFS , + exec_post);if (ret)return ret; }
@@ -1652,6 +1676,12 @@ int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans,return 0 ; } +int btrfs_qgroup_trace_leaf_items (struct btrfs_trans_handle *trans, +struct extent_buffer *eb) +{ +return qgroup_trace_leaf_items (trans, eb, true); +} +/* * Walk up the tree from the bottom, freeing leaves and any interior * nodes which have had all slots visited. If a node (leaf or
@@ -2558,10 +2588,11 @@ int btrfs_qgroup_account_extents(struct btrfs_trans_handle *trans)if (!ret) {/* -* Old roots should be searched when inserting qgroup -* extent record +* Most record->old_roots should have been populated at +* insert time. Although we still allow some records +* without old_roots populated. */ -if (WARN_ON (!record->old_roots)) { +if (!record->old_roots) {/* Search commit root to find old_roots */ ret = btrfs_find_all_roots(NULL, fs_info, record->bytenr, 0,
Signature · 1 line
2.19.1
PATCH v2 2/6 btrfs: relocation: Delay reloc tree deletion after merge_reloc_roots()
In reply to Qu WenruoRelocation code will drop btrfs_root::reloc_root as soon as merge_reloc_root() finishes.
However later qgroup code will need to access btrfs_root::reloc_root after merge_reloc_root() for delayed subtree rescan.
So alter the timming of resetting btrfs_root:::reloc_root, make it happens after transaction commit.
With this patch, we will introduce a new btrfs_root::state, BTRFS_ROOT_DEAD_RELOC_TREE, to info part of btrfs_root::reloc_tree user that although btrfs_root::reloc_tree is still non-NULL, but still it's not used any more.
The lifespan of btrfs_root::reloc tree will become:
Old behavior | New
------------------------------------------------------------------------
btrfs_init_reloc_root() --- | btrfs_init_reloc_root() ---
set reloc_root | | set reloc_root |
| | |
| | |
merge_reloc_root() | | merge_reloc_root() |
|- btrfs_update_reloc_root() --- | |- btrfs_update_reloc_root() -+-
clear btrfs_root::reloc_root | set ROOT_DEAD_RELOC_TREE |
| record root into dirty |
| roots rbtree |
| |
| reloc_block_group() Or |
| btrfs_recover_relocation() |
| | After transaction commit |
| |- clean_dirty_root() ---
| clear btrfs_root::reloc_rootDuring ROOT_DEAD_RELOC_TREE set lifespan, the only user of btrfs_root::reloc_tree should be qgroup.
And to co-operate this, also delayed btrfs_drop_snapshot() call on reloc tree, btrfs_drop_snapshot() call will also be delayed to clean_dirty_root().
--- fs/btrfs/ctree.h | 1 + fs/btrfs/relocation.c | 125 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 109 insertions(+), 17 deletions(-)
fs/btrfs/ctree.h +1 -0
@@ -1149,6 +1149,7 @@ struct btrfs_subvolume_writers {#define BTRFS_ROOT_FORCE_COW 6#define BTRFS_ROOT_MULTI_LOG_TASKS 7#define BTRFS_ROOT_DIRTY 8 +#define BTRFS_ROOT_DEAD_RELOC_TREE 9/* * in ram representation of the tree. extent_root is used for all allocations
fs/btrfs/relocation.c +108 -17
180 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH v2 3/6 btrfs: qgroup: Refactor btrfs_qgroup_trace_subtree_swap()
In reply to Qu WenruoRefactor btrfs_qgroup_trace_subtree_swap() into qgroup_trace_subtree_swap(), which only needs two extent buffer and some other bool to control the behavior.
Also, allow depending functions to accept parameter @exec_post to determine whether we need to trigger backref walk.
This provides the basis for later delayed subtree scan work.
--- fs/btrfs/qgroup.c | 104 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 32 deletions(-)
fs/btrfs/qgroup.c +72 -32
@@ -1793,7 +1793,7 @@ 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, - bool trace_leaf) + bool trace_leaf, bool exec_post) { struct btrfs_key key;struct btrfs_path *src_path;
@@ -1884,22 +1884,23 @@ static int qgroup_trace_extent_swap(struct btrfs_trans_handle* trans,* Now both @dst_path and @src_path have been populated, record the tree * blocks for qgroup accounting. */ - ret =btrfs_qgroup_trace_extent (trans, src_path->nodes[dst_level]->start, - nodesize,GFP_NOFS ); + ret =qgroup_trace_extent (trans, src_path->nodes[dst_level]->start, + nodesize,GFP_NOFS , exec_post);if (ret <0 ) goto out; - ret =btrfs_qgroup_trace_extent (trans, - dst_path->nodes[dst_level]->start, - nodesize,GFP_NOFS ); + ret =qgroup_trace_extent (trans, dst_path->nodes[dst_level]->start, + nodesize,GFP_NOFS , exec_post);if (ret <0 ) goto out;/* Record leaf file extents */ if (dst_level ==0 && trace_leaf) { - ret =btrfs_qgroup_trace_leaf_items (trans, src_path->nodes[0 ]); + ret =qgroup_trace_leaf_items (trans, src_path->nodes[0 ], + exec_post);if (ret <0 ) goto out; - ret =btrfs_qgroup_trace_leaf_items (trans, dst_path->nodes[0 ]); + ret =qgroup_trace_leaf_items (trans, dst_path->nodes[0 ], + exec_post); } out:btrfs_free_path (src_path);
@@ -1932,7 +1933,8 @@ 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, bool trace_leaf) + u64 last_snapshot, bool trace_leaf, + bool exec_post) { struct btrfs_fs_info *fs_info = trans->fs_info;struct extent_buffer *eb;
@@ -2004,7 +2006,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, trace_leaf); + root_level, trace_leaf, exec_post);if (ret <0 ) goto cleanup;
@@ -2021,7 +2023,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, trace_leaf); + last_snapshot, trace_leaf, exec_post);if (ret <0 ) goto cleanup; }
@@ -2041,6 +2043,62 @@ static int qgroup_trace_new_subtree_blocks(struct btrfs_trans_handle* trans,return ret; } +static int qgroup_trace_subtree_swap (struct btrfs_trans_handle *trans, +struct extent_buffer *src_eb, +struct extent_buffer *dst_eb, +u64 last_snapshot,bool trace_leaf, +bool exec_post) +{ +struct btrfs_fs_info *fs_info = trans->fs_info; +struct btrfs_path *dst_path =NULL ; +int level; +int ret; + +if (!test_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags)) +return 0 ; + +/* Wrong parameter order */ +if (btrfs_header_generation (src_eb) >btrfs_header_generation (dst_eb)) { +btrfs_err_rl (fs_info, +"%s: bad parameter order, src_gen=%llu dst_gen=%llu" , __func__, +btrfs_header_generation (src_eb), +btrfs_header_generation (dst_eb)); +return -EUCLEAN ; + } + +if (!extent_buffer_uptodate (src_eb) || + !extent_buffer_uptodate (dst_eb)) { + ret = -EINVAL ; + goto out; + } + + level =btrfs_header_level (dst_eb); + dst_path =btrfs_alloc_path (); +if (!dst_path) { + ret = -ENOMEM ; + goto out; + } +/* For dst_path */ +extent_buffer_get (dst_eb); + dst_path->nodes[level] = dst_eb; + dst_path->slots[level] =0 ; + dst_path->locks[level] =0 ; + +/* Do the generation aware breadth-first search */ + ret =qgroup_trace_new_subtree_blocks (trans, src_eb, dst_path, level, + level, last_snapshot, trace_leaf, + exec_post); +if (ret <0 ) + goto out; + ret =0 ; + +out: +btrfs_free_path (dst_path); +if (ret <0 ) + fs_info->qgroup_flags |=BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ; +return ret; +} +/* * Inform qgroup to trace subtree swap used in balance. *
@@ -2066,14 +2124,12 @@ int btrfs_qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans, u64 last_snapshot) {struct btrfs_fs_info *fs_info = trans->fs_info; -struct btrfs_path *dst_path =NULL ;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;int ret;if (!test_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags))
@@ -2124,22 +2180,9 @@ int btrfs_qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans, goto out; } - level =btrfs_header_level (dst_eb); - dst_path =btrfs_alloc_path (); -if (!dst_path) { - ret = -ENOMEM ; - goto out; - } - -/* For dst_path */ -extent_buffer_get (dst_eb); - dst_path->nodes[level] = dst_eb; - dst_path->slots[level] =0 ; - dst_path->locks[level] =0 ; - -/* Do the generation-aware breadth-first search */ - ret =qgroup_trace_new_subtree_blocks (trans, src_eb, dst_path, level, - level, last_snapshot, trace_leaf); +/* Do the generation aware breadth-first search */ + ret =qgroup_trace_subtree_swap (trans, src_eb, dst_eb, last_snapshot, + trace_leaf, true);if (ret <0 ) goto out; ret =0 ;
@@ -2147,9 +2190,6 @@ int btrfs_qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans, out:free_extent_buffer (src_eb);free_extent_buffer (dst_eb); -btrfs_free_path (dst_path); -if (ret <0 ) - fs_info->qgroup_flags |=BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT ;return ret; }
Signature · 1 line
2.19.1
PATCH v2 4/6 btrfs: qgroup: Introduce per-root swapped blocks infrastructure
In reply to Qu WenruoTo allow delayed subtree swap rescan, btrfs needs to record per-root info about which tree blocks get swapped.
So this patch introduces per-root btrfs_qgroup_swapped_blocks structure, which records which tree blocks get swapped.
The designed workflow will be:
1) Record the subtree root block get swapped.
During subtree swap:
O = Old tree blocks
N = New tree blocks
reloc tree file tree X
Root Root
/ \ / \
NA OB OA OB
/ | | \ / | | \
NC ND OE OF OC OD OE OF
In these case, NA and OA is going to be swapped, record (NA, OA) into file tree X.
2) After subtree swap.
reloc tree file tree X
Root Root
/ \ / \
OA OB NA OB
/ | | \ / | | \
OC OD OE OF NC ND OE OF
3a) CoW happens for OB
If we are going to CoW tree block OB, we check OB's bytenr against tree X's swapped_blocks structure.
It doesn't fit any one, nothing will happen.
3b) CoW happens for NA
Check NA's bytenr against tree X's swapped_blocks, and get a hit. Then we do subtree scan on both subtree OA and NA. Resulting 6 tree blocks to be scanned (OA, OC, OD, NA, NC, ND).
Then no matter what we do to file tree X, qgroup numbers will still be correct.
Then NA's record get removed from X's swapped_blocks.
4) Transaction commit
Any record in X's swapped_blocks get removed, since there is no modification to swapped subtrees, no need to trigger heavy qgroup subtree rescan for them.
This will introduce 128 bytes overhead for each btrfs_root even qgroup is not enabled.
--- fs/btrfs/ctree.h | 13 +++++ fs/btrfs/disk-io.c | 1 + fs/btrfs/qgroup.c | 130 +++++++++++++++++++++++++++++++++++++++++ fs/btrfs/qgroup.h | 99 +++++++++++++++++++++++++++++++ fs/btrfs/relocation.c | 7 +++ fs/btrfs/transaction.c | 1 + 6 files changed, 251 insertions(+)
fs/btrfs/ctree.h +13 -0
@@ -1151,6 +1151,17 @@ struct btrfs_subvolume_writers {#define BTRFS_ROOT_DIRTY 8#define BTRFS_ROOT_DEAD_RELOC_TREE 9 +/* +* Record swapped tree blocks of a file/subvolume tree for delayed subtree +* trace code. For detail check comment in fs/btrfs/qgroup.c. +*/ +struct btrfs_qgroup_swapped_blocks { +spinlock_t lock; +struct rb_root blocks[BTRFS_MAX_LEVEL ]; +/* RM_EMPTY_ROOT() of above blocks[] */ +bool swapped; +}; +/* * in ram representation of the tree. extent_root is used for all allocations * and for the extent tree extent_root root.
@@ -1275,6 +1286,8 @@ struct btrfs_root {u64 qgroup_meta_rsv_pertrans;u64 qgroup_meta_rsv_prealloc; +struct btrfs_qgroup_swapped_blocks swapped_blocks; +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS u64 alloc_bytenr;#endif
fs/btrfs/disk-io.c +1 -0
@@ -1204,6 +1204,7 @@ static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, root->anon_dev =0 ;spin_lock_init (&root->root_item_lock); +btrfs_qgroup_init_swapped_blocks (&root->swapped_blocks); } static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info,
fs/btrfs/qgroup.c +130 -0
133 lines not on this page · raw message
fs/btrfs/qgroup.h +99 -0
121 lines not on this page · raw message
fs/btrfs/relocation.c +7 -0
@@ -1913,6 +1913,13 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,if (ret <0 )break ; +btrfs_node_key_to_cpu (parent, &first_key, slot); + ret =btrfs_qgroup_add_swapped_blocks (trans, dest, + rc->block_group, parent, slot, + path->nodes[level], path->slots[level], + last_snapshot); +if (ret <0 ) +break ;/* * swap blocks in fs tree and reloc tree. */
fs/btrfs/transaction.c +1 -0
@@ -122,6 +122,7 @@ static noinline void switch_commit_roots(struct btrfs_transaction *trans)if (is_fstree (root->root_key.objectid))btrfs_unpin_free_ino (root);clear_btree_io_tree (&root->dirty_log_pages); +btrfs_qgroup_clean_swapped_blocks (root); }/* We can free old roots now. */
Signature · 1 line
2.19.1
PATCH v2 5/6 btrfs: qgroup: Use delayed subtree rescan for balance
In reply to Qu WenruoBefore this patch, qgroup code trace the whole subtree of file and reloc trees unconditionally.
This makes qgroup numbers consistent, but it could cause tons of unnecessary extent trace, which cause a lot of overhead.
However for subtree swap of balance, since both subtree contains the same content and tree structures, just swap them won't change qgroup numbers.
It's the race window between subtree swap and transaction commit could cause qgroup number change.
This patch will delay the qgroup subtree scan until CoW happens for the subtree root.
So if there is no other operations for the fs, balance won't cause extra qgroup overhead. (best case scenario)
And depends on the workload, most of the subtree scan can still be avoided.
Only for worst case scenario, it will fall back to old subtree swap overhead. (scan all swapped subtrees)
[[Benchmark]]
Hardware:
VM 4G vRAM, 8 vCPUs,
disk is using 'unsafe' cache mode,
backing device is SAMSUNG 850 evo SSD.
Host has 16G ram.
Mkfs parameter:
--nodesize 4K (To bump up tree size)
Initial subvolume contents:
4G data copied from /usr and /lib.
(With enough regular small files)
Snapshots:
16 snapshots of the original subvolume. each snapshot has 3 random files modified.
balance parameter:
-m
So the content should be pretty similar to a real world root fs layout.
And after file system population, there is no other activity, so it should be the best case scenario.
| v4.20-rc1 | w/ patchset | diff
-----------------------------------------------------------------------
relocated extents | 22615 | 22457 | -0.1% qgroup dirty extents | 163457 | 121606 | -25.6% time (sys) | 22.884s | 18.842s | -17.6% time (real) | 27.724s | 22.884s | -17.5%
--- fs/btrfs/ctree.c | 8 ++++ fs/btrfs/qgroup.c | 87 +++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/qgroup.h | 2 + fs/btrfs/relocation.c | 14 +++---- 4 files changed, 102 insertions(+), 9 deletions(-)
fs/btrfs/ctree.c +8 -0
@@ -12,6 +12,7 @@#include "transaction.h" #include "print-tree.h" #include "locking.h" +#include "qgroup.h" static int split_node (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct btrfs_path *path,int level);
@@ -1462,6 +1463,13 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans,btrfs_set_lock_blocking (parent);btrfs_set_lock_blocking (buf); +/* +* Before CoWing this block for later modification, check if it's +* the subtree root and do the delayed subtree trace if needed. +* +* Also We don't care about the error, as it's handled internally. +*/ +btrfs_qgroup_trace_subtree_after_cow (trans, root, buf); ret =__btrfs_cow_block (trans, root, buf, parent, parent_slot, cow_ret, search_start,0 );
fs/btrfs/qgroup.c +87 -0
90 lines not on this page · raw message
fs/btrfs/qgroup.h +2 -0
@@ -424,4 +424,6 @@ int btrfs_qgroup_add_swapped_blocks(struct btrfs_trans_handle *trans, struct extent_buffer *file_parent, int file_slot, struct extent_buffer *reloc_parent, int reloc_slot, u64 last_snapshot); +int btrfs_qgroup_trace_subtree_after_cow (struct btrfs_trans_handle *trans, +struct btrfs_root *root,struct extent_buffer *eb);#endif
fs/btrfs/relocation.c +5 -9
@@ -1904,16 +1904,12 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,* If not traced, we will leak data numbers * 2) Fs subtree * If not traced, we will double count old data -* and tree block numbers, if current trans doesn't free -* data reloc tree inode. +* +* We don't scan the subtree right now, but only record +* the swapped tree blocks. +* The real subtree rescan is delayed until we have new +* CoW on the subtree root node before transaction commit. */ - ret =btrfs_qgroup_trace_subtree_swap (trans, rc->block_group, - parent, slot, path->nodes[level], - path->slots[level], last_snapshot); -if (ret <0 ) -break ; - -btrfs_node_key_to_cpu (parent, &first_key, slot); ret = btrfs_qgroup_add_swapped_blocks(trans, dest, rc->block_group, parent, slot, path->nodes[level], path->slots[level],
Signature · 1 line
2.19.1
PATCH v2 6/6 btrfs: qgroup: Cleanup old subtree swap code
In reply to Qu WenruoSince it's replaced by new delayed subtree swap code, remove the original code.
The cleanup is small since most of its core function is still used by delayed subtree swap trace.
--- fs/btrfs/qgroup.c | 94 ----------------------------------------------- fs/btrfs/qgroup.h | 6 --- 2 files changed, 100 deletions(-)
fs/btrfs/qgroup.c +0 -94
@@ -2099,100 +2099,6 @@ static int qgroup_trace_subtree_swap(struct btrfs_trans_handle *trans,return ret; } -/* -* Inform qgroup to trace subtree swap used in balance. -* -* Unlike btrfs_qgroup_trace_subtree(), this function will only trace -* new tree blocks whose generation is equal to (or larger than) @last_snapshot. -* -* Will go down the tree block pointed by @dst_eb (pointed by @dst_parent and -* @dst_slot), and find any tree blocks whose generation is at @last_snapshot, -* and then go down @src_eb (pointed by @src_parent and @src_slot) to find -* the conterpart of the tree block, then mark both tree blocks as qgroup dirty, -* and skip all tree blocks whose generation is smaller than last_snapshot. -* -* This would skip tons of tree blocks of original btrfs_qgroup_trace_subtree(), -* which could be the cause of very slow balance if the file tree is large. -* -* @src_parent, @src_slot: pointer to src (file tree) eb. -* @dst_parent, @dst_slot: pointer to dst (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) -{ -struct btrfs_fs_info *fs_info = trans->fs_info; -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 ret; - -if (!test_bit (BTRFS_FS_QUOTA_ENABLED , &fs_info->flags)) -return 0 ; - -/* Check parameter order */ -if (btrfs_node_ptr_generation (src_parent, src_slot) > -btrfs_node_ptr_generation (dst_parent, dst_slot)) { -btrfs_err_rl (fs_info, -"%s: bad parameter order, src_gen=%llu dst_gen=%llu" , __func__, -btrfs_node_ptr_generation (src_parent, src_slot), -btrfs_node_ptr_generation (dst_parent, dst_slot)); -return -EUCLEAN ; - } - -/* -* 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); -btrfs_node_key_to_cpu (src_parent, &first_key, src_slot); - - src_eb =read_tree_block (fs_info, child_bytenr, child_gen, -btrfs_header_level (src_parent) -1 , &first_key); -if (IS_ERR (src_eb)) { - ret =PTR_ERR (src_eb); - goto out; - } - -/* Read out real @dst_eb, pointed by @src_parent and @src_slot */ - child_bytenr =btrfs_node_blockptr (dst_parent, dst_slot); - child_gen =btrfs_node_ptr_generation (dst_parent, dst_slot); -btrfs_node_key_to_cpu (dst_parent, &first_key, dst_slot); - - dst_eb =read_tree_block (fs_info, child_bytenr, child_gen, -btrfs_header_level (dst_parent) -1 , &first_key); -if (IS_ERR (dst_eb)) { - ret =PTR_ERR (dst_eb); - goto out; - } - -if (!extent_buffer_uptodate (src_eb) || !extent_buffer_uptodate (dst_eb)) { - ret = -EINVAL ; - goto out; - } - -/* Do the generation aware breadth-first search */ - ret =qgroup_trace_subtree_swap (trans, src_eb, dst_eb, last_snapshot, - trace_leaf, true); -if (ret <0 ) - goto out; - ret =0 ; - -out: -free_extent_buffer (src_eb); -free_extent_buffer (dst_eb); -return ret; -} -int btrfs_qgroup_trace_subtree (struct btrfs_trans_handle *trans,struct extent_buffer *root_eb,u64 root_gen,int root_level)
fs/btrfs/qgroup.h +0 -6
@@ -316,12 +316,6 @@ int btrfs_qgroup_trace_leaf_items(struct btrfs_trans_handle *trans,int btrfs_qgroup_trace_subtree (struct btrfs_trans_handle *trans,struct extent_buffer *root_eb,u64 root_gen,int root_level); - -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);int btrfs_qgroup_account_extent (struct btrfs_trans_handle *trans,u64 bytenr,u64 num_bytes,struct ulist *old_roots,struct ulist *new_roots);
Signature · 1 line
2.19.1
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
During test generic/517, the logs were full of the warning below. The reference test on current master, effectively misc-4.20 which was used as base of your branch did not get the warning.
[11540.167829] BTRFS: end < start 2519039 2519040 [11540.170513] WARNING: CPU: 1 PID: 539 at fs/btrfs/extent_io.c:436 insert_state+0xd8/0x100 [btrfs] [11540.174411] Modules linked in: dm_thin_pool dm_persistent_data dm_bufio dm_bio_prison btrfs libcrc32c xor zstd_decompress zstd_compress xxhash raid6_pq dm_mod loop [last unloaded: libcrc32c] [11540.178279] CPU: 1 PID: 539 Comm: xfs_io Tainted: G D W 4.20.0-rc1-default+ #329 [11540.180616] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.11.2-0-gf9626cc-prebuilt.qemu-project.org 04/01/2014 [11540.183754] RIP: 0010:insert_state+0xd8/0x100 [btrfs] [11540.189173] RSP: 0018:ffffa0d245eafb20 EFLAGS: 00010282 [11540.189885] RAX: 0000000000000000 RBX: ffff9f0bb3267320 RCX: 0000000000000000 [11540.191646] RDX: 0000000000000002 RSI: 0000000000000001 RDI: ffffffffa40c400d [11540.192942] RBP: 0000000000266fff R08: 0000000000000001 R09: 0000000000000000 [11540.193871] R10: 0000000000000000 R11: ffffffffa629da2d R12: ffff9f0ba0281c60 [11540.195527] R13: 0000000000267000 R14: ffffa0d245eafb98 R15: ffffa0d245eafb90 [11540.197026] FS: 00007fa338eb4b80(0000) GS:ffff9f0bbd600000(0000) knlGS:0000000000000000 [11540.198251] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [11540.199698] CR2: 00007fa33873bfb8 CR3: 000000006fb6e000 CR4: 00000000000006e0 [11540.201428] Call Trace: [11540.202164] __set_extent_bit+0x43b/0x5b0 [btrfs] [11540.203223] lock_extent_bits+0x5d/0x210 [btrfs] [11540.204346] ? _raw_spin_unlock+0x24/0x40 [11540.205381] ? test_range_bit+0xdf/0x130 [btrfs] [11540.206573] lock_extent_range+0xb8/0x150 [btrfs] [11540.207696] btrfs_double_extent_lock+0x78/0xb0 [btrfs] [11540.208988] btrfs_extent_same_range+0x131/0x4e0 [btrfs] [11540.210237] btrfs_remap_file_range+0x337/0x350 [btrfs] [11540.211448] vfs_dedupe_file_range_one+0x141/0x150 [11540.212622] vfs_dedupe_file_range+0x146/0x1a0 [11540.213795] do_vfs_ioctl+0x520/0x6c0 [11540.214711] ? __fget+0x109/0x1e0 [11540.215616] ksys_ioctl+0x3a/0x70 [11540.216233] __x64_sys_ioctl+0x16/0x20 [11540.216860] do_syscall_64+0x54/0x180 [11540.217409] entry_SYSCALL_64_after_hwframe+0x49/0xbe [11540.218126] RIP: 0033:0x7fa338a4daa7
Quoted 39 lines · David Sterba
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
During test generic/517, the logs were full of the warning below. The reference test on current master, effectively misc-4.20 which was used as base of your branch did not get the warning.
[11540.167829] BTRFS: end < start 2519039 2519040 [11540.170513] WARNING: CPU: 1 PID: 539 at fs/btrfs/extent_io.c:436 insert_state+0xd8/0x100 [btrfs] [11540.174411] Modules linked in: dm_thin_pool dm_persistent_data dm_bufio dm_bio_prison btrfs libcrc32c xor zstd_decompress zstd_compress xxhash raid6_pq dm_mod loop [last unloaded: libcrc32c] [11540.178279] CPU: 1 PID: 539 Comm: xfs_io Tainted: G D W 4.20.0-rc1-default+ #329 [11540.180616] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.11.2-0-gf9626cc-prebuilt.qemu-project.org 04/01/2014 [11540.183754] RIP: 0010:insert_state+0xd8/0x100 [btrfs] [11540.189173] RSP: 0018:ffffa0d245eafb20 EFLAGS: 00010282 [11540.189885] RAX: 0000000000000000 RBX: ffff9f0bb3267320 RCX: 0000000000000000 [11540.191646] RDX: 0000000000000002 RSI: 0000000000000001 RDI: ffffffffa40c400d [11540.192942] RBP: 0000000000266fff R08: 0000000000000001 R09: 0000000000000000 [11540.193871] R10: 0000000000000000 R11: ffffffffa629da2d R12: ffff9f0ba0281c60 [11540.195527] R13: 0000000000267000 R14: ffffa0d245eafb98 R15: ffffa0d245eafb90 [11540.197026] FS: 00007fa338eb4b80(0000) GS:ffff9f0bbd600000(0000) knlGS:0000000000000000 [11540.198251] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [11540.199698] CR2: 00007fa33873bfb8 CR3: 000000006fb6e000 CR4: 00000000000006e0 [11540.201428] Call Trace: [11540.202164] __set_extent_bit+0x43b/0x5b0 [btrfs] [11540.203223] lock_extent_bits+0x5d/0x210 [btrfs] [11540.204346] ? _raw_spin_unlock+0x24/0x40 [11540.205381] ? test_range_bit+0xdf/0x130 [btrfs] [11540.206573] lock_extent_range+0xb8/0x150 [btrfs] [11540.207696] btrfs_double_extent_lock+0x78/0xb0 [btrfs] [11540.208988] btrfs_extent_same_range+0x131/0x4e0 [btrfs] [11540.210237] btrfs_remap_file_range+0x337/0x350 [btrfs] [11540.211448] vfs_dedupe_file_range_one+0x141/0x150
Quoted 8 lines
[11540.212622] vfs_dedupe_file_range+0x146/0x1a0 [11540.213795] do_vfs_ioctl+0x520/0x6c0 [11540.214711] ? __fget+0x109/0x1e0 [11540.215616] ksys_ioctl+0x3a/0x70 [11540.216233] __x64_sys_ioctl+0x16/0x20 [11540.216860] do_syscall_64+0x54/0x180 [11540.217409] entry_SYSCALL_64_after_hwframe+0x49/0xbe [11540.218126] RIP: 0033:0x7fa338a4daa7
That's the infinite loop issue fixed by one of the patches submitted for 4.20-rc2:
The branch you used for testing doesn't have that fix?
Quoted 1 line
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Quoted 49 lines · Filipe Manana
Quoted 39 lines · David Sterba
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
During test generic/517, the logs were full of the warning below. The reference test on current master, effectively misc-4.20 which was used as base of your branch did not get the warning.
[11540.167829] BTRFS: end < start 2519039 2519040 [11540.170513] WARNING: CPU: 1 PID: 539 at fs/btrfs/extent_io.c:436 insert_state+0xd8/0x100 [btrfs] [11540.174411] Modules linked in: dm_thin_pool dm_persistent_data dm_bufio dm_bio_prison btrfs libcrc32c xor zstd_decompress zstd_compress xxhash raid6_pq dm_mod loop [last unloaded: libcrc32c] [11540.178279] CPU: 1 PID: 539 Comm: xfs_io Tainted: G D W 4.20.0-rc1-default+ #329 [11540.180616] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.11.2-0-gf9626cc-prebuilt.qemu-project.org 04/01/2014 [11540.183754] RIP: 0010:insert_state+0xd8/0x100 [btrfs] [11540.189173] RSP: 0018:ffffa0d245eafb20 EFLAGS: 00010282 [11540.189885] RAX: 0000000000000000 RBX: ffff9f0bb3267320 RCX: 0000000000000000 [11540.191646] RDX: 0000000000000002 RSI: 0000000000000001 RDI: ffffffffa40c400d [11540.192942] RBP: 0000000000266fff R08: 0000000000000001 R09: 0000000000000000 [11540.193871] R10: 0000000000000000 R11: ffffffffa629da2d R12: ffff9f0ba0281c60 [11540.195527] R13: 0000000000267000 R14: ffffa0d245eafb98 R15: ffffa0d245eafb90 [11540.197026] FS: 00007fa338eb4b80(0000) GS:ffff9f0bbd600000(0000) knlGS:0000000000000000 [11540.198251] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [11540.199698] CR2: 00007fa33873bfb8 CR3: 000000006fb6e000 CR4: 00000000000006e0 [11540.201428] Call Trace: [11540.202164] __set_extent_bit+0x43b/0x5b0 [btrfs] [11540.203223] lock_extent_bits+0x5d/0x210 [btrfs] [11540.204346] ? _raw_spin_unlock+0x24/0x40 [11540.205381] ? test_range_bit+0xdf/0x130 [btrfs] [11540.206573] lock_extent_range+0xb8/0x150 [btrfs] [11540.207696] btrfs_double_extent_lock+0x78/0xb0 [btrfs] [11540.208988] btrfs_extent_same_range+0x131/0x4e0 [btrfs] [11540.210237] btrfs_remap_file_range+0x337/0x350 [btrfs] [11540.211448] vfs_dedupe_file_range_one+0x141/0x150Quoted 8 lines
[11540.212622] vfs_dedupe_file_range+0x146/0x1a0 [11540.213795] do_vfs_ioctl+0x520/0x6c0 [11540.214711] ? __fget+0x109/0x1e0 [11540.215616] ksys_ioctl+0x3a/0x70 [11540.216233] __x64_sys_ioctl+0x16/0x20 [11540.216860] do_syscall_64+0x54/0x180 [11540.217409] entry_SYSCALL_64_after_hwframe+0x49/0xbe [11540.218126] RIP: 0033:0x7fa338a4daa7
Quoted 6 lines
That's the infinite loop issue fixed by one of the patches submitted for 4.20-rc2:
The branch you used for testing doesn't have that fix?
Yep, I tried v4.20-rc1 tag, which hits tons of such warning even without my patchset.
So it shouldn't be my patches causing the problem.
Thanks,
Qu
Quoted 4 lines
Quoted 2 lines
Quoted 6 lines · Filipe Manana
That's the infinite loop issue fixed by one of the patches submitted for 4.20-rc2:
The branch you used for testing doesn't have that fix?
That explains it, thanks. The branch was based on 4.20-rc1 as I took it from Qu's repository but did not check the base.
Quoted 10 lines · David Sterba
Quoted 6 lines · Filipe Manana
That's the infinite loop issue fixed by one of the patches submitted for 4.20-rc2:
The branch you used for testing doesn't have that fix?
That explains it, thanks. The branch was based on 4.20-rc1 as I took it from Qu's repository but did not check the base.
BTW should I always rebase my patches to misc-next or misc-4.20?
IMHO based on -rc tags should make it easier for David to rebase/apply, but if it's causing problem like this, I could definitely go misc-* based.
Thanks,
Qu
Quoted 7 lines · Qu Wenruo
Quoted 4 lines · David Sterba
Quoted 3 lines · Filipe Manana
That's the infinite loop issue fixed by one of the patches submitted for 4.20-rc2:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The branch you used for testing doesn't have that fix?
That explains it, thanks. The branch was based on 4.20-rc1 as I took it from Qu's repository but did not check the base.
BTW should I always rebase my patches to misc-next or misc-4.20?
The misc-next can rebase as I add the tags or need to remove a patch etc., so using last rc or the last pulled branch (ie. the exact commit from misc-4.20, not the head itself) should be better option for you so you don't need to catch up and rebase constantly.
I can handle rebases of your branches to current misc-next as long as there are no major conflicts.
Quoted 2 lines
IMHO based on -rc tags should make it easier for David to rebase/apply, but if it's causing problem like this, I could definitely go misc-* based.
No, that was my fault. I review and rebase all topic branches at each rc release, but taking the branch from your repo was a bit different step in the workflow.
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
The branch was there for some time but not for at least a week (my mistake I did not notice in time). I've rebased it on top of recent misc-next, but without the delayed refs patchset from Josef.
At the moment I'm considering it for merge to 4.21, there's still some time to pull it out in case it shows up to be too problematic. I'm mostly worried about the unknown interactions with the enospc updates or generally because of lack of qgroup and reloc code reviews.
I'm going to do some testing of the rebased branch before I add it to for-next. The branch is ext/qu/qgroup-delay-scan in my devel repos, plase check if everyghing is still ok there. Thanks.
Quoted 9 lines · David Sterba
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
Quoted 7 lines
The branch was there for some time but not for at least a week (my mistake I did not notice in time). I've rebased it on top of recent misc-next, but without the delayed refs patchset from Josef.
At the moment I'm considering it for merge to 4.21, there's still some time to pull it out in case it shows up to be too problematic. I'm mostly worried about the unknown interactions with the enospc updates or
For that part, I don't think it would have some obvious problem for enospc updates.
As the user-noticeable effect is the delay of reloc tree deletion.
Despite that, it's mostly transparent to extent allocation.
Quoted 1 line
generally because of lack of qgroup and reloc code reviews.
That's the biggest problem.
However most of the current qgroup + balance optimization is done inside qgroup code (to skip certain qgroup record), if we're going to hit some problem then this patchset would have the highest possibility to hit problem.
Later patches will just keep tweaking qgroup to without affecting any other parts mostly.
So I'm fine if you decide to pull it out for now.
Thanks,
Qu
Quoted 5 lines
I'm going to do some testing of the rebased branch before I add it to for-next. The branch is ext/qu/qgroup-delay-scan in my devel repos, plase check if everyghing is still ok there. Thanks.
Quoted 36 lines · Qu Wenruo
Quoted 9 lines · David Sterba
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
Quoted 7 lines
The branch was there for some time but not for at least a week (my mistake I did not notice in time). I've rebased it on top of recent misc-next, but without the delayed refs patchset from Josef.
At the moment I'm considering it for merge to 4.21, there's still some time to pull it out in case it shows up to be too problematic. I'm mostly worried about the unknown interactions with the enospc updates or
For that part, I don't think it would have some obvious problem for enospc updates.
As the user-noticeable effect is the delay of reloc tree deletion.
Despite that, it's mostly transparent to extent allocation.
Quoted 1 line
generally because of lack of qgroup and reloc code reviews.
That's the biggest problem.
However most of the current qgroup + balance optimization is done inside qgroup code (to skip certain qgroup record), if we're going to hit some problem then this patchset would have the highest possibility to hit problem.
Quoted 4 lines
Later patches will just keep tweaking qgroup to without affecting any other parts mostly.
So I'm fine if you decide to pull it out for now.
I've adapted a stress tests that unpacks a large tarball, snaphosts every 20 seconds, deletes a random snapshot every 50 seconds, deletes file from the original subvolume, now enhanced with qgroups just for the new snapshots inherigin the toplevel subvolume. Lockup.
It gets stuck in a snapshot call with the follwin stacktrace
[<0>] btrfs_tree_read_lock+0xf3/0x150 [btrfs] [<0>] btrfs_qgroup_trace_subtree+0x280/0x7b0 [btrfs] [<0>] do_walk_down+0x681/0xb20 [btrfs] [<0>] walk_down_tree+0xf5/0x1c0 [btrfs] [<0>] btrfs_drop_snapshot+0x43b/0xb60 [btrfs] [<0>] btrfs_clean_one_deleted_snapshot+0xc1/0x120 [btrfs] [<0>] cleaner_kthread+0xf8/0x170 [btrfs] [<0>] kthread+0x121/0x140 [<0>] ret_from_fork+0x27/0x50
and that's like 10th snapshot and ~3rd deltion. This is qgroup show:
qgroupid rfer excl parent -------- ---- ---- ------ 0/5 865.27MiB 1.66MiB --- 0/257 0.00B 0.00B --- 0/259 0.00B 0.00B --- 0/260 806.58MiB 637.25MiB --- 0/262 0.00B 0.00B --- 0/263 0.00B 0.00B --- 0/264 0.00B 0.00B --- 0/265 0.00B 0.00B --- 0/266 0.00B 0.00B --- 0/267 0.00B 0.00B --- 0/268 0.00B 0.00B --- 0/269 0.00B 0.00B --- 0/270 989.04MiB 1.22MiB --- 0/271 0.00B 0.00B --- 0/272 922.25MiB 416.00KiB --- 0/273 931.02MiB 1.50MiB --- 0/274 910.94MiB 1.52MiB ---
1/1 1.64GiB 1.64GiB
0/5,0/257,0/259,0/260,0/262,0/263,0/264,0/265,0/266,0/267,0/268,0/269,0/270,0/271,0/272,0/273,0/274
No IO or cpu activity at this point, the stacktrace and show output remains the same.
So, considering this, I'm not going to add the patchset to 4.21 but will keep it in for-next for testing, any fixups or updates will be applied.
Quoted 47 lines · David Sterba
Quoted 36 lines · Qu Wenruo
Quoted 9 lines · David Sterba
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
Quoted 7 lines
The branch was there for some time but not for at least a week (my mistake I did not notice in time). I've rebased it on top of recent misc-next, but without the delayed refs patchset from Josef.
At the moment I'm considering it for merge to 4.21, there's still some time to pull it out in case it shows up to be too problematic. I'm mostly worried about the unknown interactions with the enospc updates or
For that part, I don't think it would have some obvious problem for enospc updates.
As the user-noticeable effect is the delay of reloc tree deletion.
Despite that, it's mostly transparent to extent allocation.
Quoted 1 line
generally because of lack of qgroup and reloc code reviews.
That's the biggest problem.
However most of the current qgroup + balance optimization is done inside qgroup code (to skip certain qgroup record), if we're going to hit some problem then this patchset would have the highest possibility to hit problem.
Quoted 4 lines
Later patches will just keep tweaking qgroup to without affecting any other parts mostly.
So I'm fine if you decide to pull it out for now.
I've adapted a stress tests that unpacks a large tarball, snaphosts every 20 seconds, deletes a random snapshot every 50 seconds, deletes file from the original subvolume, now enhanced with qgroups just for the new snapshots inherigin the toplevel subvolume. Lockup.
Quoted 4 lines
It gets stuck in a snapshot call with the follwin stacktrace
[<0>] btrfs_tree_read_lock+0xf3/0x150 [btrfs] [<0>] btrfs_qgroup_trace_subtree+0x280/0x7b0 [btrfs]
This looks like the original subtree tracing has something wrong.
Thanks for the report, I'll investigate it.
Qu
Quoted 38 lines
[<0>] do_walk_down+0x681/0xb20 [btrfs] [<0>] walk_down_tree+0xf5/0x1c0 [btrfs] [<0>] btrfs_drop_snapshot+0x43b/0xb60 [btrfs] [<0>] btrfs_clean_one_deleted_snapshot+0xc1/0x120 [btrfs] [<0>] cleaner_kthread+0xf8/0x170 [btrfs] [<0>] kthread+0x121/0x140 [<0>] ret_from_fork+0x27/0x50and that's like 10th snapshot and ~3rd deltion. This is qgroup show:
qgroupid rfer excl parent -------- ---- ---- ------ 0/5 865.27MiB 1.66MiB --- 0/257 0.00B 0.00B --- 0/259 0.00B 0.00B --- 0/260 806.58MiB 637.25MiB --- 0/262 0.00B 0.00B --- 0/263 0.00B 0.00B --- 0/264 0.00B 0.00B --- 0/265 0.00B 0.00B --- 0/266 0.00B 0.00B --- 0/267 0.00B 0.00B --- 0/268 0.00B 0.00B --- 0/269 0.00B 0.00B --- 0/270 989.04MiB 1.22MiB --- 0/271 0.00B 0.00B --- 0/272 922.25MiB 416.00KiB --- 0/273 931.02MiB 1.50MiB --- 0/274 910.94MiB 1.52MiB ---1/1 1.64GiB 1.64GiB
0/5,0/257,0/259,0/260,0/262,0/263,0/264,0/265,0/266,0/267,0/268,0/269,0/270,0/271,0/272,0/273,0/274No IO or cpu activity at this point, the stacktrace and show output remains the same.
So, considering this, I'm not going to add the patchset to 4.21 but will keep it in for-next for testing, any fixups or updates will be applied.
Quoted 11 lines · Qu Wenruo
Quoted 9 lines
I've adapted a stress tests that unpacks a large tarball, snaphosts every 20 seconds, deletes a random snapshot every 50 seconds, deletes file from the original subvolume, now enhanced with qgroups just for the new snapshots inherigin the toplevel subvolume. Lockup.
It gets stuck in a snapshot call with the follwin stacktrace
[<0>] btrfs_tree_read_lock+0xf3/0x150 [btrfs] [<0>] btrfs_qgroup_trace_subtree+0x280/0x7b0 [btrfs]This looks like the original subtree tracing has something wrong.
Yes, I ran the test on current master and it locked up too, so it's not due to your patchset.
Quoted 1 line
Thanks for the report, I'll investigate it.
Thanks.
Quoted 51 lines · Qu Wenruo
Quoted 47 lines · David Sterba
Quoted 36 lines · Qu Wenruo
Quoted 9 lines · David Sterba
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
Quoted 7 lines
The branch was there for some time but not for at least a week (my mistake I did not notice in time). I've rebased it on top of recent misc-next, but without the delayed refs patchset from Josef.
At the moment I'm considering it for merge to 4.21, there's still some time to pull it out in case it shows up to be too problematic. I'm mostly worried about the unknown interactions with the enospc updates or
For that part, I don't think it would have some obvious problem for enospc updates.
As the user-noticeable effect is the delay of reloc tree deletion.
Despite that, it's mostly transparent to extent allocation.
Quoted 1 line
generally because of lack of qgroup and reloc code reviews.
That's the biggest problem.
However most of the current qgroup + balance optimization is done inside qgroup code (to skip certain qgroup record), if we're going to hit some problem then this patchset would have the highest possibility to hit problem.
Quoted 4 lines
Later patches will just keep tweaking qgroup to without affecting any other parts mostly.
So I'm fine if you decide to pull it out for now.
I've adapted a stress tests that unpacks a large tarball, snaphosts every 20 seconds, deletes a random snapshot every 50 seconds, deletes file from the original subvolume, now enhanced with qgroups just for the new snapshots inherigin the toplevel subvolume. Lockup.
Quoted 8 lines
Quoted 4 lines
It gets stuck in a snapshot call with the follwin stacktrace
[<0>] btrfs_tree_read_lock+0xf3/0x150 [btrfs] [<0>] btrfs_qgroup_trace_subtree+0x280/0x7b0 [btrfs]This looks like the original subtree tracing has something wrong.
Thanks for the report, I'll investigate it.
Btw, there's another deadlock with qgroups. I don't recall if I ever reported it, but I still hit it with fstests (rarely happens) for at least 1 year iirc:
[29845.732448] INFO: task kworker/u8:8:3898 blocked for more than 120 seconds. [29845.732852] Not tainted 4.20.0-rc5-btrfs-next-40 #1 [29845.733248] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [29845.733558] kworker/u8:8 D 0 3898 2 0x80000000 [29845.733878] Workqueue: btrfs-endio-write btrfs_endio_write_helper [btrfs] [29845.734183] Call Trace: [29845.734499] ? __schedule+0x3d4/0xbc0 [29845.734818] schedule+0x39/0x90 [29845.735131] btrfs_tree_read_lock+0xe7/0x140 [btrfs] [29845.735430] ? remove_wait_queue+0x60/0x60 [29845.735731] find_parent_nodes+0x25e/0xe30 [btrfs] [29845.736037] btrfs_find_all_roots_safe+0xc6/0x140 [btrfs] [29845.736342] btrfs_find_all_roots+0x52/0x70 [btrfs] [29845.736710] btrfs_qgroup_trace_extent_post+0x37/0x80 [btrfs] [29845.737046] btrfs_add_delayed_data_ref+0x240/0x3d0 [btrfs] [29845.737362] btrfs_inc_extent_ref+0xb7/0x140 [btrfs] [29845.737678] __btrfs_mod_ref+0x174/0x250 [btrfs] [29845.737999] ? add_pinned_bytes+0x60/0x60 [btrfs] [29845.738298] update_ref_for_cow+0x26b/0x340 [btrfs] [29845.738592] __btrfs_cow_block+0x221/0x5b0 [btrfs] [29845.738899] btrfs_cow_block+0xf4/0x210 [btrfs] [29845.739200] btrfs_search_slot+0x583/0xa40 [btrfs] [29845.739527] ? init_object+0x6b/0x80 [29845.739823] btrfs_lookup_file_extent+0x4a/0x70 [btrfs] [29845.740119] __btrfs_drop_extents+0x157/0xd70 [btrfs] [29845.740524] insert_reserved_file_extent.constprop.66+0x97/0x2f0 [btrfs] [29845.740853] ? start_transaction+0xa2/0x490 [btrfs] [29845.741166] btrfs_finish_ordered_io+0x344/0x810 [btrfs] [29845.741489] normal_work_helper+0xea/0x530 [btrfs] [29845.741880] process_one_work+0x22f/0x5d0 [29845.742174] worker_thread+0x4f/0x3b0 [29845.742462] ? rescuer_thread+0x360/0x360 [29845.742759] kthread+0x103/0x140 [29845.743044] ? kthread_create_worker_on_cpu+0x70/0x70 [29845.743336] ret_from_fork+0x3a/0x50
It happened last friday again on 4.20-rcX. It's caused by a change from 2017 (commit fb235dc06fac9eaa4408ade9c8b20d45d63c89b7 btrfs:
qgroup: Move half of the qgroup accounting time out of commit trans). The task is deadlocking with itself.
thanks
Quoted 41 lines
Qu
Quoted 38 lines
[<0>] do_walk_down+0x681/0xb20 [btrfs] [<0>] walk_down_tree+0xf5/0x1c0 [btrfs] [<0>] btrfs_drop_snapshot+0x43b/0xb60 [btrfs] [<0>] btrfs_clean_one_deleted_snapshot+0xc1/0x120 [btrfs] [<0>] cleaner_kthread+0xf8/0x170 [btrfs] [<0>] kthread+0x121/0x140 [<0>] ret_from_fork+0x27/0x50and that's like 10th snapshot and ~3rd deltion. This is qgroup show:
qgroupid rfer excl parent -------- ---- ---- ------ 0/5 865.27MiB 1.66MiB --- 0/257 0.00B 0.00B --- 0/259 0.00B 0.00B --- 0/260 806.58MiB 637.25MiB --- 0/262 0.00B 0.00B --- 0/263 0.00B 0.00B --- 0/264 0.00B 0.00B --- 0/265 0.00B 0.00B --- 0/266 0.00B 0.00B --- 0/267 0.00B 0.00B --- 0/268 0.00B 0.00B --- 0/269 0.00B 0.00B --- 0/270 989.04MiB 1.22MiB --- 0/271 0.00B 0.00B --- 0/272 922.25MiB 416.00KiB --- 0/273 931.02MiB 1.50MiB --- 0/274 910.94MiB 1.52MiB ---1/1 1.64GiB 1.64GiB
0/5,0/257,0/259,0/260,0/262,0/263,0/264,0/265,0/266,0/267,0/268,0/269,0/270,0/271,0/272,0/273,0/274No IO or cpu activity at this point, the stacktrace and show output remains the same.
So, considering this, I'm not going to add the patchset to 4.21 but will keep it in for-next for testing, any fixups or updates will be applied.
Signature · 3 lines
Filipe David Manana, “Whether you think you can, or you think you can't — you're right.”
Quoted 102 lines · Filipe Manana
Quoted 51 lines · Qu Wenruo
Quoted 47 lines · David Sterba
Quoted 36 lines · Qu Wenruo
Quoted 9 lines · David Sterba
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
Quoted 7 lines
The branch was there for some time but not for at least a week (my mistake I did not notice in time). I've rebased it on top of recent misc-next, but without the delayed refs patchset from Josef.
At the moment I'm considering it for merge to 4.21, there's still some time to pull it out in case it shows up to be too problematic. I'm mostly worried about the unknown interactions with the enospc updates or
For that part, I don't think it would have some obvious problem for enospc updates.
As the user-noticeable effect is the delay of reloc tree deletion.
Despite that, it's mostly transparent to extent allocation.
Quoted 1 line
generally because of lack of qgroup and reloc code reviews.
That's the biggest problem.
However most of the current qgroup + balance optimization is done inside qgroup code (to skip certain qgroup record), if we're going to hit some problem then this patchset would have the highest possibility to hit problem.
Quoted 4 lines
Later patches will just keep tweaking qgroup to without affecting any other parts mostly.
So I'm fine if you decide to pull it out for now.
I've adapted a stress tests that unpacks a large tarball, snaphosts every 20 seconds, deletes a random snapshot every 50 seconds, deletes file from the original subvolume, now enhanced with qgroups just for the new snapshots inherigin the toplevel subvolume. Lockup.
Quoted 8 lines
Quoted 4 lines
It gets stuck in a snapshot call with the follwin stacktrace
[<0>] btrfs_tree_read_lock+0xf3/0x150 [btrfs] [<0>] btrfs_qgroup_trace_subtree+0x280/0x7b0 [btrfs]This looks like the original subtree tracing has something wrong.
Thanks for the report, I'll investigate it.
Btw, there's another deadlock with qgroups. I don't recall if I ever reported it, but I still hit it with fstests (rarely happens) for at least 1 year iirc:
[29845.732448] INFO: task kworker/u8:8:3898 blocked for more than 120 seconds. [29845.732852] Not tainted 4.20.0-rc5-btrfs-next-40 #1 [29845.733248] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [29845.733558] kworker/u8:8 D 0 3898 2 0x80000000 [29845.733878] Workqueue: btrfs-endio-write btrfs_endio_write_helper [btrfs] [29845.734183] Call Trace: [29845.734499] ? __schedule+0x3d4/0xbc0 [29845.734818] schedule+0x39/0x90 [29845.735131] btrfs_tree_read_lock+0xe7/0x140 [btrfs] [29845.735430] ? remove_wait_queue+0x60/0x60 [29845.735731] find_parent_nodes+0x25e/0xe30 [btrfs] [29845.736037] btrfs_find_all_roots_safe+0xc6/0x140 [btrfs] [29845.736342] btrfs_find_all_roots+0x52/0x70 [btrfs] [29845.736710] btrfs_qgroup_trace_extent_post+0x37/0x80 [btrfs] [29845.737046] btrfs_add_delayed_data_ref+0x240/0x3d0 [btrfs] [29845.737362] btrfs_inc_extent_ref+0xb7/0x140 [btrfs] [29845.737678] __btrfs_mod_ref+0x174/0x250 [btrfs] [29845.737999] ? add_pinned_bytes+0x60/0x60 [btrfs] [29845.738298] update_ref_for_cow+0x26b/0x340 [btrfs] [29845.738592] __btrfs_cow_block+0x221/0x5b0 [btrfs] [29845.738899] btrfs_cow_block+0xf4/0x210 [btrfs] [29845.739200] btrfs_search_slot+0x583/0xa40 [btrfs] [29845.739527] ? init_object+0x6b/0x80 [29845.739823] btrfs_lookup_file_extent+0x4a/0x70 [btrfs] [29845.740119] __btrfs_drop_extents+0x157/0xd70 [btrfs] [29845.740524] insert_reserved_file_extent.constprop.66+0x97/0x2f0 [btrfs] [29845.740853] ? start_transaction+0xa2/0x490 [btrfs] [29845.741166] btrfs_finish_ordered_io+0x344/0x810 [btrfs] [29845.741489] normal_work_helper+0xea/0x530 [btrfs] [29845.741880] process_one_work+0x22f/0x5d0 [29845.742174] worker_thread+0x4f/0x3b0 [29845.742462] ? rescuer_thread+0x360/0x360 [29845.742759] kthread+0x103/0x140 [29845.743044] ? kthread_create_worker_on_cpu+0x70/0x70 [29845.743336] ret_from_fork+0x3a/0x50
Quoted 3 lines
It happened last friday again on 4.20-rcX. It's caused by a change from 2017 (commit
fb235dc06fac9eaa4408ade9c8b20d45d63c89b7btrfs:
qgroup: Move half of the qgroup accounting time out of commit trans).
I have to admit, this commit doesn't really save much critical section time, but causes a lot of problem for its ability to trigger backward tree locking behavior.
Especially when its original objective is to reduce balance + qgroup overhead, but did a poor job compared to recent optimization.
I'll revert it just as what we did in SLE kernels.
Thanks,
Qu
Quoted 48 lines
The task is deadlocking with itself.
thanks
Quoted 41 lines
Qu
Quoted 38 lines
[<0>] do_walk_down+0x681/0xb20 [btrfs] [<0>] walk_down_tree+0xf5/0x1c0 [btrfs] [<0>] btrfs_drop_snapshot+0x43b/0xb60 [btrfs] [<0>] btrfs_clean_one_deleted_snapshot+0xc1/0x120 [btrfs] [<0>] cleaner_kthread+0xf8/0x170 [btrfs] [<0>] kthread+0x121/0x140 [<0>] ret_from_fork+0x27/0x50and that's like 10th snapshot and ~3rd deltion. This is qgroup show:
qgroupid rfer excl parent -------- ---- ---- ------ 0/5 865.27MiB 1.66MiB --- 0/257 0.00B 0.00B --- 0/259 0.00B 0.00B --- 0/260 806.58MiB 637.25MiB --- 0/262 0.00B 0.00B --- 0/263 0.00B 0.00B --- 0/264 0.00B 0.00B --- 0/265 0.00B 0.00B --- 0/266 0.00B 0.00B --- 0/267 0.00B 0.00B --- 0/268 0.00B 0.00B --- 0/269 0.00B 0.00B --- 0/270 989.04MiB 1.22MiB --- 0/271 0.00B 0.00B --- 0/272 922.25MiB 416.00KiB --- 0/273 931.02MiB 1.50MiB --- 0/274 910.94MiB 1.52MiB ---1/1 1.64GiB 1.64GiB
0/5,0/257,0/259,0/260,0/262,0/263,0/264,0/265,0/266,0/267,0/268,0/269,0/270,0/271,0/272,0/273,0/274No IO or cpu activity at this point, the stacktrace and show output remains the same.
So, considering this, I'm not going to add the patchset to 4.21 but will keep it in for-next for testing, any fixups or updates will be applied.
Quoted 40 lines · David Sterba
Quoted 39 lines · Qu Wenruo
Quoted 9 lines · David Sterba
Quoted 7 lines · David Sterba
Quoted 4 lines · Qu Wenruo
This patchset can be fetched from github:
https://github.com/adam900710/linux/tree/qgroup_delayed_subtree_rebasedWhich is based on v4.20-rc1.
Thanks, I'll add it to for-next soon.
Quoted 7 lines
The branch was there for some time but not for at least a week (my mistake I did not notice in time). I've rebased it on top of recent misc-next, but without the delayed refs patchset from Josef.
At the moment I'm considering it for merge to 4.21, there's still some time to pull it out in case it shows up to be too problematic. I'm mostly worried about the unknown interactions with the enospc updates or
For that part, I don't think it would have some obvious problem for enospc updates.
As the user-noticeable effect is the delay of reloc tree deletion.
Despite that, it's mostly transparent to extent allocation.
Quoted 1 line
generally because of lack of qgroup and reloc code reviews.
That's the biggest problem.
However most of the current qgroup + balance optimization is done inside qgroup code (to skip certain qgroup record), if we're going to hit some problem then this patchset would have the highest possibility to hit problem.
Later patches will just keep tweaking qgroup to without affecting any other parts mostly.
Quoted 6 lines
Quoted 1 line
So I'm fine if you decide to pull it out for now.
I've adapted a stress tests that unpacks a large tarball, snaphosts every 20 seconds, deletes a random snapshot every 50 seconds, deletes file from the original subvolume, now enhanced with qgroups just for the new snapshots inherigin the toplevel subvolume. Lockup.
Could you please provide the test script?
As I can't reproduce it in my environment.
I crafted my own test with some simplification, namely no qgroup inherit. However I can't reproduce the problem even with more snapshots creation/deletion and more data.
In my test script, I created around 35 snapshots, deleted 6 snapshots, with around 1000 data regular extents and 1000 2K inline extents.
My test script can be found at:
https://gist.github.com/adam900710/4109fa23fc5ba8fc6b37a9c8e52353c1
Thanks,
Qu
Quoted 43 lines
It gets stuck in a snapshot call with the follwin stacktrace
[<0>] btrfs_tree_read_lock+0xf3/0x150 [btrfs] [<0>] btrfs_qgroup_trace_subtree+0x280/0x7b0 [btrfs] [<0>] do_walk_down+0x681/0xb20 [btrfs] [<0>] walk_down_tree+0xf5/0x1c0 [btrfs] [<0>] btrfs_drop_snapshot+0x43b/0xb60 [btrfs] [<0>] btrfs_clean_one_deleted_snapshot+0xc1/0x120 [btrfs] [<0>] cleaner_kthread+0xf8/0x170 [btrfs] [<0>] kthread+0x121/0x140 [<0>] ret_from_fork+0x27/0x50and that's like 10th snapshot and ~3rd deltion. This is qgroup show:
qgroupid rfer excl parent -------- ---- ---- ------ 0/5 865.27MiB 1.66MiB --- 0/257 0.00B 0.00B --- 0/259 0.00B 0.00B --- 0/260 806.58MiB 637.25MiB --- 0/262 0.00B 0.00B --- 0/263 0.00B 0.00B --- 0/264 0.00B 0.00B --- 0/265 0.00B 0.00B --- 0/266 0.00B 0.00B --- 0/267 0.00B 0.00B --- 0/268 0.00B 0.00B --- 0/269 0.00B 0.00B --- 0/270 989.04MiB 1.22MiB --- 0/271 0.00B 0.00B --- 0/272 922.25MiB 416.00KiB --- 0/273 931.02MiB 1.50MiB --- 0/274 910.94MiB 1.52MiB ---1/1 1.64GiB 1.64GiB
0/5,0/257,0/259,0/260,0/262,0/263,0/264,0/265,0/266,0/267,0/268,0/269,0/270,0/271,0/272,0/273,0/274No IO or cpu activity at this point, the stacktrace and show output remains the same.
So, considering this, I'm not going to add the patchset to 4.21 but will keep it in for-next for testing, any fixups or updates will be applied.