Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2018607imu; Wed, 21 Nov 2018 05:37:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/VMYfGV45cjeH4tmAFGl5dx6wOIlbTTC5a0UICe+g1iWS81TUR3oMfjoZrr0tUILWa9RdeM X-Received: by 2002:a65:5286:: with SMTP id y6mr5957721pgp.439.1542807448247; Wed, 21 Nov 2018 05:37:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542807448; cv=none; d=google.com; s=arc-20160816; b=C8yBNIIr6fQTP6RVYm5gjExklZixKLZxQbdmpGFuXpWDmv7LElFeVD4VvXvWOTe1C9 4Ht+snE2Gi2y7EgPGTwR5DRglDwfoV4KDwURDwKZqvXu8AtG8lSLv4qLIHUqw0hLHRqV B8HY2jnY2bxG5M5NBwuhguP1XN5fQlmTkLgd5jiL7aPAJTwyd/0lHcf1RMedHPxroDu2 7zcltEDVHf8hhDO7Q4KyCbFK7qDY0B4cOZ7wdFvAyTHPDBge3dBqRfdPkpSvwF1Mh858 puN1gbYNge4QjrVWI1bL782q94cz0ZvuQK4P2nS67mQ7byD8hCXlaLUz8DBfNB3IJIAs YSvA== 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=LH0PoKz0yofhwqHYTWEHtgQUpcJmahKPQaactDejBig=; b=A6YiyfsuiFRl1ucnqJRCQMJhZD7I4AwXwEa9zvRGalGcMXg5/02yqB3D7rUZ3gR3m3 k5VEle5zxkcExlUPjfBH+t6kmgFjgRokqpFo87i28hRZUXfCvalVfSkOmIyLgm+TfdKU q2KnvljzOdxGv94mHmlQFpvGuqLHYHbnzlNVpZNE6+T+kn8iiZHg2lBzBCrWu0ZMdVDY 5un8h6tb/XDTL3oVLe+i03nKWd7fJEx26jP+Le6++Sk3bS1qKs4RaGHaELZc8rVDTFOe vABRDrlpMMpeKyhJzj/qG1V/cDMI3N+7CTMDHSY0zRoGPcCE3TY0vy9oXiCT3typuXNl ymUA== 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 f63si16169168pfg.136.2018.11.21.05.37.12; Wed, 21 Nov 2018 05:37:28 -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 S1730790AbeKVAHL (ORCPT + 99 others); Wed, 21 Nov 2018 19:07:11 -0500 Received: from verein.lst.de ([213.95.11.211]:51393 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727486AbeKVAHL (ORCPT ); Wed, 21 Nov 2018 19:07:11 -0500 Received: by newverein.lst.de (Postfix, from userid 2407) id B141D68C19; Wed, 21 Nov 2018 14:32:44 +0100 (CET) Date: Wed, 21 Nov 2018 14:32:44 +0100 From: Christoph Hellwig To: Ming Lei 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 , Christoph Hellwig , 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: <20181121133244.GB1640@lst.de> References: <20181121032327.8434-1-ming.lei@redhat.com> <20181121032327.8434-4-ming.lei@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181121032327.8434-4-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 > +#define bio_iter_mp_iovec(bio, iter) \ > + segment_iter_bvec((bio)->bi_io_vec, (iter)) Besides the mp naming we'd like to get rid off there also is just a single user of this macro, please just expand it there. > +#define segment_iter_bvec(bvec, iter) \ > +((struct bio_vec) { \ > + .bv_page = segment_iter_page((bvec), (iter)), \ > + .bv_len = segment_iter_len((bvec), (iter)), \ > + .bv_offset = segment_iter_offset((bvec), (iter)), \ > +}) And for this one please keep the segment vs bvec versions of these macros close together in the file please, right now it follow the bvec_iter_bvec variant closely. > +static inline void __bio_advance_iter(struct bio *bio, struct bvec_iter *iter, > + unsigned bytes, unsigned max_seg_len) > { > 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); > + __bvec_iter_advance(bio->bi_io_vec, iter, bytes, max_seg_len); > /* 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); > +} Btw, I think the remaining users of bio_advance_iter() in bio.h should probably switch to using __bio_advance_iter to make them a little more clear to read. > +/* returns one real segment(multi-page bvec) each time */ space before the brace, please. > +#define BVEC_MAX_LEN ((unsigned int)-1) > while (bytes) { > + unsigned segment_len = segment_iter_len(bv, *iter); > > - iter->bi_bvec_done += len; > + if (max_seg_len < BVEC_MAX_LEN) > + segment_len = min_t(unsigned, segment_len, > + max_seg_len - > + bvec_iter_offset(bv, *iter)); > + > + segment_len = min(bytes, segment_len); Please stick to passing the magic zero here as can often generate more efficient code. Talking about efficent code - I wonder how much code size we'd save by moving this function out of line.. But while looking over this I wonder why we even need the max_seg_len here. The only thing __bvec_iter_advance does it to move bi_bvec_done and bi_idx forward, with corresponding decrements of bi_size. As far as I can tell the only thing that max_seg_len does is that we need to more iterations of the while loop to archive the same thing. And actual bvec used by the caller will be obtained using bvec_iter_bvec or segment_iter_bvec depending on if they want multi-page or single-page variants.