linux-bcache.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: linux-bcache-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org,
	neilb-l3A5Bk7waGM@public.gmane.org,
	Vivek Goyal <vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH v2 03/26] block: Refactor blk_update_request()
Date: Thu, 20 Sep 2012 16:50:16 -0700	[thread overview]
Message-ID: <20120920235016.GG5519@google.com> (raw)
In-Reply-To: <20120920234133.GM7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>

On Thu, Sep 20, 2012 at 04:41:33PM -0700, Tejun Heo wrote:
> Hey,
> 
> On Thu, Sep 20, 2012 at 04:36:32PM -0700, Kent Overstreet wrote:
> > > Other than that, I definitely like this.  It would be nice to note
> > > that the custom partial bio advancing in blk_update_request() is
> > > replaced with multiple calls to req_bio_endio().  I don't think it has
> > > any meaningful performance implications.  It's just nice to future
> > > readers of the commit.
> > 
> > The number of calls to req_bio_endio() isn't changing...
> > blk_update_request() called it for partial completions before. It's just
> > where the bio itself is updated that's getting shuffled around.
> >
> > Or did you mean that bio_advance() is getting called on every bio
> > instead of the custom advancing in blk_update_request() before? That is
> > different, yeah - it's now always looping over the iovec, not just for
> > partial completions.
> > 
> > Yeah, I will note that in the commit message, in case Jens sees a
> > performance regression from it :)
> 
> I don't think there's any performance implication.  It's just nice to
> explain how the complexity went away.  If for nothing else, to point
> out how silly the original code was. :)

New patch below - that commit message have what you're after?

> > > Also, it would be really nice if you can verify this actually works
> > > with partial blk_update_request().  sector update bug in the previous
> > > patch scares me a bit.  Implementing some debug hacks in the
> > > completion path might be the easiest way to verify.  A subtle bug here
> > > could be pretty painful.
> > 
> > Any suggestions on how to trigger partial updates?
> 
> ide along with many legacy drivers do it.  Any SCSI driver including
> libata only does full completion.  I don't know.  Even just trying to
> call the function and comparing before & after with the original code
> would be good.  I'd like to see at least some form of verification
> because the manifested bugs could be extremely nasty and difficult to
> track down.

Multiple partial completions should have the same semantics as a single
full completion, so maybe I'll try rigging up some test code that wraps
blk_update_request(), turning full completions into partial completions,
and verifies stuff...


commit fef0ddc82214f87de71ec6fb051eb28a6de0be74
Author: Kent Overstreet <koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
Date:   Thu Sep 20 16:38:30 2012 -0700

    block: Refactor blk_update_request()
    
    Converts it to use bio_advance(), simplifying it quite a bit in the
    process.
    
    Note that req_bio_endio() now always calls bio_advance() - which means
    it always loops over the biovec, not just on partial completions. Don't
    expect it to affect performance, but worth noting.
    
    Signed-off-by: Kent Overstreet <koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
    CC: Jens Axboe <axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org>

diff --git a/block/blk-core.c b/block/blk-core.c
index 2d739ca..9f8cb16 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -158,20 +158,10 @@ static void req_bio_endio(struct request *rq, struct bio *bio,
 	else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
 		error = -EIO;
 
-	if (unlikely(nbytes > bio->bi_size)) {
-		printk(KERN_ERR "%s: want %u bytes done, %u left\n",
-		       __func__, nbytes, bio->bi_size);
-		nbytes = bio->bi_size;
-	}
-
 	if (unlikely(rq->cmd_flags & REQ_QUIET))
 		set_bit(BIO_QUIET, &bio->bi_flags);
 
-	bio->bi_size -= nbytes;
-	bio->bi_sector += (nbytes >> 9);
-
-	if (bio_integrity(bio))
-		bio_integrity_advance(bio, nbytes);
+	bio_advance(bio, nbytes);
 
 	/* don't actually finish bio if it's part of flush sequence */
 	if (bio->bi_size == 0 && !(rq->cmd_flags & REQ_FLUSH_SEQ))
@@ -2214,8 +2204,7 @@ EXPORT_SYMBOL(blk_fetch_request);
  **/
 bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
 {
-	int total_bytes, bio_nbytes, next_idx = 0;
-	struct bio *bio;
+	int total_bytes;
 
 	if (!req->bio)
 		return false;
@@ -2259,56 +2248,21 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
 
 	blk_account_io_completion(req, nr_bytes);
 
-	total_bytes = bio_nbytes = 0;
-	while ((bio = req->bio) != NULL) {
-		int nbytes;
+	total_bytes = 0;
+	while (req->bio) {
+		struct bio *bio = req->bio;
+		unsigned bio_bytes = min(bio->bi_size, nr_bytes);
 
-		if (nr_bytes >= bio->bi_size) {
+		if (bio_bytes == bio->bi_size)
 			req->bio = bio->bi_next;
-			nbytes = bio->bi_size;
-			req_bio_endio(req, bio, nbytes, error);
-			next_idx = 0;
-			bio_nbytes = 0;
-		} else {
-			int idx = bio->bi_idx + next_idx;
-
-			if (unlikely(idx >= bio->bi_vcnt)) {
-				blk_dump_rq_flags(req, "__end_that");
-				printk(KERN_ERR "%s: bio idx %d >= vcnt %d\n",
-				       __func__, idx, bio->bi_vcnt);
-				break;
-			}
-
-			nbytes = bio_iovec_idx(bio, idx)->bv_len;
-			BIO_BUG_ON(nbytes > bio->bi_size);
-
-			/*
-			 * not a complete bvec done
-			 */
-			if (unlikely(nbytes > nr_bytes)) {
-				bio_nbytes += nr_bytes;
-				total_bytes += nr_bytes;
-				break;
-			}
 
-			/*
-			 * advance to the next vector
-			 */
-			next_idx++;
-			bio_nbytes += nbytes;
-		}
+		req_bio_endio(req, bio, bio_bytes, error);
 
-		total_bytes += nbytes;
-		nr_bytes -= nbytes;
+		total_bytes += bio_bytes;
+		nr_bytes -= bio_bytes;
 
-		bio = req->bio;
-		if (bio) {
-			/*
-			 * end more in this run, or just return 'not-done'
-			 */
-			if (unlikely(nr_bytes <= 0))
-				break;
-		}
+		if (!nr_bytes)
+			break;
 	}
 
 	/*
@@ -2324,16 +2278,6 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
 		return false;
 	}
 
-	/*
-	 * if the request wasn't completed, update state
-	 */
-	if (bio_nbytes) {
-		req_bio_endio(req, bio, bio_nbytes, error);
-		bio->bi_idx += next_idx;
-		bio_iovec(bio)->bv_offset += nr_bytes;
-		bio_iovec(bio)->bv_len -= nr_bytes;
-	}
-
 	req->__data_len -= total_bytes;
 	req->buffer = bio_data(req->bio);
 

  parent reply	other threads:[~2012-09-20 23:50 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-11  0:22 [PATCH v2 00/26] Prep work for immutable bio vecs Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 01/26] block: Convert integrity to bvec_alloc_bs(), and a bugfix Kent Overstreet
     [not found]   ` <1347322957-25260-2-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11 20:36     ` [dm-devel] " Vivek Goyal
2012-09-11 20:48       ` Kent Overstreet
2012-09-11 22:07       ` Kent Overstreet
     [not found]         ` <20120911220750.GM19739-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-12 19:39           ` Martin K. Petersen
     [not found]             ` <yq1wqzzrpy1.fsf-+q57XtR/GgMb6DWv4sQWN6xOck334EZe@public.gmane.org>
2012-09-17 21:08               ` Kent Overstreet
2012-09-20 21:53     ` Tejun Heo
2012-09-11  0:22 ` [PATCH v2 02/26] block: Add bio_advance() Kent Overstreet
     [not found]   ` <1347322957-25260-3-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 21:58     ` Tejun Heo
2012-09-20 23:13       ` Kent Overstreet
     [not found]         ` <20120920231308.GB5519-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:25           ` Tejun Heo
     [not found]             ` <20120920232506.GI7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:38               ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 03/26] block: Refactor blk_update_request() Kent Overstreet
     [not found]   ` <1347322957-25260-4-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:20     ` Tejun Heo
2012-09-20 23:36       ` Kent Overstreet
     [not found]         ` <20120920233632.GC5519-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:41           ` Tejun Heo
     [not found]             ` <20120920234133.GM7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:50               ` Kent Overstreet [this message]
2012-09-11  0:22 ` [PATCH v2 04/26] md: Convert md_trim_bio() to use bio_advance() Kent Overstreet
     [not found]   ` <1347322957-25260-5-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:27     ` Tejun Heo
2012-09-11  0:22 ` [PATCH v2 05/26] block: Add bio_end() Kent Overstreet
     [not found]   ` <1347322957-25260-6-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-17  9:17     ` Steven Whitehouse
2012-09-20 23:32     ` Tejun Heo
     [not found]       ` <20120920233225.GK7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:44         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 06/26] block: Use bio_sectors() more consistently Kent Overstreet
     [not found]   ` <1347322957-25260-7-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:36     ` Tejun Heo
     [not found]       ` <20120920233618.GL7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:47         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 07/26] block: Don't use bi_idx in bio_split() or require it to be 0 Kent Overstreet
     [not found]   ` <1347322957-25260-8-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:45     ` Tejun Heo
     [not found]       ` <20120920234544.GN7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:00         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 09/26] block: Remove some unnecessary bi_vcnt usage Kent Overstreet
     [not found]   ` <1347322957-25260-10-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:51     ` Tejun Heo
2012-09-11  0:22 ` [PATCH v2 10/26] block: Add submit_bio_wait(), remove from md Kent Overstreet
     [not found]   ` <1347322957-25260-11-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:56     ` Tejun Heo
     [not found]       ` <20120920235643.GQ7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:06         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 11/26] raid10: Use bio_reset() Kent Overstreet
2012-09-20 23:59   ` Tejun Heo
2012-09-11  0:22 ` [PATCH v2 13/26] raid5: use bio_reset() Kent Overstreet
     [not found]   ` <1347322957-25260-14-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11  5:03     ` NeilBrown
     [not found]       ` <20120911150326.79f066c0-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org>
2012-09-11 19:26         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 14/26] raid1: Refactor narrow_write_error() to not use bi_idx Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 15/26] block: Add bio_copy_data() Kent Overstreet
     [not found]   ` <1347322957-25260-16-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:06     ` Tejun Heo
2012-09-21  0:09       ` Kent Overstreet
     [not found]         ` <20120921000945.GK5519-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:15           ` Tejun Heo
2012-09-21  0:09       ` Tejun Heo
     [not found]         ` <20120921000947.GT7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:13           ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 16/26] pktcdvd: use bio_copy_data() Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 17/26] pktcdvd: Use bio_reset() in disabled code to kill bi_idx usage Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 18/26] raid1: use bio_copy_data() Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 20/26] block: Add bio_for_each_segment_all() Kent Overstreet
     [not found]   ` <1347322957-25260-21-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:35     ` Tejun Heo
2012-09-11  0:22 ` [PATCH v2 22/26] block: Add bio_alloc_pages() Kent Overstreet
     [not found]   ` <1347322957-25260-23-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:47     ` Tejun Heo
     [not found]       ` <20120921004711.GZ7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  4:50         ` Kent Overstreet
2012-09-11  0:22 ` [PATCH v2 24/26] block: Add an explicit bio flag for bios that own their bvec Kent Overstreet
     [not found] ` <1347322957-25260-1-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11  0:22   ` [PATCH v2 08/26] block: Remove bi_idx references Kent Overstreet
     [not found]     ` <1347322957-25260-9-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-20 23:49       ` Tejun Heo
2012-09-21  0:04         ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 12/26] raid1: use bio_reset() Kent Overstreet
     [not found]     ` <1347322957-25260-13-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11  4:59       ` NeilBrown
2012-09-11 18:28         ` Kent Overstreet
     [not found]           ` <20120911182825.GG19739-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-11 21:17             ` NeilBrown
2012-09-11  0:22   ` [PATCH v2 19/26] bounce: Refactor __blk_queue_bounce to not use bi_io_vec Kent Overstreet
     [not found]     ` <1347322957-25260-20-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:25       ` Tejun Heo
2012-09-21  0:29         ` Kent Overstreet
2012-09-21  0:27       ` Tejun Heo
2012-09-21  0:34         ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 21/26] block: Convert some code to bio_for_each_segment_all() Kent Overstreet
     [not found]     ` <1347322957-25260-22-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:38       ` Tejun Heo
     [not found]         ` <20120921003832.GY7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:50           ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 23/26] raid1: use bio_alloc_pages() Kent Overstreet
     [not found]     ` <1347322957-25260-24-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  0:48       ` Tejun Heo
     [not found]         ` <20120921004827.GA7264-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-21  4:51           ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 25/26] bio-integrity: Add explicit field for owner of bip_buf Kent Overstreet
     [not found]     ` <1347322957-25260-26-git-send-email-koverstreet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2012-09-12 19:41       ` Martin K. Petersen
     [not found]         ` <yq1sjanrpu7.fsf-+q57XtR/GgMb6DWv4sQWN6xOck334EZe@public.gmane.org>
2012-09-17 21:09           ` Kent Overstreet
2012-09-11  0:22   ` [PATCH v2 26/26] block: Add BIO_SUBMITTED flag, kill BIO_CLONED Kent Overstreet
2012-09-11  5:22   ` [PATCH v2 00/26] Prep work for immutable bio vecs NeilBrown
2012-09-20 23:22 ` Tejun Heo
2012-10-15 20:08 [PATCH v4 00/24] " Kent Overstreet
2012-10-15 20:09 ` [PATCH v2 03/26] block: Refactor blk_update_request() Kent Overstreet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120920235016.GG5519@google.com \
    --to=koverstreet-hpiqsd4aklfqt0dzr+alfa@public.gmane.org \
    --cc=axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org \
    --cc=dm-devel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=linux-bcache-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=neilb-l3A5Bk7waGM@public.gmane.org \
    --cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).