Skip to contentSkip to conversation

btrfs: Return number of compressed extents directly in compress_file_range

PATCH In review Nikolay Borisov 3 participants 6 messages Jul 1, 2019 – Jul 2, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 btrfs: Return number of compressed extents directly in compress_file_range

compress_file_range returns a void, yet uses a function parameter as a return value. Make that more idiomatic by simply returning the number of compressed extents directly. Also track such extents in more aptly named variables. No functional changes

---
 fs/btrfs/inode.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
fs/btrfs/inode.c +11 -9
index 4e183c2d3555..3b0bf5ea9eb6 100644
@@ -440,8 +440,7 @@ static inline void inode_should_defrag(struct btrfs_inode *inode,
  * are written in the same order that the flusher thread sent them
  * down.
  */
-static noinline void compress_file_range(struct async_chunk *async_chunk,
-					 int *num_added)
+static noinline int compress_file_range(struct async_chunk *async_chunk)
 {
 	struct inode *inode = async_chunk->inode;
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
@@ -457,6 +456,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 	int i;
 	int will_compress;
 	int compress_type = fs_info->compress_type;
+	int compressed_extents = 0;
 	int redirty = 0;
 
 	inode_should_defrag(BTRFS_I(inode), start, end, end - start + 1,
@@ -619,7 +619,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 		 */
 		total_in = ALIGN(total_in, PAGE_SIZE);
 		if (total_compressed + blocksize <= total_in) {
-			*num_added += 1;
+			compressed_extents += 1;
 
 			/*
 			 * The async work queues will take care of doing actual
@@ -636,7 +636,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 				cond_resched();
 				goto again;
 			}
-			return;
+			return compressed_extents;
 		}
 	}
 	if (pages) {
@@ -675,9 +675,9 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 		extent_range_redirty_for_io(inode, start, end);
 	add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
 			 BTRFS_COMPRESS_NONE);
-	*num_added += 1;
+	compressed_extents += 1;
 
-	return;
+	return compressed_extents;
 
 free_pages_out:
 	for (i = 0; i < nr_pages; i++) {
@@ -685,6 +685,8 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 		put_page(pages[i]);
 	}
 	kfree(pages);
+
+	return 0;
 }
 
 static void free_async_extent_pages(struct async_extent *async_extent)
@@ -1122,12 +1124,12 @@ static noinline int cow_file_range(struct inode *inode,
 static noinline void async_cow_start(struct btrfs_work *work)
 {
 	struct async_chunk *async_chunk;
-	int num_added = 0;
+	int compressed_extents = 0;
 
 	async_chunk = container_of(work, struct async_chunk, work);
 
-	compress_file_range(async_chunk, &num_added);
-	if (num_added == 0) {
+	compressed_extents = compress_file_range(async_chunk);
+	if (compressed_extents == 0) {
 		btrfs_add_delayed_iput(async_chunk->inode);
 		async_chunk->inode = NULL;
 	}
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 btrfs: Move free_pages_out label in inline extent handling branch in compress_file_range

This label is only executed if compress_file_range fails to create an inline extent. So move its code in the semantically related inline extent handling branch. No functional changes.

---
 fs/btrfs/inode.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
fs/btrfs/inode.c +8 -10
index 3b0bf5ea9eb6..072a300f8487 100644
@@ -600,7 +600,14 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 						     PAGE_SET_WRITEBACK |
 						     page_error_op |
 						     PAGE_END_WRITEBACK);
-			goto free_pages_out;
+
+			for (i = 0; i < nr_pages; i++) {
+				WARN_ON(pages[i]->mapping);
+				put_page(pages[i]);
+			}
+			kfree(pages);
+
+			return 0;
 		}
 	}
 
@@ -678,15 +685,6 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 	compressed_extents += 1;
 
 	return compressed_extents;
-
-free_pages_out:
-	for (i = 0; i < nr_pages; i++) {
-		WARN_ON(pages[i]->mapping);
-		put_page(pages[i]);
-	}
-	kfree(pages);
-
-	return 0;
 }
 
 static void free_async_extent_pages(struct async_extent *async_extent)
Signature · 1 line
2.17.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] btrfs: Move free_pages_out label in inline extent handling branch in compress_file_range

Quoted 5 lines · Nikolay Borisov

This label is only executed if compress_file_range fails to create an inline extent. So move its code in the semantically related inline extent handling branch. No functional changes.

Thanks,
Qu

Quoted 41 lines
---
 fs/btrfs/inode.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
fs/btrfs/inode.c +8 -10
index 3b0bf5ea9eb6..072a300f8487 100644
@@ -600,7 +600,14 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 						     PAGE_SET_WRITEBACK |
 						     page_error_op |
 						     PAGE_END_WRITEBACK);
-			goto free_pages_out;
+
+			for (i = 0; i < nr_pages; i++) {
+				WARN_ON(pages[i]->mapping);
+				put_page(pages[i]);
+			}
+			kfree(pages);
+
+			return 0;
 		}
 	}
 
@@ -678,15 +685,6 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
 	compressed_extents += 1;
 
 	return compressed_extents;
-
-free_pages_out:
-	for (i = 0; i < nr_pages; i++) {
-		WARN_ON(pages[i]->mapping);
-		put_page(pages[i]);
-	}
-	kfree(pages);
-
-	return 0;
 }
 
 static void free_async_extent_pages(struct async_extent *async_extent)
Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] btrfs: Move free_pages_out label in inline extent handling branch in compress_file_range

In reply to Nikolay Borisov
Quoted 5 lines · Nikolay Borisov

This label is only executed if compress_file_range fails to create an inline extent. So move its code in the semantically related inline extent handling branch. No functional changes.

Looks good.

Quoted 41 lines
---
  fs/btrfs/inode.c | 18 ++++++++----------
  1 file changed, 8 insertions(+), 10 deletions(-)
fs/btrfs/inode.c +8 -10
index 3b0bf5ea9eb6..072a300f8487 100644
@@ -600,7 +600,14 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
  						     PAGE_SET_WRITEBACK |
  						     page_error_op |
  						     PAGE_END_WRITEBACK);
-			goto free_pages_out;
+
+			for (i = 0; i < nr_pages; i++) {
+				WARN_ON(pages[i]->mapping);
+				put_page(pages[i]);
+			}
+			kfree(pages);
+
+			return 0;
  		}
  	}
 
@@ -678,15 +685,6 @@ static noinline int compress_file_range(struct async_chunk *async_chunk)
  	compressed_extents += 1;
 
  	return compressed_extents;
-
-free_pages_out:
-	for (i = 0; i < nr_pages; i++) {
-		WARN_ON(pages[i]->mapping);
-		put_page(pages[i]);
-	}
-	kfree(pages);
-
-	return 0;
  }
 
  static void free_async_extent_pages(struct async_extent *async_extent)
Reviewed-by on v1 1/2
#4 lore raw
In reply to Nikolay Borisov
Quoted 6 lines · Nikolay Borisov

compress_file_range returns a void, yet uses a function parameter as a return value. Make that more idiomatic by simply returning the number of compressed extents directly. Also track such extents in more aptly named variables. No functional changes

Thanks,
Qu

Quoted 82 lines
---
 fs/btrfs/inode.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)
fs/btrfs/inode.c +11 -9
index 4e183c2d3555..3b0bf5ea9eb6 100644
@@ -440,8 +440,7 @@ static inline void inode_should_defrag(struct btrfs_inode *inode,
  * are written in the same order that the flusher thread sent them
  * down.
  */
-static noinline void compress_file_range(struct async_chunk *async_chunk,
-					 int *num_added)
+static noinline int compress_file_range(struct async_chunk *async_chunk)
 {
 	struct inode *inode = async_chunk->inode;
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
@@ -457,6 +456,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 	int i;
 	int will_compress;
 	int compress_type = fs_info->compress_type;
+	int compressed_extents = 0;
 	int redirty = 0;
 
 	inode_should_defrag(BTRFS_I(inode), start, end, end - start + 1,
@@ -619,7 +619,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 		 */
 		total_in = ALIGN(total_in, PAGE_SIZE);
 		if (total_compressed + blocksize <= total_in) {
-			*num_added += 1;
+			compressed_extents += 1;
 
 			/*
 			 * The async work queues will take care of doing actual
@@ -636,7 +636,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 				cond_resched();
 				goto again;
 			}
-			return;
+			return compressed_extents;
 		}
 	}
 	if (pages) {
@@ -675,9 +675,9 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 		extent_range_redirty_for_io(inode, start, end);
 	add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
 			 BTRFS_COMPRESS_NONE);
-	*num_added += 1;
+	compressed_extents += 1;
 
-	return;
+	return compressed_extents;
 
 free_pages_out:
 	for (i = 0; i < nr_pages; i++) {
@@ -685,6 +685,8 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
 		put_page(pages[i]);
 	}
 	kfree(pages);
+
+	return 0;
 }
 
 static void free_async_extent_pages(struct async_extent *async_extent)
@@ -1122,12 +1124,12 @@ static noinline int cow_file_range(struct inode *inode,
 static noinline void async_cow_start(struct btrfs_work *work)
 {
 	struct async_chunk *async_chunk;
-	int num_added = 0;
+	int compressed_extents = 0;
 
 	async_chunk = container_of(work, struct async_chunk, work);
 
-	compress_file_range(async_chunk, &num_added);
-	if (num_added == 0) {
+	compressed_extents = compress_file_range(async_chunk);
+	if (compressed_extents == 0) {
 		btrfs_add_delayed_iput(async_chunk->inode);
 		async_chunk->inode = NULL;
 	}
Reviewed-by on v1 1/2
#5 lore raw
In reply to Nikolay Borisov
Quoted 6 lines · Nikolay Borisov

compress_file_range returns a void, yet uses a function parameter as a return value. Make that more idiomatic by simply returning the number of compressed extents directly. Also track such extents in more aptly named variables. No functional changes

Looks good.

Quoted 82 lines
---
  fs/btrfs/inode.c | 20 +++++++++++---------
  1 file changed, 11 insertions(+), 9 deletions(-)
fs/btrfs/inode.c +11 -9
index 4e183c2d3555..3b0bf5ea9eb6 100644
@@ -440,8 +440,7 @@ static inline void inode_should_defrag(struct btrfs_inode *inode,
   * are written in the same order that the flusher thread sent them
   * down.
   */
-static noinline void compress_file_range(struct async_chunk *async_chunk,
-					 int *num_added)
+static noinline int compress_file_range(struct async_chunk *async_chunk)
  {
  	struct inode *inode = async_chunk->inode;
  	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
@@ -457,6 +456,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
  	int i;
  	int will_compress;
  	int compress_type = fs_info->compress_type;
+	int compressed_extents = 0;
  	int redirty = 0;
 
  	inode_should_defrag(BTRFS_I(inode), start, end, end - start + 1,
@@ -619,7 +619,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
  		 */
  		total_in = ALIGN(total_in, PAGE_SIZE);
  		if (total_compressed + blocksize <= total_in) {
-			*num_added += 1;
+			compressed_extents += 1;
 
  			/*
  			 * The async work queues will take care of doing actual
@@ -636,7 +636,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
  				cond_resched();
  				goto again;
  			}
-			return;
+			return compressed_extents;
  		}
  	}
  	if (pages) {
@@ -675,9 +675,9 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
  		extent_range_redirty_for_io(inode, start, end);
  	add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
  			 BTRFS_COMPRESS_NONE);
-	*num_added += 1;
+	compressed_extents += 1;
 
-	return;
+	return compressed_extents;
 
  free_pages_out:
  	for (i = 0; i < nr_pages; i++) {
@@ -685,6 +685,8 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
  		put_page(pages[i]);
  	}
  	kfree(pages);
+
+	return 0;
  }
 
  static void free_async_extent_pages(struct async_extent *async_extent)
@@ -1122,12 +1124,12 @@ static noinline int cow_file_range(struct inode *inode,
  static noinline void async_cow_start(struct btrfs_work *work)
  {
  	struct async_chunk *async_chunk;
-	int num_added = 0;
+	int compressed_extents = 0;
 
  	async_chunk = container_of(work, struct async_chunk, work);
 
-	compress_file_range(async_chunk, &num_added);
-	if (num_added == 0) {
+	compressed_extents = compress_file_range(async_chunk);
+	if (compressed_extents == 0) {
  		btrfs_add_delayed_iput(async_chunk->inode);
  		async_chunk->inode = NULL;
  	}