* simplify I/O size calculation helpers v2
@ 2021-10-13 17:12 ` Christoph Hellwig
0 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: Mike Snitzer, linux-block, dm-devel
Hi Jens,
this series calculates various I/O size calculations.
Changes since v1:
- rename chunk_size_left to blk_chunk_sectors_left
- split a patch into two
Diffstat:
block/blk-merge.c | 28 ++++++++++++++++------------
drivers/md/dm.c | 18 ++++++------------
include/linux/blkdev.h | 27 ++++++++-------------------
3 files changed, 30 insertions(+), 43 deletions(-)
^ permalink raw reply [flat|nested] 19+ messages in thread
* [dm-devel] simplify I/O size calculation helpers v2
@ 2021-10-13 17:12 ` Christoph Hellwig
0 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, dm-devel, Mike Snitzer
Hi Jens,
this series calculates various I/O size calculations.
Changes since v1:
- rename chunk_size_left to blk_chunk_sectors_left
- split a patch into two
Diffstat:
block/blk-merge.c | 28 ++++++++++++++++------------
drivers/md/dm.c | 18 ++++++------------
include/linux/blkdev.h | 27 ++++++++-------------------
3 files changed, 30 insertions(+), 43 deletions(-)
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 1/6] block: factor out a chunk_size_left helper
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
@ 2021-10-13 17:12 ` Christoph Hellwig
-1 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: Mike Snitzer, linux-block, dm-devel
Factor out a helper from blk_max_size_offset so that it can be reused
independently.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/blkdev.h | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 17705c970d7e1..c6ecd996c2d46 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -622,6 +622,18 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
return q->limits.max_sectors;
}
+/*
+ * Return how much of the chunk sectors is left to be used for an I/O at the
+ * given offset.
+ */
+static inline unsigned int blk_chunk_sectors_left(sector_t offset,
+ unsigned int chunk_sectors)
+{
+ if (unlikely(!is_power_of_2(chunk_sectors)))
+ return chunk_sectors - sector_div(offset, chunk_sectors);
+ return chunk_sectors - (offset & (chunk_sectors - 1));
+}
+
/*
* Return maximum size of a request at given offset. Only valid for
* file system requests.
@@ -637,12 +649,8 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
return q->limits.max_sectors;
}
- if (likely(is_power_of_2(chunk_sectors)))
- chunk_sectors -= offset & (chunk_sectors - 1);
- else
- chunk_sectors -= sector_div(offset, chunk_sectors);
-
- return min(q->limits.max_sectors, chunk_sectors);
+ return min(q->limits.max_sectors,
+ blk_chunk_sectors_left(offset, chunk_sectors));
}
/*
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [dm-devel] [PATCH 1/6] block: factor out a chunk_size_left helper
@ 2021-10-13 17:12 ` Christoph Hellwig
0 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, dm-devel, Mike Snitzer
Factor out a helper from blk_max_size_offset so that it can be reused
independently.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/blkdev.h | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 17705c970d7e1..c6ecd996c2d46 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -622,6 +622,18 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
return q->limits.max_sectors;
}
+/*
+ * Return how much of the chunk sectors is left to be used for an I/O at the
+ * given offset.
+ */
+static inline unsigned int blk_chunk_sectors_left(sector_t offset,
+ unsigned int chunk_sectors)
+{
+ if (unlikely(!is_power_of_2(chunk_sectors)))
+ return chunk_sectors - sector_div(offset, chunk_sectors);
+ return chunk_sectors - (offset & (chunk_sectors - 1));
+}
+
/*
* Return maximum size of a request at given offset. Only valid for
* file system requests.
@@ -637,12 +649,8 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
return q->limits.max_sectors;
}
- if (likely(is_power_of_2(chunk_sectors)))
- chunk_sectors -= offset & (chunk_sectors - 1);
- else
- chunk_sectors -= sector_div(offset, chunk_sectors);
-
- return min(q->limits.max_sectors, chunk_sectors);
+ return min(q->limits.max_sectors,
+ blk_chunk_sectors_left(offset, chunk_sectors));
}
/*
--
2.30.2
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 2/6] dm: open code blk_max_size_offset in max_io_len
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
@ 2021-10-13 17:12 ` Christoph Hellwig
-1 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: Mike Snitzer, linux-block, dm-devel
max_io_len always passed in an explicit, non-zero chunk_sectors into
blk_max_size_offset. That means much of blk_max_size_offset is not needed
and open coding it simplifies the code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/dm.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index a011d09cb0fac..825ed9d84c9c0 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -944,24 +944,18 @@ static inline sector_t max_io_len_target_boundary(struct dm_target *ti,
static sector_t max_io_len(struct dm_target *ti, sector_t sector)
{
sector_t target_offset = dm_target_offset(ti, sector);
- sector_t len = max_io_len_target_boundary(ti, target_offset);
- sector_t max_len;
+ unsigned int len = max_io_len_target_boundary(ti, target_offset);
/*
* Does the target need to split IO even further?
* - varied (per target) IO splitting is a tenet of DM; this
* explains why stacked chunk_sectors based splitting via
- * blk_max_size_offset() isn't possible here. So pass in
- * ti->max_io_len to override stacked chunk_sectors.
+ * blk_queue_split() isn't possible here.
*/
- if (ti->max_io_len) {
- max_len = blk_max_size_offset(ti->table->md->queue,
- target_offset, ti->max_io_len);
- if (len > max_len)
- len = max_len;
- }
-
- return len;
+ if (!ti->max_io_len)
+ return len;
+ return min3(len, ti->table->md->queue->limits.max_sectors,
+ blk_chunk_sectors_left(target_offset, ti->max_io_len));
}
int dm_set_target_max_io_len(struct dm_target *ti, sector_t len)
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [dm-devel] [PATCH 2/6] dm: open code blk_max_size_offset in max_io_len
@ 2021-10-13 17:12 ` Christoph Hellwig
0 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, dm-devel, Mike Snitzer
max_io_len always passed in an explicit, non-zero chunk_sectors into
blk_max_size_offset. That means much of blk_max_size_offset is not needed
and open coding it simplifies the code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/dm.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index a011d09cb0fac..825ed9d84c9c0 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -944,24 +944,18 @@ static inline sector_t max_io_len_target_boundary(struct dm_target *ti,
static sector_t max_io_len(struct dm_target *ti, sector_t sector)
{
sector_t target_offset = dm_target_offset(ti, sector);
- sector_t len = max_io_len_target_boundary(ti, target_offset);
- sector_t max_len;
+ unsigned int len = max_io_len_target_boundary(ti, target_offset);
/*
* Does the target need to split IO even further?
* - varied (per target) IO splitting is a tenet of DM; this
* explains why stacked chunk_sectors based splitting via
- * blk_max_size_offset() isn't possible here. So pass in
- * ti->max_io_len to override stacked chunk_sectors.
+ * blk_queue_split() isn't possible here.
*/
- if (ti->max_io_len) {
- max_len = blk_max_size_offset(ti->table->md->queue,
- target_offset, ti->max_io_len);
- if (len > max_len)
- len = max_len;
- }
-
- return len;
+ if (!ti->max_io_len)
+ return len;
+ return min3(len, ti->table->md->queue->limits.max_sectors,
+ blk_chunk_sectors_left(target_offset, ti->max_io_len));
}
int dm_set_target_max_io_len(struct dm_target *ti, sector_t len)
--
2.30.2
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [dm-devel] [PATCH 3/6] block: only call blk_queue_get_max_sectors once in blk_rq_get_max_sectors
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
@ 2021-10-13 17:12 ` Christoph Hellwig
-1 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, dm-devel, Mike Snitzer
Consolidate the two calls to blk_rq_get_max_sectors into one using a
local variable.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-merge.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 14ce19607cd8a..8ed50952e93ad 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -595,17 +595,18 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
sector_t offset)
{
struct request_queue *q = rq->q;
+ unsigned int max_sectors;
if (blk_rq_is_passthrough(rq))
return q->limits.max_hw_sectors;
+ max_sectors = blk_queue_get_max_sectors(q, req_op(rq));
if (!q->limits.chunk_sectors ||
req_op(rq) == REQ_OP_DISCARD ||
req_op(rq) == REQ_OP_SECURE_ERASE)
- return blk_queue_get_max_sectors(q, req_op(rq));
+ return max_sectors;
- return min(blk_max_size_offset(q, offset, 0),
- blk_queue_get_max_sectors(q, req_op(rq)));
+ return min(max_sectors, blk_max_size_offset(q, offset, 0));
}
static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
--
2.30.2
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 3/6] block: only call blk_queue_get_max_sectors once in blk_rq_get_max_sectors
@ 2021-10-13 17:12 ` Christoph Hellwig
0 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: Mike Snitzer, linux-block, dm-devel
Consolidate the two calls to blk_rq_get_max_sectors into one using a
local variable.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-merge.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 14ce19607cd8a..8ed50952e93ad 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -595,17 +595,18 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
sector_t offset)
{
struct request_queue *q = rq->q;
+ unsigned int max_sectors;
if (blk_rq_is_passthrough(rq))
return q->limits.max_hw_sectors;
+ max_sectors = blk_queue_get_max_sectors(q, req_op(rq));
if (!q->limits.chunk_sectors ||
req_op(rq) == REQ_OP_DISCARD ||
req_op(rq) == REQ_OP_SECURE_ERASE)
- return blk_queue_get_max_sectors(q, req_op(rq));
+ return max_sectors;
- return min(blk_max_size_offset(q, offset, 0),
- blk_queue_get_max_sectors(q, req_op(rq)));
+ return min(max_sectors, blk_max_size_offset(q, offset, 0));
}
static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 4/6] block: open code blk_max_size_offset in blk_rq_get_max_sectors
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
@ 2021-10-13 17:12 ` Christoph Hellwig
-1 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: Mike Snitzer, linux-block, dm-devel
blk_rq_get_max_sectors always uses q->limits.chunk_sectors as the
chunk_sectors argument, and already checks for max_sectors through the
call to blk_queue_get_max_sectors. That means much of
blk_max_size_offset is not needed and open coding it simplifies the code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-merge.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 8ed50952e93ad..3e9dde152fdcd 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -605,8 +605,8 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
req_op(rq) == REQ_OP_DISCARD ||
req_op(rq) == REQ_OP_SECURE_ERASE)
return max_sectors;
-
- return min(max_sectors, blk_max_size_offset(q, offset, 0));
+ return min(max_sectors,
+ blk_chunk_sectors_left(offset, q->limits.chunk_sectors));
}
static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [dm-devel] [PATCH 4/6] block: open code blk_max_size_offset in blk_rq_get_max_sectors
@ 2021-10-13 17:12 ` Christoph Hellwig
0 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, dm-devel, Mike Snitzer
blk_rq_get_max_sectors always uses q->limits.chunk_sectors as the
chunk_sectors argument, and already checks for max_sectors through the
call to blk_queue_get_max_sectors. That means much of
blk_max_size_offset is not needed and open coding it simplifies the code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-merge.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 8ed50952e93ad..3e9dde152fdcd 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -605,8 +605,8 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
req_op(rq) == REQ_OP_DISCARD ||
req_op(rq) == REQ_OP_SECURE_ERASE)
return max_sectors;
-
- return min(max_sectors, blk_max_size_offset(q, offset, 0));
+ return min(max_sectors,
+ blk_chunk_sectors_left(offset, q->limits.chunk_sectors));
}
static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
--
2.30.2
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 5/6] block: fold blk_max_size_offset into get_max_io_size
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
@ 2021-10-13 17:12 ` Christoph Hellwig
-1 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: Mike Snitzer, linux-block, dm-devel
Fold blk_max_size_offset into the only remaining user.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-merge.c | 15 ++++++++++-----
include/linux/blkdev.h | 19 -------------------
2 files changed, 10 insertions(+), 24 deletions(-)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 3e9dde152fdcd..87ea3e7b8ad28 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -177,14 +177,19 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q,
static inline unsigned get_max_io_size(struct request_queue *q,
struct bio *bio)
{
- unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector, 0);
- unsigned max_sectors = sectors;
unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT;
unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT;
- unsigned start_offset = bio->bi_iter.bi_sector & (pbs - 1);
+ sector_t sector = bio->bi_iter.bi_sector;
+ unsigned start_offset = sector & (pbs - 1);
+ unsigned sectors = q->limits.max_sectors;
+ unsigned max_sectors;
+
+ if (q->limits.chunk_sectors) {
+ sectors = min(sectors, blk_chunk_sectors_left(sector,
+ q->limits.chunk_sectors));
+ }
- max_sectors += start_offset;
- max_sectors &= ~(pbs - 1);
+ max_sectors = (sectors + start_offset) & ~(pbs - 1);
if (max_sectors > start_offset)
return max_sectors - start_offset;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index c6ecd996c2d46..7e6b68969cec0 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -634,25 +634,6 @@ static inline unsigned int blk_chunk_sectors_left(sector_t offset,
return chunk_sectors - (offset & (chunk_sectors - 1));
}
-/*
- * Return maximum size of a request at given offset. Only valid for
- * file system requests.
- */
-static inline unsigned int blk_max_size_offset(struct request_queue *q,
- sector_t offset,
- unsigned int chunk_sectors)
-{
- if (!chunk_sectors) {
- if (q->limits.chunk_sectors)
- chunk_sectors = q->limits.chunk_sectors;
- else
- return q->limits.max_sectors;
- }
-
- return min(q->limits.max_sectors,
- blk_chunk_sectors_left(offset, chunk_sectors));
-}
-
/*
* Access functions for manipulating queue properties
*/
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [dm-devel] [PATCH 5/6] block: fold blk_max_size_offset into get_max_io_size
@ 2021-10-13 17:12 ` Christoph Hellwig
0 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, dm-devel, Mike Snitzer
Fold blk_max_size_offset into the only remaining user.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-merge.c | 15 ++++++++++-----
include/linux/blkdev.h | 19 -------------------
2 files changed, 10 insertions(+), 24 deletions(-)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 3e9dde152fdcd..87ea3e7b8ad28 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -177,14 +177,19 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q,
static inline unsigned get_max_io_size(struct request_queue *q,
struct bio *bio)
{
- unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector, 0);
- unsigned max_sectors = sectors;
unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT;
unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT;
- unsigned start_offset = bio->bi_iter.bi_sector & (pbs - 1);
+ sector_t sector = bio->bi_iter.bi_sector;
+ unsigned start_offset = sector & (pbs - 1);
+ unsigned sectors = q->limits.max_sectors;
+ unsigned max_sectors;
+
+ if (q->limits.chunk_sectors) {
+ sectors = min(sectors, blk_chunk_sectors_left(sector,
+ q->limits.chunk_sectors));
+ }
- max_sectors += start_offset;
- max_sectors &= ~(pbs - 1);
+ max_sectors = (sectors + start_offset) & ~(pbs - 1);
if (max_sectors > start_offset)
return max_sectors - start_offset;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index c6ecd996c2d46..7e6b68969cec0 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -634,25 +634,6 @@ static inline unsigned int blk_chunk_sectors_left(sector_t offset,
return chunk_sectors - (offset & (chunk_sectors - 1));
}
-/*
- * Return maximum size of a request at given offset. Only valid for
- * file system requests.
- */
-static inline unsigned int blk_max_size_offset(struct request_queue *q,
- sector_t offset,
- unsigned int chunk_sectors)
-{
- if (!chunk_sectors) {
- if (q->limits.chunk_sectors)
- chunk_sectors = q->limits.chunk_sectors;
- else
- return q->limits.max_sectors;
- }
-
- return min(q->limits.max_sectors,
- blk_chunk_sectors_left(offset, chunk_sectors));
-}
-
/*
* Access functions for manipulating queue properties
*/
--
2.30.2
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 6/6] block: pass the start sector to get_max_io_size
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
@ 2021-10-13 17:12 ` Christoph Hellwig
-1 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: Mike Snitzer, linux-block, dm-devel
Pass the start sector instead of the whole bio.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-merge.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 87ea3e7b8ad28..7498f570aa302 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -174,12 +174,10 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q,
* requests that are submitted to a block device if the start of a bio is not
* aligned to a physical block boundary.
*/
-static inline unsigned get_max_io_size(struct request_queue *q,
- struct bio *bio)
+static inline unsigned get_max_io_size(struct request_queue *q, sector_t sector)
{
unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT;
unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT;
- sector_t sector = bio->bi_iter.bi_sector;
unsigned start_offset = sector & (pbs - 1);
unsigned sectors = q->limits.max_sectors;
unsigned max_sectors;
@@ -288,7 +286,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
struct bio_vec bv, bvprv, *bvprvp = NULL;
struct bvec_iter iter;
unsigned nsegs = 0, sectors = 0;
- const unsigned max_sectors = get_max_io_size(q, bio);
+ const unsigned max_sectors = get_max_io_size(q, bio->bi_iter.bi_sector);
const unsigned max_segs = queue_max_segments(q);
bio_for_each_bvec(bv, bio, iter) {
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [dm-devel] [PATCH 6/6] block: pass the start sector to get_max_io_size
@ 2021-10-13 17:12 ` Christoph Hellwig
0 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2021-10-13 17:12 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, dm-devel, Mike Snitzer
Pass the start sector instead of the whole bio.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
block/blk-merge.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 87ea3e7b8ad28..7498f570aa302 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -174,12 +174,10 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q,
* requests that are submitted to a block device if the start of a bio is not
* aligned to a physical block boundary.
*/
-static inline unsigned get_max_io_size(struct request_queue *q,
- struct bio *bio)
+static inline unsigned get_max_io_size(struct request_queue *q, sector_t sector)
{
unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT;
unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT;
- sector_t sector = bio->bi_iter.bi_sector;
unsigned start_offset = sector & (pbs - 1);
unsigned sectors = q->limits.max_sectors;
unsigned max_sectors;
@@ -288,7 +286,7 @@ static struct bio *blk_bio_segment_split(struct request_queue *q,
struct bio_vec bv, bvprv, *bvprvp = NULL;
struct bvec_iter iter;
unsigned nsegs = 0, sectors = 0;
- const unsigned max_sectors = get_max_io_size(q, bio);
+ const unsigned max_sectors = get_max_io_size(q, bio->bi_iter.bi_sector);
const unsigned max_segs = queue_max_segments(q);
bio_for_each_bvec(bv, bio, iter) {
--
2.30.2
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH 1/6] block: factor out a chunk_size_left helper
2022-06-16 23:05 ` Mike Snitzer
@ 2022-06-17 6:22 ` Christoph Hellwig
0 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2022-06-17 6:22 UTC (permalink / raw)
To: Mike Snitzer
Cc: Christoph Hellwig, Jens Axboe, Mike Snitzer, dm-devel, linux-block
On Thu, Jun 16, 2022 at 07:05:48PM -0400, Mike Snitzer wrote:
> > + return min(q->limits.max_sectors,
> > + blk_chunk_sectors_left(offset, chunk_sectors));
> > }
>
> While you're at it, any reason not to use queue_max_sectors() here?
I'm not sure if it is a good reason, but this code sniplet goes
away later in the series, and all replacemens do use queue_max_sectors.
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 1/6] block: factor out a chunk_size_left helper
2022-06-14 9:09 ` [PATCH 1/6] block: factor out a chunk_size_left helper Christoph Hellwig
2022-06-14 16:39 ` Bart Van Assche
2022-06-15 10:32 ` Pankaj Raghav
@ 2022-06-16 23:05 ` Mike Snitzer
2022-06-17 6:22 ` Christoph Hellwig
2 siblings, 1 reply; 19+ messages in thread
From: Mike Snitzer @ 2022-06-16 23:05 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Jens Axboe, Mike Snitzer, dm-devel, linux-block
On Tue, Jun 14 2022 at 5:09P -0400,
Christoph Hellwig <hch@lst.de> wrote:
> Factor out a helper from blk_max_size_offset so that it can be reused
> independently.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> include/linux/blkdev.h | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 914c613d81da7..e66ad451274ec 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -933,6 +933,17 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
> return q->limits.max_sectors;
> }
>
> +/*
> + * Return how much of the chunk is left to be used for I/O at a given offset.
> + */
> +static inline unsigned int blk_chunk_sectors_left(sector_t offset,
> + unsigned int chunk_sectors)
> +{
> + if (unlikely(!is_power_of_2(chunk_sectors)))
> + return chunk_sectors - sector_div(offset, chunk_sectors);
> + return chunk_sectors - (offset & (chunk_sectors - 1));
> +}
> +
> /*
> * Return maximum size of a request at given offset. Only valid for
> * file system requests.
> @@ -948,12 +959,8 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
> return q->limits.max_sectors;
> }
>
> - if (likely(is_power_of_2(chunk_sectors)))
> - chunk_sectors -= offset & (chunk_sectors - 1);
> - else
> - chunk_sectors -= sector_div(offset, chunk_sectors);
> -
> - return min(q->limits.max_sectors, chunk_sectors);
> + return min(q->limits.max_sectors,
> + blk_chunk_sectors_left(offset, chunk_sectors));
> }
While you're at it, any reason not to use queue_max_sectors() here?
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 1/6] block: factor out a chunk_size_left helper
2022-06-14 9:09 ` [PATCH 1/6] block: factor out a chunk_size_left helper Christoph Hellwig
2022-06-14 16:39 ` Bart Van Assche
@ 2022-06-15 10:32 ` Pankaj Raghav
2022-06-16 23:05 ` Mike Snitzer
2 siblings, 0 replies; 19+ messages in thread
From: Pankaj Raghav @ 2022-06-15 10:32 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Jens Axboe, Mike Snitzer, dm-devel, linux-block, Pankaj Raghav
On Tue, Jun 14, 2022 at 11:09:29AM +0200, Christoph Hellwig wrote:
> Factor out a helper from blk_max_size_offset so that it can be reused
> independently.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> include/linux/blkdev.h | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
Looks good,
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 1/6] block: factor out a chunk_size_left helper
2022-06-14 9:09 ` [PATCH 1/6] block: factor out a chunk_size_left helper Christoph Hellwig
@ 2022-06-14 16:39 ` Bart Van Assche
2022-06-15 10:32 ` Pankaj Raghav
2022-06-16 23:05 ` Mike Snitzer
2 siblings, 0 replies; 19+ messages in thread
From: Bart Van Assche @ 2022-06-14 16:39 UTC (permalink / raw)
To: Christoph Hellwig, Jens Axboe; +Cc: Mike Snitzer, dm-devel, linux-block
On 6/14/22 02:09, Christoph Hellwig wrote:
> Factor out a helper from blk_max_size_offset so that it can be reused
> independently.
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 1/6] block: factor out a chunk_size_left helper
2022-06-14 9:09 clean up the chunk_sizehandling helpers a little Christoph Hellwig
@ 2022-06-14 9:09 ` Christoph Hellwig
2022-06-14 16:39 ` Bart Van Assche
` (2 more replies)
0 siblings, 3 replies; 19+ messages in thread
From: Christoph Hellwig @ 2022-06-14 9:09 UTC (permalink / raw)
To: Jens Axboe; +Cc: Mike Snitzer, dm-devel, linux-block
Factor out a helper from blk_max_size_offset so that it can be reused
independently.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/blkdev.h | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 914c613d81da7..e66ad451274ec 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -933,6 +933,17 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
return q->limits.max_sectors;
}
+/*
+ * Return how much of the chunk is left to be used for I/O at a given offset.
+ */
+static inline unsigned int blk_chunk_sectors_left(sector_t offset,
+ unsigned int chunk_sectors)
+{
+ if (unlikely(!is_power_of_2(chunk_sectors)))
+ return chunk_sectors - sector_div(offset, chunk_sectors);
+ return chunk_sectors - (offset & (chunk_sectors - 1));
+}
+
/*
* Return maximum size of a request at given offset. Only valid for
* file system requests.
@@ -948,12 +959,8 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
return q->limits.max_sectors;
}
- if (likely(is_power_of_2(chunk_sectors)))
- chunk_sectors -= offset & (chunk_sectors - 1);
- else
- chunk_sectors -= sector_div(offset, chunk_sectors);
-
- return min(q->limits.max_sectors, chunk_sectors);
+ return min(q->limits.max_sectors,
+ blk_chunk_sectors_left(offset, chunk_sectors));
}
/*
--
2.30.2
^ permalink raw reply related [flat|nested] 19+ messages in thread
end of thread, other threads:[~2022-06-17 6:22 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 17:12 simplify I/O size calculation helpers v2 Christoph Hellwig
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
2021-10-13 17:12 ` [PATCH 1/6] block: factor out a chunk_size_left helper Christoph Hellwig
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
2021-10-13 17:12 ` [PATCH 2/6] dm: open code blk_max_size_offset in max_io_len Christoph Hellwig
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
2021-10-13 17:12 ` [dm-devel] [PATCH 3/6] block: only call blk_queue_get_max_sectors once in blk_rq_get_max_sectors Christoph Hellwig
2021-10-13 17:12 ` Christoph Hellwig
2021-10-13 17:12 ` [PATCH 4/6] block: open code blk_max_size_offset " Christoph Hellwig
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
2021-10-13 17:12 ` [PATCH 5/6] block: fold blk_max_size_offset into get_max_io_size Christoph Hellwig
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
2021-10-13 17:12 ` [PATCH 6/6] block: pass the start sector to get_max_io_size Christoph Hellwig
2021-10-13 17:12 ` [dm-devel] " Christoph Hellwig
2022-06-14 9:09 clean up the chunk_sizehandling helpers a little Christoph Hellwig
2022-06-14 9:09 ` [PATCH 1/6] block: factor out a chunk_size_left helper Christoph Hellwig
2022-06-14 16:39 ` Bart Van Assche
2022-06-15 10:32 ` Pankaj Raghav
2022-06-16 23:05 ` Mike Snitzer
2022-06-17 6:22 ` Christoph Hellwig
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.