Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp472694imu; Fri, 16 Nov 2018 05:31:25 -0800 (PST) X-Google-Smtp-Source: AJdET5c3/ECMpSanNtWlbYRU5NrAteiBbuCx0VcLAnVzZ+jkTsxs/Q3imNiahS66i1Fq1FOIsIXn X-Received: by 2002:a62:8a51:: with SMTP id y78mr376845pfd.35.1542375085683; Fri, 16 Nov 2018 05:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542375085; cv=none; d=google.com; s=arc-20160816; b=GVOIUZxuHvKXZSfvoi8z7T8S5t2tJakwWDl44NetqWveOMJheIRrtLX0j8GHw0VlbC SvnZfquC9OybYiDudQo7I4bOQT+WfXWRdpEpj5lmgFPeJ1fXR/skYWLuoFAPqlvu8H1X w7fvRNabdXNAvtvxQ7yi413Ne35QurrnpPKFbi9CrqonzVxdR9csvML6aD6KU5Hvu29l RJ1E4HI4CNFNVnPAzW2LGckSZmINCITH9qMb31bkyT1lDf+JmjD+FGiA0az1H1SKYvVi UTtCSbjOYNUkPzBr6SdppyZ7j996flC1ailmD4ha/JGNp4jHoJEYI65jtDxD8ROnd0y9 Go+Q== 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=CURVFFkDk21Aq1J6uNgGM0yIYYSW58tpmDh7w4b0ygw=; b=07L/2mgc6udM3SLnWtT0VVAFy/YZkX7g6PFOgwyQvxAPlgeAnEoEQzLFBpo7KaN7yG ylS3jWP6sNYg2lz4XlN3W531uDaY/QRkOoTEUU3h4zkrXJx1qJshEuD6w4MlVxoDhdrW zthQZXy5ky3G+6FbbAH9NSHtr7PM3FOjSlTkt156/stTFsX8cPti64OcaSRkc05cAICw wKHSjM7o1jsis0gAZ75gkocg7ZLbBscQlD2u7gev78ZUBSvvnmpp1qKIhEpQcjFMl8T4 t9qnBwT8dfx2FLew2bnyRkntVRzY+pl/KbLK1vRp7b2HQU7uvjIwDhAhKac+qIb+qGDc LdVg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y68-v6si33737730pfi.61.2018.11.16.05.31.11; Fri, 16 Nov 2018 05:31:25 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389801AbeKPXmz (ORCPT + 99 others); Fri, 16 Nov 2018 18:42:55 -0500 Received: from verein.lst.de ([213.95.11.211]:49787 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727727AbeKPXmz (ORCPT ); Fri, 16 Nov 2018 18:42:55 -0500 Received: by newverein.lst.de (Postfix, from userid 2407) id C99CB68D60; Fri, 16 Nov 2018 14:30:28 +0100 (CET) Date: Fri, 16 Nov 2018 14:30:28 +0100 From: Christoph Hellwig To: Ming Lei 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 02/19] block: introduce bio_for_each_bvec() Message-ID: <20181116133028.GB3165@lst.de> References: <20181115085306.9910-1-ming.lei@redhat.com> <20181115085306.9910-3-ming.lei@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181115085306.9910-3-ming.lei@redhat.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > +static inline void __bio_advance_iter(struct bio *bio, struct bvec_iter *iter, > + unsigned bytes, bool mp) I think these magic 'bool np' arguments and wrappers over wrapper don't help anyone to actually understand the code. I'd vote for removing as many wrappers as we really don't need, and passing the actual segment limit instead of the magic bool flag. Something like this untested patch: diff --git a/include/linux/bio.h b/include/linux/bio.h index 277921ad42e7..dcad0b69f57a 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -138,30 +138,21 @@ static inline bool bio_full(struct bio *bio) 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, bool mp) + unsigned bytes, unsigned max_segment) { iter->bi_sector += bytes >> 9; if (bio_no_advance_iter(bio)) iter->bi_size -= bytes; else - if (!mp) - bvec_iter_advance(bio->bi_io_vec, iter, bytes); - else - mp_bvec_iter_advance(bio->bi_io_vec, iter, bytes); + __bvec_iter_advance(bio->bi_io_vec, iter, bytes, max_segment); /* 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, false); -} - -static inline void bio_advance_mp_iter(struct bio *bio, struct bvec_iter *iter, - unsigned bytes) -{ - __bio_advance_iter(bio, iter, bytes, true); + __bio_advance_iter(bio, iter, bytes, PAGE_SIZE); } #define __bio_for_each_segment(bvl, bio, iter, start) \ @@ -177,7 +168,7 @@ static inline void bio_advance_mp_iter(struct bio *bio, struct bvec_iter *iter, for (iter = (start); \ (iter).bi_size && \ ((bvl = bio_iter_mp_iovec((bio), (iter))), 1); \ - bio_advance_mp_iter((bio), &(iter), (bvl).bv_len)) + __bio_advance_iter((bio), &(iter), (bvl).bv_len, 0)) /* returns one real segment(multipage bvec) each time */ #define bio_for_each_bvec(bvl, bio, iter) \ diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 02f26d2b59ad..5e2ed46c1c88 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -138,8 +138,7 @@ struct bvec_iter_all { }) static inline bool __bvec_iter_advance(const struct bio_vec *bv, - struct bvec_iter *iter, - unsigned bytes, bool mp) + struct bvec_iter *iter, unsigned bytes, unsigned max_segment) { if (WARN_ONCE(bytes > iter->bi_size, "Attempted to advance past end of bvec iter\n")) { @@ -148,18 +147,18 @@ static inline bool __bvec_iter_advance(const struct bio_vec *bv, } while (bytes) { - unsigned len; + unsigned segment_len = mp_bvec_iter_len(bv, *iter); - if (mp) - len = mp_bvec_iter_len(bv, *iter); - else - len = bvec_iter_len(bv, *iter); + if (max_segment) { + max_segment -= bvec_iter_offset(bv, *iter); + segment_len = min(segment_len, max_segment); + } - len = min(bytes, len); + segment_len = min(bytes, segment_len); - bytes -= len; - iter->bi_size -= len; - iter->bi_bvec_done += len; + bytes -= segment_len; + iter->bi_size -= segment_len; + iter->bi_bvec_done += segment_len; if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) { iter->bi_bvec_done = 0; @@ -197,14 +196,7 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, struct bvec_iter *iter, unsigned bytes) { - return __bvec_iter_advance(bv, iter, bytes, false); -} - -static inline bool mp_bvec_iter_advance(const struct bio_vec *bv, - struct bvec_iter *iter, - unsigned bytes) -{ - return __bvec_iter_advance(bv, iter, bytes, true); + return __bvec_iter_advance(bv, iter, bytes, PAGE_SIZE); } #define for_each_bvec(bvl, bio_vec, iter, start) \