Message ID | 20240705123232.2165187-3-hch@lst.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] block: add a bvec_phys helper | expand |
On 7/5/24 6:32 AM, Christoph Hellwig wrote: > Work on a single address to simplify the logic, and prepare the callers > from using better helpers. > > Signed-off-by: Christoph Hellwig <hch@lst.de> > --- > block/blk-merge.c | 27 ++++++++++++--------------- > 1 file changed, 12 insertions(+), 15 deletions(-) > > diff --git a/block/blk-merge.c b/block/blk-merge.c > index cff20bcc0252a7..b1e1b7a6933511 100644 > --- a/block/blk-merge.c > +++ b/block/blk-merge.c > @@ -207,25 +207,24 @@ static inline unsigned get_max_io_size(struct bio *bio, > } > > /** > - * get_max_segment_size() - maximum number of bytes to add as a single segment > + * get_max_segment_size() - maximum number of bytes to add to a single segment v1 had this change too, not sure why? The previous description seems better than the changed one.
On Sat, Jul 06, 2024 at 12:21:06AM -0600, Jens Axboe wrote: > > /** > > - * get_max_segment_size() - maximum number of bytes to add as a single segment > > + * get_max_segment_size() - maximum number of bytes to add to a single segment > > v1 had this change too, not sure why? The previous description seems > better than the changed one. Because it is used to also append data from another bio_vec to a pre-existing SG segment, not just to create new ones.
On 7/6/24 12:22 AM, Christoph Hellwig wrote: > On Sat, Jul 06, 2024 at 12:21:06AM -0600, Jens Axboe wrote: >>> /** >>> - * get_max_segment_size() - maximum number of bytes to add as a single segment >>> + * get_max_segment_size() - maximum number of bytes to add to a single segment >> >> v1 had this change too, not sure why? The previous description seems >> better than the changed one. > > Because it is used to also append data from another bio_vec to a > pre-existing SG segment, not just to create new ones. Sure, but then let's make it something that makes more sense at least. Maximum size to consider as a single segment, or something like that.
diff --git a/block/blk-merge.c b/block/blk-merge.c index cff20bcc0252a7..b1e1b7a6933511 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -207,25 +207,24 @@ static inline unsigned get_max_io_size(struct bio *bio, } /** - * get_max_segment_size() - maximum number of bytes to add as a single segment + * get_max_segment_size() - maximum number of bytes to add to a single segment * @lim: Request queue limits. - * @start_page: See below. - * @offset: Offset from @start_page where to add a segment. + * @paddr: address of the range to add + * @max_len: maximum length available to add at @paddr * - * Returns the maximum number of bytes that can be added as a single segment. + * Returns the maximum number of bytes of the range starting at @paddr that can + * be added to a single segment. */ static inline unsigned get_max_segment_size(const struct queue_limits *lim, - struct page *start_page, unsigned long offset) + phys_addr_t paddr, unsigned int len) { - unsigned long mask = lim->seg_boundary_mask; - - offset = mask & (page_to_phys(start_page) + offset); - /* * Prevent an overflow if mask = ULONG_MAX and offset = 0 by adding 1 * after having calculated the minimum. */ - return min(mask - offset, (unsigned long)lim->max_segment_size - 1) + 1; + return min_t(unsigned long, len, + min(lim->seg_boundary_mask - (lim->seg_boundary_mask & paddr), + (unsigned long)lim->max_segment_size - 1) + 1); } /** @@ -258,9 +257,7 @@ static bool bvec_split_segs(const struct queue_limits *lim, unsigned seg_size = 0; while (len && *nsegs < max_segs) { - seg_size = get_max_segment_size(lim, bv->bv_page, - bv->bv_offset + total_len); - seg_size = min(seg_size, len); + seg_size = get_max_segment_size(lim, bvec_phys(bv) + total_len, len); (*nsegs)++; total_len += seg_size; @@ -494,8 +491,8 @@ static unsigned blk_bvec_map_sg(struct request_queue *q, while (nbytes > 0) { unsigned offset = bvec->bv_offset + total; - unsigned len = min(get_max_segment_size(&q->limits, - bvec->bv_page, offset), nbytes); + unsigned len = get_max_segment_size(&q->limits, bvec_phys(bvec), + nbytes); struct page *page = bvec->bv_page; /*
Work on a single address to simplify the logic, and prepare the callers from using better helpers. Signed-off-by: Christoph Hellwig <hch@lst.de> --- block/blk-merge.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)