linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Cleanup of bio_get/set
@ 2017-12-13  8:25 Nikolay Borisov
  2017-12-13  8:25 ` [PATCH 1/4] btrfs: Remove redundant bio_get/set calls in compressed read/write paths Nikolay Borisov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Nikolay Borisov @ 2017-12-13  8:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

Hello, 

Here is a series which cleans the btrfs source code of all the redundant 
bio_get/set calls. After it's applied there is only a single bio_get inovcation
left in __alloc_device for the flush_bio (and that is wrong since it 
leaks the bio, but this will be fixed in a follow up fix).

Nikolay Borisov (4):
  btrfs: Remove redundant bio_get/set calls in compressed read/write
    paths
  btrfs: Remove redundant bio_get/set from submit_dio_repair_bio
  btrfs: Remove redundan bio_get/bio_set pair from submit_one_bio
  btrfs: Remove redundant pair of bio_get/set in __btrfs_submit_dio_bio

 fs/btrfs/compression.c | 12 ------------
 fs/btrfs/extent_io.c   |  2 --
 fs/btrfs/inode.c       | 10 ++--------
 3 files changed, 2 insertions(+), 22 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] btrfs: Remove redundant bio_get/set calls in compressed read/write paths
  2017-12-13  8:25 [PATCH 0/4] Cleanup of bio_get/set Nikolay Borisov
@ 2017-12-13  8:25 ` Nikolay Borisov
  2017-12-13  8:25 ` [PATCH 2/4] btrfs: Remove redundant bio_get/set from submit_dio_repair_bio Nikolay Borisov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2017-12-13  8:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

bio_get/set is necessary only if the bio is going to be referenced
following submissions. In the code paths where such calls are made
we don't really need them since the bio is referenced only if
btrfs_map_bio returns an error. And this function can return an error
prior to submission only. So referencing the bio is safe. Furthermore
we do call bio_endio which will consume the last reference. So let's
remove the redundant calls.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/compression.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 9e06a052be60..93779bab5a61 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -362,8 +362,6 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
 		page->mapping = NULL;
 		if (submit || bio_add_page(bio, page, PAGE_SIZE, 0) <
 		    PAGE_SIZE) {
-			bio_get(bio);
-
 			/*
 			 * inc the count before we submit the bio so
 			 * we know the end IO handler won't happen before
@@ -386,8 +384,6 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
 				bio_endio(bio);
 			}
 
-			bio_put(bio);
-
 			bio = btrfs_bio_alloc(bdev, first_byte);
 			bio->bi_opf = REQ_OP_WRITE | write_flags;
 			bio->bi_private = cb;
@@ -403,7 +399,6 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
 		first_byte += PAGE_SIZE;
 		cond_resched();
 	}
-	bio_get(bio);
 
 	ret = btrfs_bio_wq_end_io(fs_info, bio, BTRFS_WQ_ENDIO_DATA);
 	BUG_ON(ret); /* -ENOMEM */
@@ -419,7 +414,6 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
 		bio_endio(bio);
 	}
 
-	bio_put(bio);
 	return 0;
 }
 
@@ -652,8 +646,6 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
 		page->mapping = NULL;
 		if (submit || bio_add_page(comp_bio, page, PAGE_SIZE, 0) <
 		    PAGE_SIZE) {
-			bio_get(comp_bio);
-
 			ret = btrfs_bio_wq_end_io(fs_info, comp_bio,
 						  BTRFS_WQ_ENDIO_DATA);
 			BUG_ON(ret); /* -ENOMEM */
@@ -680,8 +672,6 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
 				bio_endio(comp_bio);
 			}
 
-			bio_put(comp_bio);
-
 			comp_bio = btrfs_bio_alloc(bdev, cur_disk_byte);
 			bio_set_op_attrs(comp_bio, REQ_OP_READ, 0);
 			comp_bio->bi_private = cb;
@@ -691,7 +681,6 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
 		}
 		cur_disk_byte += PAGE_SIZE;
 	}
-	bio_get(comp_bio);
 
 	ret = btrfs_bio_wq_end_io(fs_info, comp_bio, BTRFS_WQ_ENDIO_DATA);
 	BUG_ON(ret); /* -ENOMEM */
@@ -707,7 +696,6 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
 		bio_endio(comp_bio);
 	}
 
-	bio_put(comp_bio);
 	return 0;
 
 fail2:
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] btrfs: Remove redundant bio_get/set from submit_dio_repair_bio
  2017-12-13  8:25 [PATCH 0/4] Cleanup of bio_get/set Nikolay Borisov
  2017-12-13  8:25 ` [PATCH 1/4] btrfs: Remove redundant bio_get/set calls in compressed read/write paths Nikolay Borisov
@ 2017-12-13  8:25 ` Nikolay Borisov
  2017-12-13  8:25 ` [PATCH 3/4] btrfs: Remove redundan bio_get/bio_set pair from submit_one_bio Nikolay Borisov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2017-12-13  8:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

The bio that is passsed is the newly created repair bio which already
has a reference count of 1, which is going to be consumed by the
endio routine on successful submission. On error the handler also
calls bio_put.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/inode.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 9ad8c9321c8f..6d2fe773d479 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7941,15 +7941,12 @@ static inline blk_status_t submit_dio_repair_bio(struct inode *inode,
 
 	BUG_ON(bio_op(bio) == REQ_OP_WRITE);
 
-	bio_get(bio);
-
 	ret = btrfs_bio_wq_end_io(fs_info, bio, BTRFS_WQ_ENDIO_DIO_REPAIR);
 	if (ret)
-		goto err;
+		return ret;
 
 	ret = btrfs_map_bio(fs_info, bio, mirror_num, 0);
-err:
-	bio_put(bio);
+
 	return ret;
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] btrfs: Remove redundan bio_get/bio_set pair from submit_one_bio
  2017-12-13  8:25 [PATCH 0/4] Cleanup of bio_get/set Nikolay Borisov
  2017-12-13  8:25 ` [PATCH 1/4] btrfs: Remove redundant bio_get/set calls in compressed read/write paths Nikolay Borisov
  2017-12-13  8:25 ` [PATCH 2/4] btrfs: Remove redundant bio_get/set from submit_dio_repair_bio Nikolay Borisov
@ 2017-12-13  8:25 ` Nikolay Borisov
  2017-12-13  8:25 ` [PATCH 4/4] btrfs: Remove redundant pair of bio_get/set in __btrfs_submit_dio_bio Nikolay Borisov
  2018-01-02 15:40 ` [PATCH 0/4] Cleanup of bio_get/set David Sterba
  4 siblings, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2017-12-13  8:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

The bio is never referenced after it has been submitted so there is no
point in getting an extra reference.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/extent_io.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 16ae832bdb5d..c2fe059f9c92 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2732,7 +2732,6 @@ static int __must_check submit_one_bio(struct bio *bio, int mirror_num,
 	start = page_offset(page) + bvec->bv_offset;
 
 	bio->bi_private = NULL;
-	bio_get(bio);
 
 	if (tree->ops)
 		ret = tree->ops->submit_bio_hook(tree->private_data, bio,
@@ -2740,7 +2739,6 @@ static int __must_check submit_one_bio(struct bio *bio, int mirror_num,
 	else
 		btrfsic_submit_bio(bio);
 
-	bio_put(bio);
 	return blk_status_to_errno(ret);
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] btrfs: Remove redundant pair of bio_get/set in __btrfs_submit_dio_bio
  2017-12-13  8:25 [PATCH 0/4] Cleanup of bio_get/set Nikolay Borisov
                   ` (2 preceding siblings ...)
  2017-12-13  8:25 ` [PATCH 3/4] btrfs: Remove redundan bio_get/bio_set pair from submit_one_bio Nikolay Borisov
@ 2017-12-13  8:25 ` Nikolay Borisov
  2018-01-02 15:40 ` [PATCH 0/4] Cleanup of bio_get/set David Sterba
  4 siblings, 0 replies; 6+ messages in thread
From: Nikolay Borisov @ 2017-12-13  8:25 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

The bio is not referenced after it has been submitted and the endio is
going to consume the sole reference on successful submission. On error,
the callers of __btrfs_submit_dio_bio do invoke bio_put so we don't
leak it either.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/inode.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 6d2fe773d479..692dbd2fc239 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8449,8 +8449,6 @@ __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, u64 file_offset,
 	if (async_submit)
 		async_submit = !atomic_read(&BTRFS_I(inode)->sync_writers);
 
-	bio_get(bio);
-
 	if (!write) {
 		ret = btrfs_bio_wq_end_io(fs_info, bio, BTRFS_WQ_ENDIO_DATA);
 		if (ret)
@@ -8483,7 +8481,6 @@ __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, u64 file_offset,
 map:
 	ret = btrfs_map_bio(fs_info, bio, 0, 0);
 err:
-	bio_put(bio);
 	return ret;
 }
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] Cleanup of bio_get/set
  2017-12-13  8:25 [PATCH 0/4] Cleanup of bio_get/set Nikolay Borisov
                   ` (3 preceding siblings ...)
  2017-12-13  8:25 ` [PATCH 4/4] btrfs: Remove redundant pair of bio_get/set in __btrfs_submit_dio_bio Nikolay Borisov
@ 2018-01-02 15:40 ` David Sterba
  4 siblings, 0 replies; 6+ messages in thread
From: David Sterba @ 2018-01-02 15:40 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs

On Wed, Dec 13, 2017 at 10:25:36AM +0200, Nikolay Borisov wrote:
> Hello, 
> 
> Here is a series which cleans the btrfs source code of all the redundant 
> bio_get/set calls. After it's applied there is only a single bio_get inovcation
> left in __alloc_device for the flush_bio (and that is wrong since it 
> leaks the bio, but this will be fixed in a follow up fix).
> 
> Nikolay Borisov (4):
>   btrfs: Remove redundant bio_get/set calls in compressed read/write
>     paths
>   btrfs: Remove redundant bio_get/set from submit_dio_repair_bio
>   btrfs: Remove redundan bio_get/bio_set pair from submit_one_bio
>   btrfs: Remove redundant pair of bio_get/set in __btrfs_submit_dio_bio

All

Reviewed-by: David Sterba <dsterba@suse.com>

and added to 4.16 queue.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-01-02 15:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-13  8:25 [PATCH 0/4] Cleanup of bio_get/set Nikolay Borisov
2017-12-13  8:25 ` [PATCH 1/4] btrfs: Remove redundant bio_get/set calls in compressed read/write paths Nikolay Borisov
2017-12-13  8:25 ` [PATCH 2/4] btrfs: Remove redundant bio_get/set from submit_dio_repair_bio Nikolay Borisov
2017-12-13  8:25 ` [PATCH 3/4] btrfs: Remove redundan bio_get/bio_set pair from submit_one_bio Nikolay Borisov
2017-12-13  8:25 ` [PATCH 4/4] btrfs: Remove redundant pair of bio_get/set in __btrfs_submit_dio_bio Nikolay Borisov
2018-01-02 15:40 ` [PATCH 0/4] Cleanup of bio_get/set David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).