From patchwork Mon Oct 15 20:08:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1595601 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by patchwork2.kernel.org (Postfix) with ESMTP id 332E8DFB34 for ; Mon, 15 Oct 2012 20:13:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FKA0Fb006646; Mon, 15 Oct 2012 16:10:00 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FK9wRU026906 for ; Mon, 15 Oct 2012 16:09:58 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9FK9rMa023810 for ; Mon, 15 Oct 2012 16:09:53 -0400 Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9FK9gLq018944 for ; Mon, 15 Oct 2012 16:09:45 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so5214108pad.33 for ; Mon, 15 Oct 2012 13:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=+3DiSPfCSiUXbMPlsczm0TD1EEZgQLajkOCJU9Dj304=; b=AXH69bLVNRayaEsM30QCrgexPOthz17XCZThQJJhCgUfx571iZ/K+KHxfETyBNdyTK G2gPROWN1XBzRPIcaulab7fr4fikwdql1kpJlBPzj50q8/wUxHZl8nlTcqQsKhRyOVYr PAaPX0qbMhVryRBiCLMFwERa47AQq8iB8p/QlCWzu3+7OA1VR5gZp7Waproh6JPRK6u/ JXkhGrM0IGl62k4iAgQ/2wdns5tJcy2VR6GwNp+HYzIphiUi+vtzLjgHRKjNZQkLwRDF VPvmTvVz5rRBCGxmaMVAjpSnSTVGeoqUEOgmjMLkUFQCPTKPNLgMM2fbZfctTFaV/fuN 3ZkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=+3DiSPfCSiUXbMPlsczm0TD1EEZgQLajkOCJU9Dj304=; b=n50rmOcXavtfQjWewlM2G1uMTmOsts4nxsPgum8Bu4HruZhKOvnmAngHYfcLvISVpA 6WqSwBQ4PFboDAkDrfAd3R9i7LtcnZPdjlu7aak1q/0jve7MG6Dj0Jbsj0LYyLH17GHT 6ZV8De4r6ogmJ6+eP7qxxEAu0ikGxt5o3PlKADrYZBHG576Oi/njdAUWU7ysnf/8mKeT OHrqr75G1PqvaSULzeERkx48XjV7VI65ZcBYK3iTLjD2szS0MxpnYrno6J4CL4HYuwDk 8tEh9t06bp0ZcpgQa6nOQdByyhnzB5hA4Ljq/wkLE0UmCvl9/u+IN1irKEhFlZ51HV3U pLYw== Received: by 10.68.212.74 with SMTP id ni10mr40366169pbc.20.1350331785545; Mon, 15 Oct 2012 13:09:45 -0700 (PDT) Received: from formenos.mtv.corp.google.com (formenos.mtv.corp.google.com [172.18.110.66]) by mx.google.com with ESMTPS id k9sm3021703paz.22.2012.10.15.13.09.44 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 13:09:44 -0700 (PDT) From: Kent Overstreet To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Date: Mon, 15 Oct 2012 13:08:36 -0700 Message-Id: <1350331769-14856-3-git-send-email-koverstreet@google.com> In-Reply-To: <1350331769-14856-1-git-send-email-koverstreet@google.com> References: <1350331769-14856-1-git-send-email-koverstreet@google.com> X-Gm-Message-State: ALoCoQme/kJq3uE7rMJECkjh+wfIk6X27Hol4vEcWPH9MUSJOQw45ge9vpYcGJIXNNS9cqXbsboPkSrGkmugNSEGMmyasAbdhD/ZiIs4ha7tFgV6vg48taEjg6JxCUnJ09RddAnyjafj5mnvmc6Ky6GM0gxKv3zfGOdxvxeHqr22vszCXo2FHhTPagYQVW674TLzEwrZ4dq6 X-RedHat-Spam-Score: -3.072 (BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.21 X-loop: dm-devel@redhat.com Cc: tj@kernel.org, axboe@kernel.dk, Kent Overstreet , vgoyal@redhat.com Subject: [dm-devel] [PATCH v4 02/24] block: Refactor blk_update_request() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com 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. Tested it by forcing partial updates, and dumping before and after on various bio/bvec fields when doing a partial update. Signed-off-by: Kent Overstreet CC: Jens Axboe --- block/blk-core.c | 80 +++++++++----------------------------------------------- 1 file changed, 12 insertions(+), 68 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index a17869f..a8a1a9e 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)) @@ -2219,8 +2209,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; @@ -2264,56 +2253,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; } /* @@ -2329,16 +2283,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);