Skip to content

Commit f70167a

Browse files
johnpgarryaxboe
authored andcommitted
block: Generalize chunk_sectors support as boundary support
The purpose of the chunk_sectors limit is to ensure that a mergeble request fits within the boundary of the chunck_sector value. Such a feature will be useful for other request_queue boundary limits, so generalize the chunk_sectors merge code. This idea was proposed by Hannes Reinecke. Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Acked-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Link: https://lore.kernel.org/r/20240620125359.2684798-3-john.g.garry@oracle.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 8d1dfd5 commit f70167a

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

block/blk-merge.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ static struct bio *bio_split_write_zeroes(struct bio *bio,
154154
return bio_split(bio, lim->max_write_zeroes_sectors, GFP_NOIO, bs);
155155
}
156156

157+
static inline unsigned int blk_boundary_sectors(const struct queue_limits *lim)
158+
{
159+
return lim->chunk_sectors;
160+
}
161+
157162
/*
158163
* Return the maximum number of sectors from the start of a bio that may be
159164
* submitted as a single request to a block device. If enough sectors remain,
@@ -167,12 +172,13 @@ static inline unsigned get_max_io_size(struct bio *bio,
167172
{
168173
unsigned pbs = lim->physical_block_size >> SECTOR_SHIFT;
169174
unsigned lbs = lim->logical_block_size >> SECTOR_SHIFT;
175+
unsigned boundary_sectors = blk_boundary_sectors(lim);
170176
unsigned max_sectors = lim->max_sectors, start, end;
171177

172-
if (lim->chunk_sectors) {
178+
if (boundary_sectors) {
173179
max_sectors = min(max_sectors,
174-
blk_chunk_sectors_left(bio->bi_iter.bi_sector,
175-
lim->chunk_sectors));
180+
blk_boundary_sectors_left(bio->bi_iter.bi_sector,
181+
boundary_sectors));
176182
}
177183

178184
start = bio->bi_iter.bi_sector & (pbs - 1);
@@ -588,19 +594,21 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
588594
sector_t offset)
589595
{
590596
struct request_queue *q = rq->q;
591-
unsigned int max_sectors;
597+
struct queue_limits *lim = &q->limits;
598+
unsigned int max_sectors, boundary_sectors;
592599

593600
if (blk_rq_is_passthrough(rq))
594601
return q->limits.max_hw_sectors;
595602

603+
boundary_sectors = blk_boundary_sectors(lim);
596604
max_sectors = blk_queue_get_max_sectors(rq);
597605

598-
if (!q->limits.chunk_sectors ||
606+
if (!boundary_sectors ||
599607
req_op(rq) == REQ_OP_DISCARD ||
600608
req_op(rq) == REQ_OP_SECURE_ERASE)
601609
return max_sectors;
602610
return min(max_sectors,
603-
blk_chunk_sectors_left(offset, q->limits.chunk_sectors));
611+
blk_boundary_sectors_left(offset, boundary_sectors));
604612
}
605613

606614
static inline int ll_new_hw_segment(struct request *req, struct bio *bio,

drivers/md/dm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ static sector_t __max_io_len(struct dm_target *ti, sector_t sector,
11881188
return len;
11891189
return min_t(sector_t, len,
11901190
min(max_sectors ? : queue_max_sectors(ti->table->md->queue),
1191-
blk_chunk_sectors_left(target_offset, max_granularity)));
1191+
blk_boundary_sectors_left(target_offset, max_granularity)));
11921192
}
11931193

11941194
static inline sector_t max_io_len(struct dm_target *ti, sector_t sector)

include/linux/blkdev.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -907,14 +907,15 @@ static inline bool bio_straddles_zones(struct bio *bio)
907907
}
908908

909909
/*
910-
* Return how much of the chunk is left to be used for I/O at a given offset.
910+
* Return how much within the boundary is left to be used for I/O at a given
911+
* offset.
911912
*/
912-
static inline unsigned int blk_chunk_sectors_left(sector_t offset,
913-
unsigned int chunk_sectors)
913+
static inline unsigned int blk_boundary_sectors_left(sector_t offset,
914+
unsigned int boundary_sectors)
914915
{
915-
if (unlikely(!is_power_of_2(chunk_sectors)))
916-
return chunk_sectors - sector_div(offset, chunk_sectors);
917-
return chunk_sectors - (offset & (chunk_sectors - 1));
916+
if (unlikely(!is_power_of_2(boundary_sectors)))
917+
return boundary_sectors - sector_div(offset, boundary_sectors);
918+
return boundary_sectors - (offset & (boundary_sectors - 1));
918919
}
919920

920921
/**

0 commit comments

Comments
 (0)