Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp1976146pxb; Sun, 10 Jan 2021 19:00:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhw4ktMUo89W10/PCn/r4tFdn6StuLPAr2+NzFSxxx8cfPEYP5gNMQ+vubuhIn3p7wch+H X-Received: by 2002:a17:906:15ca:: with SMTP id l10mr9062950ejd.402.1610334052026; Sun, 10 Jan 2021 19:00:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610334052; cv=none; d=google.com; s=arc-20160816; b=R28PXM+y+Jbbn8gvLnImcBrryEnvOCxpmXi6T0jCPww/OHvbuz4i/2jsTuBYsc+QO2 cxEEHi/tj9K78iBLaQbujStp1FViO7K2eMr9cNBSMMo3EkrmTlr4GNF/NG+Ay2u03zMK bzCGQh9g5KS7Zv8XSBbz5/znXzI9jq/hf1JO/8xxD42qNNQ9eBkVb/T2UUx+I4dmnO9m V/2IIcSSPqbLfseWTnagOhFQ3ca0wd7oK20+7h+y0Gv+LGSDF+FioOJKOrgdhsmwtRbX Dv5q0hjGC4xo2oqv+k3M2fvRH/4ecR4KStjRvShfMNkH5T5tNYbSVTC4ibpS5V0Ubk6/ H+BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ty7GFnFeJc6jZbRimFvcSxwHhWMZKBFI3wOaZ1vJeGo=; b=aw1zXbT+OpNqN62h0MgpAm4l1M67+5Bzr9XQeMC92LkVC5Mk2lmq3bMSJkFsPC4wsG xEXh4fXpgTlXaC8ZxnD7uJ32NYprLP8v6FLWJOy04dlcJ6Z9P6ttm0eg36BmzhhG1Lys ptsz/sNOxlWOgvpO39WQv/4l/Lp8JuAEnOYWdvkX7gGsCDc1sX3AO4FEHei1vSxoHZwK zBC7cxkRvTD1Ik+FojtpWRWNcca6DR1EG1/eYLWor4ka6+M5QfCDCYFu+pXaG3sHZJLM I+rTHQwJUoLb5K8JK0h191Z4pLKxExCxWKnCK67cmIq7W9NACc2N4OyKUUeTgEB9KzPO 8ITw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Fr+xXpfm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p9si6009374ejg.481.2021.01.10.19.00.28; Sun, 10 Jan 2021 19:00:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Fr+xXpfm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726987AbhAKC66 (ORCPT + 99 others); Sun, 10 Jan 2021 21:58:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33681 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbhAKC66 (ORCPT ); Sun, 10 Jan 2021 21:58:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610333852; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ty7GFnFeJc6jZbRimFvcSxwHhWMZKBFI3wOaZ1vJeGo=; b=Fr+xXpfmf4re8oGKe8e//ZXLBH09jXAtj63DpfhSRp3FtpgJJnEGX6iyM0rCqzvBHxDM7T q4AMtfuF0p8fU6DssgUYmr8/FpDc077QSkwRu1Vtutf80gOfo/2A62bROfVJKpYjTPOTnr QQK/9ZmdTHM0XutaWS+mS0eOnERmXJ8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-176-lfrDpYNaMcuSG9HvsZrXJA-1; Sun, 10 Jan 2021 21:57:28 -0500 X-MC-Unique: lfrDpYNaMcuSG9HvsZrXJA-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7949180A09E; Mon, 11 Jan 2021 02:57:25 +0000 (UTC) Received: from T590 (ovpn-12-180.pek2.redhat.com [10.72.12.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 208EF19D9D; Mon, 11 Jan 2021 02:57:14 +0000 (UTC) Date: Mon, 11 Jan 2021 10:57:10 +0800 From: Ming Lei To: Pavel Begunkov Cc: linux-block@vger.kernel.org, Jens Axboe , Christoph Hellwig , Matthew Wilcox , Johannes Weiner , Alexander Viro , "Darrick J . Wong" , "Martin K . Petersen" , Jonathan Corbet , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, linux-doc@vger.kernel.org, Christoph Hellwig Subject: Re: [PATCH v3 6/7] bio: add a helper calculating nr segments to alloc Message-ID: <20210111025710.GG4147870@T590> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 09, 2021 at 04:03:02PM +0000, Pavel Begunkov wrote: > Add a helper function calculating the number of bvec segments we need to > allocate to construct a bio. It doesn't change anything functionally, > but will be used to not duplicate special cases in the future. > > Reviewed-by: Christoph Hellwig > Signed-off-by: Pavel Begunkov > --- > fs/block_dev.c | 7 ++++--- > fs/iomap/direct-io.c | 9 ++++----- > include/linux/bio.h | 10 ++++++++++ > 3 files changed, 18 insertions(+), 8 deletions(-) > > diff --git a/fs/block_dev.c b/fs/block_dev.c > index 3b8963e228a1..6f5bd9950baf 100644 > --- a/fs/block_dev.c > +++ b/fs/block_dev.c > @@ -416,7 +416,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, int nr_pages) > dio->size += bio->bi_iter.bi_size; > pos += bio->bi_iter.bi_size; > > - nr_pages = iov_iter_npages(iter, BIO_MAX_PAGES); > + nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_PAGES); > if (!nr_pages) { > bool polled = false; > > @@ -481,9 +481,10 @@ blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter) > { > int nr_pages; > > - nr_pages = iov_iter_npages(iter, BIO_MAX_PAGES + 1); > - if (!nr_pages) > + if (!iov_iter_count(iter)) > return 0; > + > + nr_pages = bio_iov_vecs_to_alloc(iter, BIO_MAX_PAGES + 1); > if (is_sync_kiocb(iocb) && nr_pages <= BIO_MAX_PAGES) > return __blkdev_direct_IO_simple(iocb, iter, nr_pages); > > diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c > index 933f234d5bec..ea1e8f696076 100644 > --- a/fs/iomap/direct-io.c > +++ b/fs/iomap/direct-io.c > @@ -250,11 +250,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, > orig_count = iov_iter_count(dio->submit.iter); > iov_iter_truncate(dio->submit.iter, length); > > - nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES); > - if (nr_pages <= 0) { > - ret = nr_pages; > + if (!iov_iter_count(dio->submit.iter)) > goto out; > - } > > if (need_zeroout) { > /* zero out from the start of the block to the write offset */ > @@ -263,6 +260,7 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, > iomap_dio_zero(dio, iomap, pos - pad, pad); > } > > + nr_pages = bio_iov_vecs_to_alloc(dio->submit.iter, BIO_MAX_PAGES); > do { > size_t n; > if (dio->error) { > @@ -308,7 +306,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t length, > dio->size += n; > copied += n; > > - nr_pages = iov_iter_npages(dio->submit.iter, BIO_MAX_PAGES); > + nr_pages = bio_iov_vecs_to_alloc(dio->submit.iter, > + BIO_MAX_PAGES); > iomap_dio_submit_bio(dio, iomap, bio, pos); > pos += n; > } while (nr_pages); > diff --git a/include/linux/bio.h b/include/linux/bio.h > index 1edda614f7ce..d8f9077c43ef 100644 > --- a/include/linux/bio.h > +++ b/include/linux/bio.h > @@ -10,6 +10,7 @@ > #include > /* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */ > #include > +#include > > #define BIO_DEBUG > > @@ -441,6 +442,15 @@ static inline void bio_wouldblock_error(struct bio *bio) > bio_endio(bio); > } > > +/* > + * Calculate number of bvec segments that should be allocated to fit data > + * pointed by @iter. > + */ > +static inline int bio_iov_vecs_to_alloc(struct iov_iter *iter, int max_segs) > +{ > + return iov_iter_npages(iter, max_segs); > +} > + > struct request_queue; > > extern int submit_bio_wait(struct bio *bio); > -- > 2.24.0 > Reviewed-by: Ming Lei -- Ming