Skip to contentSkip to conversation

Btrfs: set leave_spinning in btrfs_get_extent

PATCH Superseded Liu Bo 2 participants 6 messages Aug 23, 2018 – Sep 6, 2018 Btrfs file system

lore
Share & tools
lore

Liu Bo

author
#0 lore raw

PATCH 1/1 Btrfs: set leave_spinning in btrfs_get_extent

Unless it's going to read inline extents from btree leaf to page, btrfs_get_extent won't sleep during the period of holding path lock.

This sets leave_spinning at first and sets path to blocking mode right before reading inline extent if that's the case. The benefit is that a path in spinning mode typically has less impact (faster) on waiters rather than that in blocking mode.

---
 fs/btrfs/inode.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +9 -1
index 10e86f7b5398..4219be9c21f9 100644
@@ -6843,6 +6843,12 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 	 */
 	path->reada = READA_FORWARD;
 
+	/*
+	 * Unless we're going to uncompress inline extent, no sleep would
+	 * happen.
+	 */
+	path->leave_spinning = 1;
+
 	ret = btrfs_lookup_file_extent(NULL, root, path, objectid, start, 0);
 	if (ret < 0) {
 		err = ret;
@@ -6945,6 +6951,8 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 		em->orig_block_len = em->len;
 		em->orig_start = em->start;
 		ptr = btrfs_file_extent_inline_start(item) + extent_offset;
+
+		btrfs_set_path_blocking(path);
 		if (!PageUptodate(page)) {
 			if (btrfs_file_extent_compression(leaf, item) !=
 			    BTRFS_COMPRESS_NONE) {
@@ -6992,10 +7000,10 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 	err = btrfs_add_extent_mapping(fs_info, em_tree, &em, start, len);
 	write_unlock(&em_tree->lock);
 out:
+	btrfs_free_path(path);
 
 	trace_btrfs_get_extent(root, inode, em);
 
-	btrfs_free_path(path);
 	if (err) {
 		free_extent_map(em);
 		return ERR_PTR(err);
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH v2 1/1 Btrfs: set leave_spinning in btrfs_get_extent

Unless it's going to read inline extents from btree leaf to page, btrfs_get_extent won't sleep during the period of holding path lock.

This sets leave_spinning at first and sets path to blocking mode right before reading inline extent if that's the case. The benefit is that a path in spinning mode typically has less impact (faster) on waiters rather than that in blocking mode.

Also fixes the misalignment of the prototype, which is too trivial for a single patch.

---
v2: send out the correct patch.

 fs/btrfs/ctree.h |  4 ++--
 fs/btrfs/inode.c | 14 +++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)
fs/btrfs/ctree.h +2 -2
index 1aeed3c0e949..00e506de70ba 100644
@@ -3177,8 +3177,8 @@ int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
 struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
 			 struct btrfs_root *root, int *was_new);
 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
-		struct page *page, size_t pg_offset,
-		u64 start, u64 end, int create);
+				    struct page *page, size_t pg_offset,
+				    u64 start, u64 end, int create);
 int btrfs_update_inode(struct btrfs_trans_handle *trans,
 			      struct btrfs_root *root,
 			      struct inode *inode);
fs/btrfs/inode.c +11 -3
index 10e86f7b5398..31d43355f052 100644
@@ -6787,9 +6787,9 @@ static noinline int uncompress_inline(struct btrfs_path *path,
  * This also copies inline extents directly into the page.
  */
 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
-		struct page *page,
-	    size_t pg_offset, u64 start, u64 len,
-		int create)
+				    struct page *page,
+				    size_t pg_offset, u64 start, u64 len,
+				    int create)
 {
 	struct btrfs_fs_info *fs_info = inode->root->fs_info;
 	int ret;
@@ -6843,6 +6843,12 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 	 */
 	path->reada = READA_FORWARD;
 
+	/*
+	 * Unless we're going to uncompress inline extent, no sleep would
+	 * happen.
+	 */
+	path->leave_spinning = 1;
+
 	ret = btrfs_lookup_file_extent(NULL, root, path, objectid, start, 0);
 	if (ret < 0) {
 		err = ret;
@@ -6945,6 +6951,8 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 		em->orig_block_len = em->len;
 		em->orig_start = em->start;
 		ptr = btrfs_file_extent_inline_start(item) + extent_offset;
+
+		btrfs_set_path_blocking(path);
 		if (!PageUptodate(page)) {
 			if (btrfs_file_extent_compression(leaf, item) !=
 			    BTRFS_COMPRESS_NONE) {
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 24 lines · Liu Bo

Unless it's going to read inline extents from btree leaf to page, btrfs_get_extent won't sleep during the period of holding path lock.

This sets leave_spinning at first and sets path to blocking mode right before reading inline extent if that's the case. The benefit is that a path in spinning mode typically has less impact (faster) on waiters rather than that in blocking mode.

Also fixes the misalignment of the prototype, which is too trivial for a single patch.

---
v2: send out the correct patch.

 fs/btrfs/ctree.h |  4 ++--
 fs/btrfs/inode.c | 14 +++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)
fs/btrfs/ctree.h +0 -0
index 1aeed3c0e949..00e506de70ba 100644

fs/btrfs/ctree.h int btrfs_merge_bio_hook(struct page *page, unsigned long offset, · line 3181

Quoted 7 lines
fs/btrfs/ctree.h +2 -2
@@ -3177,8 +3177,8 @@ int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
 struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
 			 struct btrfs_root *root, int *was_new);
 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
-		struct page *page, size_t pg_offset,
-		u64 start, u64 end, int create);
+				    struct page *page, size_t pg_offset,
+				    u64 start, u64 end, int create);

Please don't add unrelated changes.

Quoted 8 lines
fs/btrfs/ctree.h +0 -0
 int btrfs_update_inode(struct btrfs_trans_handle *trans,
 			      struct btrfs_root *root,
 			      struct inode *inode);
fs/btrfs/inode.c +0 -0
index 10e86f7b5398..31d43355f052 100644

fs/btrfs/inode.c static noinline int uncompress_inline(struct btrfs_path *path, · line 6792

Quoted 9 lines
fs/btrfs/inode.c +3 -3
@@ -6787,9 +6787,9 @@ static noinline int uncompress_inline(struct btrfs_path *path,
  * This also copies inline extents directly into the page.
  */
 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
-		struct page *page,
-	    size_t pg_offset, u64 start, u64 len,
-		int create)
+				    struct page *page,
+				    size_t pg_offset, u64 start, u64 len,
+				    int create)

Ok, this looks ugly and the reformatting makes sense, both declaration and prototype, but please send it as a separate patch.

author
#3 lore raw
Quoted 47 lines · David Sterba
Quoted 24 lines · Liu Bo

Unless it's going to read inline extents from btree leaf to page, btrfs_get_extent won't sleep during the period of holding path lock.

This sets leave_spinning at first and sets path to blocking mode right before reading inline extent if that's the case. The benefit is that a path in spinning mode typically has less impact (faster) on waiters rather than that in blocking mode.

Also fixes the misalignment of the prototype, which is too trivial for a single patch.

---
v2: send out the correct patch.

 fs/btrfs/ctree.h |  4 ++--
 fs/btrfs/inode.c | 14 +++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)
fs/btrfs/ctree.h +0 -0
index 1aeed3c0e949..00e506de70ba 100644

fs/btrfs/ctree.h int btrfs_merge_bio_hook(struct page *page, unsigned long offset, · line 3181

Quoted 7 lines
fs/btrfs/ctree.h +2 -2
@@ -3177,8 +3177,8 @@ int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
 struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
 			 struct btrfs_root *root, int *was_new);
 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
-		struct page *page, size_t pg_offset,
-		u64 start, u64 end, int create);
+				    struct page *page, size_t pg_offset,
+				    u64 start, u64 end, int create);

Please don't add unrelated changes.

Quoted 12 lines
fs/btrfs/ctree.h +0 -0
 int btrfs_update_inode(struct btrfs_trans_handle *trans,
 			      struct btrfs_root *root,
 			      struct inode *inode);
fs/btrfs/inode.c +0 -1
index 10e86f7b5398..31d43355f052 100644
@@ -6787,9 +6787,9 @@ static noinline int uncompress_inline(struct btrfs_path *path,
  * This also copies inline extents directly into the page.
  */
 struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
-		struct page *page,
Quoted 8 lines

fs/btrfs/inode.c static noinline int uncompress_inline(struct btrfs_path *path, · line 6792

Quoted 5 lines
fs/btrfs/inode.c +3 -2
-	    size_t pg_offset, u64 start, u64 len,
-		int create)
+				    struct page *page,
+				    size_t pg_offset, u64 start, u64 len,
+				    int create)

Ok, this looks ugly and the reformatting makes sense, both declaration and prototype, but please send it as a separate patch.

Sure.

Note that there're still some format issues introduced by the old patch set of "inode -> btrfs_inode".

thanks,
-liubo

author
#4 lore raw

PATCH v3 1/1 Btrfs: set leave_spinning in btrfs_get_extent

In reply to Liu Bo

Unless it's going to read inline extents from btree leaf to page, btrfs_get_extent won't sleep during the period of holding path lock.

This sets leave_spinning at first and sets path to blocking mode right before reading inline extent if that's the case. The benefit is that a path in spinning mode typically has less impact (faster) on waiters rather than that in blocking mode.

Also fixes the misalignment of the prototype, which is too trivial for a single patch.

---
v3: separate alignment fix out of this patch.

 fs/btrfs/inode.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/btrfs/inode.c +8 -0
index 10e86f7b5398..1e0af0cc56fc 100644
@@ -6843,6 +6843,12 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 	 */
 	path->reada = READA_FORWARD;
 
+	/*
+	 * Unless we're going to uncompress inline extent, no sleep would
+	 * happen.
+	 */
+	path->leave_spinning = 1;
+
 	ret = btrfs_lookup_file_extent(NULL, root, path, objectid, start, 0);
 	if (ret < 0) {
 		err = ret;
@@ -6945,6 +6951,8 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
 		em->orig_block_len = em->len;
 		em->orig_start = em->start;
 		ptr = btrfs_file_extent_inline_start(item) + extent_offset;
+
+		btrfs_set_path_blocking(path);
 		if (!PageUptodate(page)) {
 			if (btrfs_file_extent_compression(leaf, item) !=
 			    BTRFS_COMPRESS_NONE) {
Signature · 1 line
1.8.3.1
Reviewed-by on v3 1/1
#5 lore raw
Quoted 10 lines · Liu Bo

Unless it's going to read inline extents from btree leaf to page, btrfs_get_extent won't sleep during the period of holding path lock.

This sets leave_spinning at first and sets path to blocking mode right before reading inline extent if that's the case. The benefit is that a path in spinning mode typically has less impact (faster) on waiters rather than that in blocking mode.

Also fixes the misalignment of the prototype, which is too trivial for a single patch.

^^^ removed as it refers to the hunks from v2.

Quoted 1 line