From patchwork Mon Nov 26 02:17:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10697395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3F2469BA for ; Mon, 26 Nov 2018 02:20:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D56829A6F for ; Mon, 26 Nov 2018 02:20:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9147D29A89; Mon, 26 Nov 2018 02:20:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 915C429A52 for ; Mon, 26 Nov 2018 02:20:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52A5E6B3F7F; Sun, 25 Nov 2018 21:20:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4FF9B6B3F81; Sun, 25 Nov 2018 21:20:18 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C72F6B3F82; Sun, 25 Nov 2018 21:20:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id 117066B3F7F for ; Sun, 25 Nov 2018 21:20:18 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id y83so17872648qka.7 for ; Sun, 25 Nov 2018 18:20:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=iiHAK/QyTWLI6+6lI1iCedqrSnHhk/ms7RdzNo36y3M=; b=gOP9Y1fqZvNKozg9PrvhugmAAEtWV+helysvxeyWQ52SLLAeDdyBlfd5+GLV7a4fKX qwgR34n+jygGFzM4WuBV88IxGhJF76N04AyP/a2En7uVqm4FQKlQqFJqVSpnXa6cLqJf gpTKQbnnuiI4NHQedaO/4JpLbq1DbgILEaybI4+w97IxIaNs87SPJPWlY7j+bJhyY2MO vwTxaI/LL/GpfaSSGTdwFGMm9vSO5c2GVrDv9/dTzhjRlhSfhAcjwblD/zHtB/88PkuR WYQj930V64PAeao+t+28vIWg8mTz7Zuhl9B/GCCIPguZ9GSzUhRm9ajRqSpY6jwEzTgD ggKg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWYOOJVDN8Vwl6EMr8jZc0cT4fkV6lPQjwSdA48sNNpuwrHqWAqb iVZi7hTAiwYsS4k7aJ/meMXj5BDOfcj6yF9dZaMzU7UXWYKMdgavzV8J9s/zvDyQk0uA6MBbhkz HpLVHcVRbxMk7h/LOghxHp3CF3YUKcAzlevJZRCnrMVweCgvm0E+XcupuzrS+ZeQkZg== X-Received: by 2002:ac8:2281:: with SMTP id f1mr23767422qta.197.1543198817786; Sun, 25 Nov 2018 18:20:17 -0800 (PST) X-Google-Smtp-Source: AJdET5eD41vzK8Kt5vOHcbZy/pNXYLBhvEvy5wJbX29VYyaIUT50jy2rB7QCsinIpX1Npemvi6Zs X-Received: by 2002:ac8:2281:: with SMTP id f1mr23767395qta.197.1543198817191; Sun, 25 Nov 2018 18:20:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543198817; cv=none; d=google.com; s=arc-20160816; b=CV2Fb47KC/dix2cvRdnlDTEnXaIhPNOCqpGQdiRbklEP+ujz3wnBBg9TvOWvx9zVC3 iTmavJz9VBVc0aPnGbA1LcmduVhw7Q4yD2u5VWiQtTPLxgZ9JK5O0twbQ5qpVyciYaDw zDTldIqrIN7zaJ7Cf8ead9sY7Hlc5c2zag7jiEarT9nYSMgIdO7q8dCGyxcP1wCckY7q 4AFE2536T6FVvU6QECpSMGgUT+x/wS+Pv01VQy8RfOKQIyv/yk2oGThRbX2N3jmGVHEQ x0/ZoeGCCwOw/GkQi+5U+R4+lKhBCmX1W+ZgkrD5/+PTXM2yqhxe9ByaxrTBYmJRHdbJ b5ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=iiHAK/QyTWLI6+6lI1iCedqrSnHhk/ms7RdzNo36y3M=; b=wp+V8mN+alzEOfCFayQv7uaSk7LHpGcsQG3iUVAEBF2p0pQRYr3lxMTeq6rXrSriYB +xbPAu6hL3c7jEPoVeQk84ksf1sLOS9nnCQdAUnOc9BoET0Ajhw0Tw4eeD0e+okrEA2f nB1Ey/ezXRxLfIm9Lfw7XD7DThObpKE6m/ehqxwVP6BaLcLFcTNJjvOsxaTffEhyvGqI /g/CZU/I0FcrwFv4WbX4efpXiLlqNy6d8Bh3FuHIyePO5PAssctZ5UiExZAELUjMJRwA iyMXrjgtjjL1JByUWqfGX+4vF56JCjWwf/XH+pCrpOMEMjg3kP3UrdCqEZv2ubj0VIJ2 M36A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id h12si7732908qvb.79.2018.11.25.18.20.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Nov 2018 18:20:17 -0800 (PST) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 1AFAE307EA9E; Mon, 26 Nov 2018 02:20:16 +0000 (UTC) Received: from localhost (ovpn-8-19.pek2.redhat.com [10.72.8.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F06A5DE8D; Mon, 26 Nov 2018 02:20:15 +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 V12 13/20] block: loop: pass multi-page bvec to iov_iter Date: Mon, 26 Nov 2018 10:17:13 +0800 Message-Id: <20181126021720.19471-14-ming.lei@redhat.com> In-Reply-To: <20181126021720.19471-1-ming.lei@redhat.com> References: <20181126021720.19471-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.44]); Mon, 26 Nov 2018 02:20:16 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. Reviewed-by: Christoph Hellwig Signed-off-by: Ming Lei Reviewed-by: Omar Sandoval --- drivers/block/loop.c | 20 ++++++++++---------- 1 file changed, 10 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;