Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2717303imu; Fri, 23 Nov 2018 13:38:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/VBs9TJ7lqbzRjPdDs87z1gNTC+U6b/2ZoO9ZNm1hRdrM5sVqo8TNNfWHyBDemEJD6g1CvY X-Received: by 2002:a62:4e83:: with SMTP id c125mr15874803pfb.101.1543009112888; Fri, 23 Nov 2018 13:38:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543009112; cv=none; d=google.com; s=arc-20160816; b=y0RFVZ4zE2jxwJkjXVke74nKU/yqIEOXeUbTrxxZ66ZtM0D0KDHZAWV4NyAFJuGYdL +z2y1CTEbX8gqJVI4VtSuCBojiQPiPmxz3eoIUK4AgiLQnksY6O5uT/rcq6Qij8vltT+ ucCpHs2vRAly5i3/YicYU47qVN9Ep3qR0wV6VzMcHqYctJc1StnS3tZAE96iVVlC5irm SL8/seGqUqZ5BBVA3i8IDEjtivOs9RSzB0LjLA7V5OBrjTXFgLOGN6o48TGjuq1ALdDy tAi2e++FxOD8Yx3jeG4rKb0qOqH1+enBUxo5yhYHe/g7Sd+qMBkm84Mn62SCKko48N// Apqw== 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=m5oIYiz/+XRc0XrdEaBRR9VO3AZ6tEECqakmzasDzQM=; b=We33N2ukHzWKwZCo81Dygj3jjkrylFCtwda1+Vd1NtbzgFK3uqJpg2mNyOJtCoKZ1r 240PHVc7SoUqWw6WZr8YdtA6v9WBHEYwqX3MdvV/VAZdv/nFY3mU1ep2fXcTE9bnuRoz RLsDBihHfMmptqWa7lTDivCXrM2G6ZdbUgPR1JFI4W5RNa7ZmdOQDjqeK702Y45KpnHf PHYSJD1H5lDpSETZAwTCWzAOlMIUKlNJILn+gLpBhGQx5FoGOTAx0ybFpxOiuntYfPu5 BEDRyiQ7VYqxyELDOtxWYSFd8UkjOsXEVrOqKWusR33GoTentEx99Gh/M/zkjbkpBqj8 JdOA== 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 94-v6si8299709plf.347.2018.11.23.13.38.17; Fri, 23 Nov 2018 13:38:32 -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 S2405689AbeKWBiB (ORCPT + 99 others); Thu, 22 Nov 2018 20:38:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34462 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388992AbeKWBiB (ORCPT ); Thu, 22 Nov 2018 20:38:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5279630024F0; Thu, 22 Nov 2018 14:58:17 +0000 (UTC) Received: from ming.t460p (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E482282714; Thu, 22 Nov 2018 14:57:54 +0000 (UTC) Date: Thu, 22 Nov 2018 22:57:50 +0800 From: Ming Lei To: Christoph Hellwig Cc: Jens Axboe , 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 , linux-ext4@vger.kernel.org, Coly Li , linux-bcache@vger.kernel.org, Boaz Harrosh , Bob Peterson , cluster-devel@redhat.com Subject: Re: [PATCH V11 03/19] block: introduce bio_for_each_bvec() Message-ID: <20181122145749.GA22146@ming.t460p> References: <20181121032327.8434-1-ming.lei@redhat.com> <20181121032327.8434-4-ming.lei@redhat.com> <20181121133244.GB1640@lst.de> <20181121153135.GB19111@ming.t460p> <20181121161025.GB4977@lst.de> <20181121171217.GA6259@lst.de> <20181122101527.GB27273@ming.t460p> <20181122102309.GA29295@lst.de> <20181122103033.GA29418@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181122103033.GA29418@lst.de> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 22 Nov 2018 14:58:18 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 22, 2018 at 11:30:33AM +0100, Christoph Hellwig wrote: > Btw, this patch instead of the plain rever might make it a little > more clear what is going on by skipping the confusing helper altogher > and operating on the raw bvec array: > > > diff --git a/include/linux/bio.h b/include/linux/bio.h > index e5b975fa0558..926550ce2d21 100644 > --- a/include/linux/bio.h > +++ b/include/linux/bio.h > @@ -137,24 +137,18 @@ static inline bool bio_full(struct bio *bio) > for (i = 0, iter_all.idx = 0; iter_all.idx < (bio)->bi_vcnt; iter_all.idx++) \ > bvec_for_each_segment(bvl, &((bio)->bi_io_vec[iter_all.idx]), i, iter_all) > > -static inline void __bio_advance_iter(struct bio *bio, struct bvec_iter *iter, > - unsigned bytes, unsigned max_seg_len) > +static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, > + unsigned bytes) > { > iter->bi_sector += bytes >> 9; > > if (bio_no_advance_iter(bio)) > iter->bi_size -= bytes; > else > - __bvec_iter_advance(bio->bi_io_vec, iter, bytes, max_seg_len); > + bvec_iter_advance(bio->bi_io_vec, iter, bytes); > /* TODO: It is reasonable to complete bio with error here. */ > } > > -static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, > - unsigned bytes) > -{ > - __bio_advance_iter(bio, iter, bytes, PAGE_SIZE); > -} > - > #define __bio_for_each_segment(bvl, bio, iter, start) \ > for (iter = (start); \ > (iter).bi_size && \ > @@ -168,7 +162,7 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, > for (iter = (start); \ > (iter).bi_size && \ > ((bvl = bio_iter_mp_iovec((bio), (iter))), 1); \ > - __bio_advance_iter((bio), &(iter), (bvl).bv_len, BVEC_MAX_LEN)) > + bio_advance_iter((bio), &(iter), (bvl).bv_len)) > > /* returns one real segment(multi-page bvec) each time */ > #define bio_for_each_bvec(bvl, bio, iter) \ > diff --git a/include/linux/bvec.h b/include/linux/bvec.h > index cab36d838ed0..7d0f9bdb6f05 100644 > --- a/include/linux/bvec.h > +++ b/include/linux/bvec.h > @@ -25,8 +25,6 @@ > #include > #include > > -#define BVEC_MAX_LEN ((unsigned int)-1) > - > /* > * was unsigned short, but we might as well be ready for > 64kB I/O pages > */ > @@ -102,8 +100,8 @@ struct bvec_iter_all { > .bv_offset = segment_iter_offset((bvec), (iter)), \ > }) > > -static inline bool __bvec_iter_advance(const struct bio_vec *bv, > - struct bvec_iter *iter, unsigned bytes, unsigned max_seg_len) > +static inline bool bvec_iter_advance(const struct bio_vec *bv, > + struct bvec_iter *iter, unsigned bytes) > { > if (WARN_ONCE(bytes > iter->bi_size, > "Attempted to advance past end of bvec iter\n")) { > @@ -112,20 +110,15 @@ static inline bool __bvec_iter_advance(const struct bio_vec *bv, > } > > while (bytes) { > - unsigned segment_len = segment_iter_len(bv, *iter); > - > - if (max_seg_len < BVEC_MAX_LEN) > - segment_len = min_t(unsigned, segment_len, > - max_seg_len - > - bvec_iter_offset(bv, *iter)); > + const struct bio_vec *cur = bv + iter->bi_idx; > + unsigned len = min3(bytes, iter->bi_size, > + cur->bv_len - iter->bi_bvec_done); > > - segment_len = min(bytes, segment_len); > - > - bytes -= segment_len; > - iter->bi_size -= segment_len; > - iter->bi_bvec_done += segment_len; > + bytes -= len; > + iter->bi_size -= len; > + iter->bi_bvec_done += len; > > - if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) { > + if (iter->bi_bvec_done == cur->bv_len) { > iter->bi_bvec_done = 0; > iter->bi_idx++; > } I'd rather not do the optimization part in this patchset, given it doesn't belong to this patchset, and it may decrease readability. So I plan to revert the delta part in V12 first. Thanks, Ming