On Fri, Feb 14, 2025 at 12:38:54PM -0800, Caleb Sander Mateos wrote: > On Fri, Feb 14, 2025 at 7:45 AM Keith Busch <kbusch@xxxxxxxx> wrote: > > + > > + nr_bvecs = blk_rq_nr_phys_segments(rq); > > Is this guaranteed to match the number of bvecs in the request? Yes. > Wouldn't the number of physical segments depend on how the block > device splits the bvecs? Also yes. >lo_rw_aio() uses rq_for_each_bvec() to count > the number of bvecs, for example. Hm, that seems unnecessary. The request's nr_phys_segments is initialized to the number of bvecs rather than page segments, so it can be used instead of recounting them from a given struct request. The initial number of physical segments for a request is set in bio_split_rw_at(), which uses bio_for_each_bvec(). That's what rq_for_each_bvec would use, too. The same is used for any bio's that get merged into the bio.