Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1491803imu; Tue, 20 Nov 2018 19:28:41 -0800 (PST) X-Google-Smtp-Source: AJdET5cjjrrTt82mDUAY1xrXxODZX3spco/suAdRPIa5uSz4c+yghn6SYZ1njT1UwHlP0/UMcjkh X-Received: by 2002:aa7:87ce:: with SMTP id i14mr5032534pfo.20.1542770921115; Tue, 20 Nov 2018 19:28:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542770921; cv=none; d=google.com; s=arc-20160816; b=mrSutY5CH6GS2w7WwElxwJA+WqxcRZkYZfQzDI3NGtELd73sKWDgZnMFddQLBzJ395 c9MylPaepXObEz0t1tcVwn4Ii27pJz41Wncy4qp0x++c0OWGbzKV6Jg+GJmtQPUIimP6 ioNrpEV+oxf56JZ1655zQZsOdLg70hoDXckp07p5/W6O1Io5gWROniomqChRETa3zH0o F2Fw3MCBjwevZ97UKzQp3zGPpk7A86RHXObnIHZulcPAUdOV9FZgSGR/IhZDLFhKT4l3 7awYxw0hIhD4/EhWsXoZ0e42adAN1cAPKyuFN4Glv9wWlJuHlv0Mf15gZebT2jY81msB Avcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=TSBLWrtYdTLJ/i/PjrMa6QoZNwXwGBQxVHczPRHzxZo=; b=dAtWPVhhFiBzJhOjAMAWwXswElI0O37/O0R/oMKS5alsFUhprQ8dDvo+8IrJf9f8If logqKJKZBwbNpqcFKlrW8Sz1dDf3CORltcsvYoS0Ou6GxuVFrEDuBgJLw4CP9YHzV1BA n3LFHUk3y0sGKzEsErGjbhv3TJIdxreH1bEVO3eiwfL1i3lwoh3Ij3KXLCe2jD8W2kRp fS6iref5+581uqFA+b4qVMBtwOO4TCWYkz83xMJYyR6sC3GJ2stQ0slq3CnLX1/cGIJo /eX6wjX8RDEkgbtvqdMboZw43tc3mG+LbRh3RO7JmDB20WSinJ8eU8ZbYuGSt8ezWHUN qKFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k5si44133655pgr.69.2018.11.20.19.28.26; Tue, 20 Nov 2018 19:28:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728006AbeKUN7s (ORCPT + 99 others); Wed, 21 Nov 2018 08:59:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46666 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727069AbeKUN7r (ORCPT ); Wed, 21 Nov 2018 08:59:47 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CB3E30B2537; Wed, 21 Nov 2018 03:27:16 +0000 (UTC) Received: from localhost (ovpn-8-21.pek2.redhat.com [10.72.8.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 991F47D2F2; Wed, 21 Nov 2018 03:27:01 +0000 (UTC) From: Ming Lei To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , Omar Sandoval , Sagi Grimberg , Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com, Ming Lei Subject: [PATCH V11 10/19] block: loop: pass multi-page bvec to iov_iter Date: Wed, 21 Nov 2018 11:23:18 +0800 Message-Id: <20181121032327.8434-11-ming.lei@redhat.com> In-Reply-To: <20181121032327.8434-1-ming.lei@redhat.com> References: <20181121032327.8434-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 21 Nov 2018 03:27:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org iov_iter is implemented on bvec itererator helpers, so it is safe to pass multi-page bvec to it, and this way is much more efficient than passing one page in each bvec. Signed-off-by: Ming Lei --- drivers/block/loop.c | 20 ++++++++++---------- include/linux/blkdev.h | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 176ab1f28eca..e3683211f12d 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -510,21 +510,22 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, loff_t pos, bool rw) { struct iov_iter iter; + struct req_iterator rq_iter; struct bio_vec *bvec; struct request *rq = blk_mq_rq_from_pdu(cmd); struct bio *bio = rq->bio; struct file *file = lo->lo_backing_file; + struct bio_vec tmp; unsigned int offset; - int segments = 0; + int nr_bvec = 0; int ret; + rq_for_each_bvec(tmp, rq, rq_iter) + nr_bvec++; + if (rq->bio != rq->biotail) { - struct req_iterator iter; - struct bio_vec tmp; - __rq_for_each_bio(bio, rq) - segments += bio_segments(bio); - bvec = kmalloc_array(segments, sizeof(struct bio_vec), + bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), GFP_NOIO); if (!bvec) return -EIO; @@ -533,10 +534,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, /* * The bios of the request may be started from the middle of * the 'bvec' because of bio splitting, so we can't directly - * copy bio->bi_iov_vec to new bvec. The rq_for_each_segment + * copy bio->bi_iov_vec to new bvec. The rq_for_each_bvec * API will take care of all details for us. */ - rq_for_each_segment(tmp, rq, iter) { + rq_for_each_bvec(tmp, rq, rq_iter) { *bvec = tmp; bvec++; } @@ -550,11 +551,10 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, */ offset = bio->bi_iter.bi_bvec_done; bvec = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter); - segments = bio_segments(bio); } atomic_set(&cmd->ref, 2); - iov_iter_bvec(&iter, rw, bvec, segments, blk_rq_bytes(rq)); + iov_iter_bvec(&iter, rw, bvec, nr_bvec, blk_rq_bytes(rq)); iter.iov_offset = offset; cmd->iocb.ki_pos = pos; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 1ad6eafc43f2..a281b6737b61 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -805,6 +805,10 @@ struct req_iterator { __rq_for_each_bio(_iter.bio, _rq) \ bio_for_each_segment(bvl, _iter.bio, _iter.iter) +#define rq_for_each_bvec(bvl, _rq, _iter) \ + __rq_for_each_bio(_iter.bio, _rq) \ + bio_for_each_bvec(bvl, _iter.bio, _iter.iter) + #define rq_iter_last(bvec, _iter) \ (_iter.bio->bi_next == NULL && \ bio_iter_last(bvec, _iter.iter)) -- 2.9.5