linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanyak@nvidia.com>
To: Ming Lei <ming.lei@redhat.com>,
	Caleb Sander Mateos <csander@purestorage.com>
Cc: Jens Axboe <axboe@kernel.dk>, Damien Le Moal <dlemoal@kernel.org>,
	Christoph Hellwig <hch@lst.de>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] loop: use blk_rq_nr_phys_segments() instead of iterating bvecs
Date: Sun, 9 Nov 2025 19:05:25 +0000	[thread overview]
Message-ID: <b62e658a-a35c-4fa8-9674-2d3a12266176@nvidia.com> (raw)
In-Reply-To: <aRCG3OUThPCys92r@fedora>

On 11/9/25 04:19, Ming Lei wrote:
> On Sat, Nov 08, 2025 at 04:01:00PM -0700, Caleb Sander Mateos wrote:
>> The number of bvecs can be obtained directly from struct request's
>> nr_phys_segments field via blk_rq_nr_phys_segments(), so use that
>> instead of iterating over the bvecs an extra time.
>>
>> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
>> ---
>>   drivers/block/loop.c | 5 +----
>>   1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
>> index 13ce229d450c..8096478fad45 100644
>> --- a/drivers/block/loop.c
>> +++ b/drivers/block/loop.c
>> @@ -346,16 +346,13 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,
>>   	struct request *rq = blk_mq_rq_from_pdu(cmd);
>>   	struct bio *bio = rq->bio;
>>   	struct file *file = lo->lo_backing_file;
>>   	struct bio_vec tmp;
>>   	unsigned int offset;
>> -	int nr_bvec = 0;
>> +	unsigned short nr_bvec = blk_rq_nr_phys_segments(rq);
>>   	int ret;
>>   
>> -	rq_for_each_bvec(tmp, rq, rq_iter)
>> -		nr_bvec++;
>> -
> The two may not be same, since one bvec can be splitted into multiple segments.
>
> Thanks,
> Ming
>
>

I had this patch only to realize this :-

bvec_split_segs():-
* When splitting a bio, it can happen that a bvec is encountered that is too
* big to fit in a single segment and hence that it has to be split in the
* middle. This function verifies whether or not that should happen. The 
value
* %true is returned if and only if appending the entire @bv to a bio with
* *@nsegs segments and *@sectors sectors would make that bio 
unacceptable for
* the block driver.

if following messup the indentation after I send plz ignore :-

submit_bio()
   -> submit_bio_noacct()
     -> __submit_bio_noacct()
       -> __submit_bio()
         -> blk_mq_submit_bio()
           -> __bio_split_to_limits()
             -> bio_split_rw()
               -> bio_split_rw_at()
                 -> bio_split_io_at()

                   -- bio_for_each_bvec()   (iterate all bvecs)
                    -- [Fast path]
                         nsegs++             (1 bvec = 1 segment)
                         bytes += bv.bv_len
                    -- [Slow path]
                       /* one bv is passed from bio bvec list  */
                       -> bvec_split_segs(lim, &bv, &nsegs, &bytes,
                                          lim->max_segments, max_bytes)

                            /* working on one bvec and associated 
segments */
                            -- while (len && *nsegs < max_segs) {

                                 ...

                                 get_max_segment_size()
                                   -> min(len,
                                          seg_boundary_mask - offset,
                                          max_segment_size)

                                 (*nsegs)++
                                 total_len += seg_size
                                 len -= seg_size

                                 ...

                               }

                            -- *bytes += total_len
                            -- return (len > 0)

           -> blk_mq_bio_to_request()
                rq->nr_phys_segments = nr_segs

-ck




  reply	other threads:[~2025-11-09 19:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-08 23:00 [PATCH 0/2] use blk_rq_nr_phys_segments() instead of iterating bvecs Caleb Sander Mateos
2025-11-08 23:01 ` [PATCH 1/2] loop: " Caleb Sander Mateos
2025-11-09 12:19   ` Ming Lei
2025-11-09 19:05     ` Chaitanya Kulkarni [this message]
2025-11-10 16:47     ` Caleb Sander Mateos
2025-11-10 21:34       ` Chaitanya Kulkarni
2025-11-11  1:22       ` Ming Lei
2025-11-08 23:01 ` [PATCH 2/2] zloop: " Caleb Sander Mateos
2025-11-11  9:07   ` Christoph Hellwig
2025-11-11 18:19     ` Chaitanya Kulkarni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b62e658a-a35c-4fa8-9674-2d3a12266176@nvidia.com \
    --to=chaitanyak@nvidia.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=dlemoal@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).