diff mbox

Btrfs: set keep_lock when necessary in btrfs_defrag_leaves

Message ID 1524620434-108372-1-git-send-email-bo.liu@linux.alibaba.com (mailing list archive)
State New, archived
Headers show

Commit Message

Liu Bo April 25, 2018, 1:40 a.m. UTC
path->keep_lock is set but @path immediatley gets released, this sets
->keep_lock only when it's necessary.

Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
---
 fs/btrfs/tree-defrag.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

David Sterba April 25, 2018, 8:01 p.m. UTC | #1
On Wed, Apr 25, 2018 at 09:40:34AM +0800, Liu Bo wrote:
> path->keep_lock is set but @path immediatley gets released, this sets
> ->keep_lock only when it's necessary.

Can you please write down more details for context? This mostly repeats
what the code does, but not why. Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Liu Bo April 26, 2018, 1:13 a.m. UTC | #2
On Thu, Apr 26, 2018 at 4:01 AM, David Sterba <dsterba@suse.cz> wrote:
> On Wed, Apr 25, 2018 at 09:40:34AM +0800, Liu Bo wrote:
>> path->keep_lock is set but @path immediatley gets released, this sets
>> ->keep_lock only when it's necessary.
>
> Can you please write down more details for context? This mostly repeats
> what the code does, but not why. Thanks.

Urr, right, I missed the important piece.

->keep_lock may hold the locks of all nodes on the path instead of
only level=1 node and level=0 leaf.  As it's more likely that lock
content happens on tree root and higher nodes, we have to release as
less locks as possible.

Will update in v2.

thanks,
liubo

> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/tree-defrag.c b/fs/btrfs/tree-defrag.c
index 3c0987ab587d..c12747904d4c 100644
--- a/fs/btrfs/tree-defrag.c
+++ b/fs/btrfs/tree-defrag.c
@@ -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) {