Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2457077imu; Mon, 19 Nov 2018 00:27:12 -0800 (PST) X-Google-Smtp-Source: AJdET5dN/fZAyplIRKyGbGIHtqKEDTmphx010d/BTpzTBCqBjW/Ke4Pq1pls1/maENbnyuF7AX3q X-Received: by 2002:a65:4946:: with SMTP id q6mr18795483pgs.201.1542616032834; Mon, 19 Nov 2018 00:27:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542616032; cv=none; d=google.com; s=arc-20160816; b=ysrIRo6+0vY+5e4XOtvrmv/AVkw0es2gQGiIMFhXMwfgb4S/aFDgkAhkeZEJHqBO+P hgH3AVUtNQFO/raZ1GLwyHm0XW/0KL6c6fGusjUCMwV3JjqCitLiWXo2HNzmlHF3U1mX 7rnueT17bZZI5yfZijpvjcpmfgFNwWquJqKHB6ERMNqnL+irw93wFHZLM3obQC0Mr4hi Gxw1P9dGk2UOnREy9DWZTjRa090JLnE6tFBdqCGWzwxmnuB0niQPpaAwPySTyR1qPrVB PTCsJZprOxHaYRO4p7RP4xOdhERMCglSLB5xIqI1pYlS5Swf/Fs0pGcQbAvN5l3qjrNk Byvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=HTTDtVihptYPvm/+nTi8AxCCHKKK+wEE2R/lk245pJs=; b=JKybB8HCwUrpfUw96wOC0aOMZ+AWAWyaJkQKj8tGYKq9e5NYLgPTp0ETdu6a9Gp94C L/QcpE8tEcl2kd25ilVllkXLwMopnErkCBBGL8kGtQlcKOb5aRXa/hr19AX5Fry0f8rx mbx8f7CfnLrTCcCL+OcWbbDIx/EZUZo2TzRiXjTHg6tIcVQwZYx3bY2pnqsA93HcDzsy Hv/Hs7KbAAflGtmXXl8T/O3LPPtr4llH9OiIOI7ZPIw1EPDySNEIQguYiDhUPyYuPNPb O4iC6+kOIKRKkKKvdwXN8Y6QOmZG4VduuZwhxZ3vOmJvRtkdLW6e9cmcGu5Na5t0un5h JXsQ== 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 t11si12109236plo.293.2018.11.19.00.26.57; Mon, 19 Nov 2018 00:27:12 -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 S1726984AbeKSStL (ORCPT + 99 others); Mon, 19 Nov 2018 13:49:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34112 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726175AbeKSStL (ORCPT ); Mon, 19 Nov 2018 13:49:11 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67A8730820D3; Mon, 19 Nov 2018 08:26:16 +0000 (UTC) Received: from ming.t460p (ovpn-8-26.pek2.redhat.com [10.72.8.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F6B41974E; Mon, 19 Nov 2018 08:25:54 +0000 (UTC) Date: Mon, 19 Nov 2018 16:25:49 +0800 From: Ming Lei To: Omar Sandoval Cc: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Dave Chinner , Kent Overstreet , Mike Snitzer , dm-devel@redhat.com, Alexander Viro , linux-fsdevel@vger.kernel.org, Shaohua Li , linux-raid@vger.kernel.org, linux-erofs@lists.ozlabs.org, David Sterba , linux-btrfs@vger.kernel.org, "Darrick J . Wong" , linux-xfs@vger.kernel.org, Gao Xiang , Christoph Hellwig , Theodore Ts'o , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com Subject: Re: [PATCH V10 10/19] block: loop: pass multi-page bvec to iov_iter Message-ID: <20181119082548.GD16736@ming.t460p> References: <20181115085306.9910-1-ming.lei@redhat.com> <20181115085306.9910-11-ming.lei@redhat.com> <20181116004022.GE23828@vader> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181116004022.GE23828@vader> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Mon, 19 Nov 2018 08:26:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 15, 2018 at 04:40:22PM -0800, Omar Sandoval wrote: > On Thu, Nov 15, 2018 at 04:52:57PM +0800, Ming Lei wrote: > > 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. > > > > Cc: Dave Chinner > > Cc: Kent Overstreet > > Cc: Mike Snitzer > > Cc: dm-devel@redhat.com > > Cc: Alexander Viro > > Cc: linux-fsdevel@vger.kernel.org > > Cc: Shaohua Li > > Cc: linux-raid@vger.kernel.org > > Cc: linux-erofs@lists.ozlabs.org > > Cc: David Sterba > > Cc: linux-btrfs@vger.kernel.org > > Cc: Darrick J. Wong > > Cc: linux-xfs@vger.kernel.org > > Cc: Gao Xiang > > Cc: Christoph Hellwig > > Cc: Theodore Ts'o > > Cc: linux-ext4@vger.kernel.org > > Cc: Coly Li > > Cc: linux-bcache@vger.kernel.org > > Cc: Boaz Harrosh > > Cc: Bob Peterson > > Cc: cluster-devel@redhat.com > > Reviewed-by: Omar Sandoval > > Comments below. > > > Signed-off-by: Ming Lei > > --- > > drivers/block/loop.c | 23 ++++++++++++----------- > > 1 file changed, 12 insertions(+), 11 deletions(-) > > > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > > index bf6bc35aaf88..a3fd418ec637 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++; > > + } > > Even if they're not strictly necessary, could you please include the > curly braces for __rq_for_each_bio() here? Sure, will do it. > > > bvec = cmd->bvec; > > offset = 0; > > } else { > > @@ -550,11 +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); > > This scared me for a second, but it's fine to do here because we haven't > actually enabled multipage bvecs yet, right? Well, it is fine, all helpers supporting multi-page bvec actually works well when it isn't enabled, cause single-page bvec is one special case in which multi-page bevc helpers have to deal with. Thanks, Ming