Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6312047imm; Wed, 27 Jun 2018 05:52:49 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKJ2v/ZxzCEgRFH5pDlphiucoo5+S5Q/AyQU1xwiHUp0PvbBlIv2tYgQRrgUBgLCqFLEubQ X-Received: by 2002:a65:4081:: with SMTP id t1-v6mr5125421pgp.32.1530103969154; Wed, 27 Jun 2018 05:52:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530103969; cv=none; d=google.com; s=arc-20160816; b=HeOaFDMxBLysz6BxNPQ4/lXBcIbxBg1UrMUGCnmeh4SocvnYaoQ8FwGXeDTlpBiFEh tw4oTITCkOHtpOaRZohte33IEuJmikvbHZSPH3t2QUW3dXlvYvRy2gweTs0I5wmG050r hHzDgEBmx+KUiuGJLVoIIzocFixMdRbPBGabsFtPNMUW4XBS2t9/GNrIF4Ww6c5tnOXF PeOxOQ6GJJDxRdqp44LaBhvgZ26L6meqK8aPO2KYCt6jsuK2XkuDdO4Gnnu4r9ztG2Bi OFc3J+FoOtmsGTAhb7lTFKvAdOg4x0rBWVh2urN3qqdjx1iI5R+tjgrjrBjet06ZXvH+ RxhA== 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:arc-authentication-results; bh=5ZBNt58hf1SD5wVcC/xHS38Iko7a929ZeiycD4fV5mE=; b=oOLAGjbGYEAURGeAMK9LWjFxzrXmKCOUSm9sEdbinSgasgtx6xHKp5FQFQNdMFL96v JXIjhgD088uy/Kwj170hpRV0HEUixkorBIajIx7gVJzdCc84pqNFBvU5DWgxiz5SouRu 2/SSoIuhh+EkKJSTccwU46/PYLZgfjAEGJRIr5vJe4yblzsXd2r7CIH6pNc43AirkVi6 EyRVFHmzxTb+aZEjiZYr+XE698NtWYmcVyfSzgeNJRY6fWDB5lawwh7jxyjMSmT8fl8z q0K5ACalx9KrUqsel8FCnFwdoq6yjKR7t2Pb/vk4DPlqND2unokQ66Q/R/LA2HxplyrW alpg== 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 a9-v6si3449535pgf.380.2018.06.27.05.52.34; Wed, 27 Jun 2018 05:52:49 -0700 (PDT) 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 S965294AbeF0Mtu (ORCPT + 99 others); Wed, 27 Jun 2018 08:49:50 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39310 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932312AbeF0Mtr (ORCPT ); Wed, 27 Jun 2018 08:49:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 530604021CC1; Wed, 27 Jun 2018 12:49:46 +0000 (UTC) Received: from localhost (ovpn-12-44.pek2.redhat.com [10.72.12.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC2B72156888; Wed, 27 Jun 2018 12:49:37 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Kent Overstreet Cc: David Sterba , Huang Ying , Mike Snitzer , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , "Darrick J . Wong" , Coly Li , Filipe Manana , Randy Dunlap , Ming Lei Subject: [PATCH V7 19/24] block: loop: pass multipage bvec to iov_iter Date: Wed, 27 Jun 2018 20:45:43 +0800 Message-Id: <20180627124548.3456-20-ming.lei@redhat.com> In-Reply-To: <20180627124548.3456-1-ming.lei@redhat.com> References: <20180627124548.3456-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 27 Jun 2018 12:49:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 27 Jun 2018 12:49:46 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org iov_iter is implemented with bvec itererator, so it is safe to pass multipage 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 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index d6b6f434fd4b..a350b323e891 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -515,16 +515,16 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, struct bio *bio = rq->bio; struct file *file = lo->lo_backing_file; unsigned int offset; - int segments = 0; + int nr_bvec = 0; int ret; if (rq->bio != rq->biotail) { - struct req_iterator iter; + struct bvec_iter iter; struct bio_vec tmp; __rq_for_each_bio(bio, rq) - segments += bio_segments(bio); - bvec = kmalloc_array(segments, sizeof(struct bio_vec), + nr_bvec += bio_bvecs(bio); + bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), GFP_NOIO); if (!bvec) return -EIO; @@ -533,13 +533,14 @@ 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 bio_for_each_bvec * API will take care of all details for us. */ - rq_for_each_segment(tmp, rq, iter) { - *bvec = tmp; - bvec++; - } + __rq_for_each_bio(bio, rq) + bio_for_each_bvec(tmp, bio, iter) { + *bvec = tmp; + bvec++; + } bvec = cmd->bvec; offset = 0; } else { @@ -550,12 +551,11 @@ 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); + nr_bvec = bio_bvecs(bio); } atomic_set(&cmd->ref, 2); - iov_iter_bvec(&iter, ITER_BVEC | rw, bvec, - segments, blk_rq_bytes(rq)); + iov_iter_bvec(&iter, ITER_BVEC | rw, bvec, nr_bvec, blk_rq_bytes(rq)); iter.iov_offset = offset; cmd->iocb.ki_pos = pos; -- 2.9.5