Btrfs: set keep_lock when necessary in btrfs_defrag_leaves
PATCH v2 1/1 Btrfs: set keep_lock when necessary in btrfs_defrag_leaves
path->keep_lock may force to lock tree root and higher nodes, and make lock contention worse, thus it needs to be avoided as much as possible.
In btrfs_degrag_leaves, path->keep_lock is set but @path immediatley gets released, which is not necessary at all.
---
v2: update commit log with more details.
fs/btrfs/tree-defrag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/tree-defrag.c +1 -2
@@ -65,8 +65,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,memcpy (&key, &root->defrag_progress,sizeof (key)); } - path->keep_locks =1 ; - ret =btrfs_search_forward (root, &key, path,BTRFS_OLDEST_GENERATION );if (ret <0 ) goto out;
@@ -81,6 +79,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,* a deadlock (attempting to write lock an already write locked leaf). */ path->lowest_level =1 ; + path->keep_locks =1 ; wret =btrfs_search_slot (trans, root, &key, path,0 ,1 );if (wret <0 ) {
Signature · 1 line
1.8.3.1
Quoted 7 lines · Liu Bo
path->keep_lockmay force to lock tree root and higher nodes, and make lock contention worse, thus it needs to be avoided as much as possible.In
btrfs_degrag_leaves,path->keep_lockis set but @path immediatley gets released, which is not necessary at all.
This is still very terse and still doesn't explain why keep_locks should be set right before btrfs_search_slot and not the beginning of the function. "when necessary" is perhaps the second most uninformative reason of doing something, right after "because of reasons"
Quoted 29 lines
Signed-off-by Liu Bo <[email protected]>---
v2: update commit log with more details.fs/btrfs/tree-defrag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/btrfs/tree-defrag.c +1
-2@@ -65,8 +65,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,memcpy (&key, &root->defrag_progress,sizeof (key)); } - path->keep_locks =1 ; - ret =btrfs_search_forward (root, &key, path,BTRFS_OLDEST_GENERATION );if (ret <0 ) goto out;@@ -81,6 +79,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,* a deadlock (attempting to write lock an already write locked leaf). */ path->lowest_level =1 ; + path->keep_locks =1 ; wret =btrfs_search_slot (trans, root, &key, path,0 ,1 );if (wret <0 ) {
Quoted 6 lines · Liu Bo
path->keep_lockmay force to lock tree root and higher nodes, and make lock contention worse, thus it needs to be avoided as much as possible.In
btrfs_degrag_leaves,path->keep_lockis set but @path immediatley gets released, which is not necessary at all.
So what is the effect of this? The locks are held throughout btrfs_search_forward and released after that. Thi
Quoted 12 lines
Signed-off-by Liu Bo <[email protected]>---
v2: update commit log with more details.fs/btrfs/tree-defrag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/btrfs/tree-defrag.c +0
-0
fs/btrfs/tree-defrag.c int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, · line 68
Quoted 6 lines
fs/btrfs/tree-defrag.c +0
-2@@ -65,8 +65,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,memcpy (&key, &root->defrag_progress,sizeof (key)); } - path->keep_locks =1 ; - ret =btrfs_search_forward (root, &key, path,BTRFS_OLDEST_GENERATION );
What does btrfs_search_forward do as the first statement:
5115 int btrfs_search_forward(struct btrfs_root *root, struct btrfs_key *min_key,
5116 struct btrfs_path *path,
5117 u64 min_trans)
5118 {
.... declarations
5128
5129 path->keep_locks = 1;
So even if removed from above, there will be no change. The value of keep_locks is preserved after btrfs_path_release.
Quoted 17 lines
fs/btrfs/tree-defrag.c +1
-0if (ret <0 ) goto out;@@ -81,6 +79,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,* a deadlock (attempting to write lock an already write locked leaf). */ path->lowest_level =1 ; + path->keep_locks =1 ; wret =btrfs_search_slot (trans, root, &key, path,0 ,1 );if (wret <0 ) {Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 40 lines · David Sterba
Quoted 6 lines · Liu Bo
path->keep_lockmay force to lock tree root and higher nodes, and make lock contention worse, thus it needs to be avoided as much as possible.In
btrfs_degrag_leaves,path->keep_lockis set but @path immediatley gets released, which is not necessary at all.So what is the effect of this? The locks are held throughout
btrfs_search_forwardand released after that. ThiQuoted 12 lines
Signed-off-by Liu Bo <[email protected]>---
v2: update commit log with more details.fs/btrfs/tree-defrag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/btrfs/tree-defrag.c +0
-0fs/btrfs/tree-defrag.c int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, · line 68
Quoted 6 lines
fs/btrfs/tree-defrag.c +0
-2@@ -65,8 +65,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,memcpy (&key, &root->defrag_progress,sizeof (key)); } - path->keep_locks =1 ; - ret =btrfs_search_forward (root, &key, path,BTRFS_OLDEST_GENERATION );What does
btrfs_search_forwarddo as the first statement:5115 int btrfs_search_forward(struct
btrfs_root*root, structbtrfs_key*min_key,
5116 structbtrfs_path*path,
5117 u64min_trans)
5118 {
.... declarations
5128
5129path->keep_locks= 1;
Quoted 3 lines
So even if removed from above, there will be no change. The value of
keep_locksis preserved afterbtrfs_path_release.
It will set it back,
out:
path->keep_locks = keep_locks;
thanks,
liubo
Quoted 21 lines
Quoted 13 lines
fs/btrfs/tree-defrag.c +1
-1if (ret <0 ) goto out;@@ -81,6 +79,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,* a deadlock (attempting to write lock an already write locked leaf). */ path->lowest_level =1 ; + path->keep_locks =1 ; wret =btrfs_search_slot (trans, root, &key, path,0 ,1 );if (wret <0 ) { --1.8.3.1
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 28 lines · Liu Bo
Quoted 28 lines
Quoted 11 lines
---
v2: update commit log with more details.fs/btrfs/tree-defrag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/btrfs/tree-defrag.c +0
-0fs/btrfs/tree-defrag.c int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, · line 68
Quoted 6 lines
fs/btrfs/tree-defrag.c +0
-2@@ -65,8 +65,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,memcpy (&key, &root->defrag_progress,sizeof (key)); } - path->keep_locks =1 ; - ret =btrfs_search_forward (root, &key, path,BTRFS_OLDEST_GENERATION );What does
btrfs_search_forwarddo as the first statement:5115 int btrfs_search_forward(struct
btrfs_root*root, structbtrfs_key*min_key,
5116 structbtrfs_path*path,
5117 u64min_trans)
5118 {
.... declarations
5128
5129path->keep_locks= 1;
Quoted 8 lines
Quoted 3 lines
So even if removed from above, there will be no change. The value of
keep_locksis preserved afterbtrfs_path_release.It will set it back,
out:
path->keep_locks = keep_locks;
Oh, right. So much for reading the whole function.
Quoted 40 lines · David Sterba
Quoted 6 lines · Liu Bo
path->keep_lockmay force to lock tree root and higher nodes, and make lock contention worse, thus it needs to be avoided as much as possible.In
btrfs_degrag_leaves,path->keep_lockis set but @path immediatley gets released, which is not necessary at all.So what is the effect of this? The locks are held throughout
btrfs_search_forwardand released after that. ThiQuoted 12 lines
Signed-off-by Liu Bo <[email protected]>---
v2: update commit log with more details.fs/btrfs/tree-defrag.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/btrfs/tree-defrag.c +0
-0fs/btrfs/tree-defrag.c int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, · line 68
Quoted 6 lines
fs/btrfs/tree-defrag.c +0
-2@@ -65,8 +65,6 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,memcpy (&key, &root->defrag_progress,sizeof (key)); } - path->keep_locks =1 ; - ret =btrfs_search_forward (root, &key, path,BTRFS_OLDEST_GENERATION );What does
btrfs_search_forwarddo as the first statement:5115 int btrfs_search_forward(struct
btrfs_root*root, structbtrfs_key*min_key,
5116 structbtrfs_path*path,
5117 u64min_trans)
5118 {
.... declarations
5128
5129path->keep_locks= 1;
Quoted 3 lines
So even if removed from above, there will be no change. The value of
keep_locksis preserved afterbtrfs_path_release.
FYI, btrfs_search_forward() doesn't need keep_locks's semantics as all of its callers only access path->nodes[0], thus I'm planning to remove keep_locks setting inside it, too.
thanks,
liubo
Quoted 21 lines
Quoted 13 lines
fs/btrfs/tree-defrag.c +1
-1if (ret <0 ) goto out;@@ -81,6 +79,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,* a deadlock (attempting to write lock an already write locked leaf). */ path->lowest_level =1 ; + path->keep_locks =1 ; wret =btrfs_search_slot (trans, root, &key, path,0 ,1 );if (wret <0 ) { --1.8.3.1
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Liu Bo
Quoted 10 lines
What does
btrfs_search_forwarddo as the first statement:5115 int btrfs_search_forward(struct
btrfs_root*root, structbtrfs_key*min_key,
5116 structbtrfs_path*path,
5117 u64min_trans)
5118 {
.... declarations
5128
5129path->keep_locks= 1;
Quoted 7 lines
Quoted 3 lines
So even if removed from above, there will be no change. The value of
keep_locksis preserved afterbtrfs_path_release.FYI,
btrfs_search_forward()doesn't need keep_locks's semantics as all of its callers only access path->nodes[0], thus I'm planning to removekeep_lockssetting inside it, too.
Ok.
Please update the changelog of this patch and note something about btrfs_search_forward that sets the path lock on it's own and that there's no change in defrag leaves.