block: make sure discard/writesame bio is aligned with logical block size
Subsystems (2)
v2 cover block: make sure discard/writesame bio is aligned with logical block size
Hi,
The 1st & 3rd patch fixes bio size alignment issue.
The 2nd patch cleans up __blkdev_issue_discard() a bit.
V2:
- introduce helper of bio_allowed_max_sectors()
- add commit log for patch 2
Ming Lei (3):
block: make sure discard bio is aligned with logical block size
block: cleanup __blkdev_issue_discard()
block: make sure writesame bio is aligned with logical block size
block/blk-lib.c | 26 +++++++------------------- block/blk-merge.c | 3 ++- block/blk.h | 10 ++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-)
Signature · 1 line
2.9.5
PATCH v2 1/3 block: make sure discard bio is aligned with logical block size
Obviously the created discard bio has to be aligned with logical block size.
This patch introduces the helper of bio_allowed_max_sectors() for this purpose.
--- block/blk-lib.c | 3 +-- block/blk-merge.c | 3 ++- block/blk.h | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-)
block/blk-lib.c +1 -2
@@ -57,8 +57,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,if (!req_sects) goto fail; -if (req_sects >UINT_MAX >>9 ) - req_sects =UINT_MAX >>9 ; + req_sects =min (req_sects,bio_allowed_max_sectors (q)); end_sect = sector + req_sects;
block/blk-merge.c +2 -1
@@ -90,7 +90,8 @@ static struct bio *blk_bio_discard_split(struct request_queue *q,/* Zero-sector (unknown) and one-sector granularities are the same. */ granularity =max (q->limits.discard_granularity >>9 ,1U ); - max_discard_sectors =min (q->limits.max_discard_sectors,UINT_MAX >>9 ); + max_discard_sectors =min (q->limits.max_discard_sectors, +bio_allowed_max_sectors (q)); max_discard_sectors -= max_discard_sectors % granularity;if (unlikely (!max_discard_sectors)) {
block/blk.h +10 -0
@@ -396,6 +396,16 @@ static inline unsigned long blk_rq_deadline(struct request *rq) }/* +* The max size one bio can handle is UINT_MAX becasue bvec_iter.bi_size +* is defined as 'unsigned int', meantime it has to aligned to with logical +* block size which is the minimum accepted unit by hardware. +*/ +static inline unsigned int bio_allowed_max_sectors (struct request_queue *q) +{ +return round_down (UINT_MAX ,queue_logical_block_size (q)) >>9 ; +} + +/* * Internal io_context interface */ void get_io_context (struct io_context *ioc);
Signature · 1 line
2.9.5
PATCH v2 2/3 block: cleanup __blkdev_issue_discard()
In reply to Ming LeiCleanup __blkdev_issue_discard() a bit:
- remove local variable of 'end_sect'
- remove code block of 'fail'
--- block/blk-lib.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
block/blk-lib.c +6 -17
@@ -51,15 +51,12 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,if ((sector | nr_sects) & bs_mask)return -EINVAL ; -while (nr_sects) { -unsigned int req_sects = nr_sects; -sector_t end_sect; - -if (!req_sects) - goto fail; - req_sects =min (req_sects,bio_allowed_max_sectors (q)); +if (!nr_sects) +return -EINVAL ; - end_sect = sector + req_sects; +while (nr_sects) { + unsigned int req_sects = min_t(unsigned int, nr_sects, +bio_allowed_max_sectors (q)); bio =blk_next_bio (bio,0 , gfp_mask); bio->bi_iter.bi_sector = sector;
@@ -67,8 +64,8 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,bio_set_op_attrs (bio, op,0 ); bio->bi_iter.bi_size = req_sects <<9 ; + sector += req_sects; nr_sects -= req_sects; - sector = end_sect;/* * We can loop for a long time in here, if someone does
@@ -81,14 +78,6 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, *biop = bio;return 0 ; - -fail: -if (bio) { -submit_bio_wait (bio); -bio_put (bio); - } - *biop =NULL ; -return -EOPNOTSUPP ; }EXPORT_SYMBOL (__blkdev_issue_discard);
Signature · 1 line
2.9.5
PATCH v2 3/3 block: make sure writesame bio is aligned with logical block size
In reply to Ming LeiObviously the created writesame bio has to be aligned with logical block size, and use bio_allowed_max_sectors() to retrieve this number.
--- block/blk-lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/blk-lib.c +1 -1
@@ -149,7 +149,7 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector,return -EOPNOTSUPP ;/* Ensure that max_write_same_sectors doesn't overflow bi_size */ - max_write_same_sectors =UINT_MAX >>9 ; + max_write_same_sectors =bio_allowed_max_sectors (q);while (nr_sects) { bio =blk_next_bio (bio,1 , gfp_mask);
Signature · 1 line
2.9.5
Quoted 21 lines · Ming Lei
Hi,
The 1st & 3rd patch fixes bio size alignment issue.
The 2nd patch cleans up
__blkdev_issue_discard()a bit.V2:
- introduce helper ofbio_allowed_max_sectors()
- add commit log for patch 2Ming Lei (3):
block: make sure discard bio is aligned with logical block size
block: cleanup__blkdev_issue_discard()
block: make sure writesame bio is aligned with logical block sizeblock/blk-lib.c | 26 +++++++------------------- block/blk-merge.c | 3 ++- block/blk.h | 10 ++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-)
Quoted 6 lines
Cc Rui Salvaterra <[email protected]>Cc Mike Snitzer <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Xiao Ni <[email protected]>Cc Mariusz Dabrowski <[email protected]>
V2 addresses Christoph's comment by introducing bio_allowed_max_sectors().
Ping...
Thanks,
Ming
Rui Salvaterra
Tested-byQuoted 7 lines · Ming Lei
V2 addresses Christoph's comment by introducing
bio_allowed_max_sectors().Ping...
Thanks,
Ming
Hi, Ming,
Sorry for the delay. I tested your V2 against Linux 4.20-rc1 and everything seems fine. FWIW, V2 is also
Thanks again,
Rui
Quoted 9 lines · Rui Salvaterra
Quoted 7 lines · Ming Lei
V2 addresses Christoph's comment by introducing
bio_allowed_max_sectors().Ping...
Thanks,
Ming
Quoted 6 lines
Hi, Ming,
Sorry for the delay. I tested your V2 against Linux 4.20-rc1 and everything seems fine. FWIW, V2 is also
Tested-by Rui Salvaterra <[email protected]>
Rui, thanks for your test on V2.
Jens, what do you think about this patchset?
Thanks,
Ming
Jens Axboe
maintainerQuoted 12 lines · Ming Lei
Quoted 11 lines · Rui Salvaterra
Quoted 7 lines · Ming Lei
V2 addresses Christoph's comment by introducing
bio_allowed_max_sectors().Ping...
Thanks,
MingHi, Ming,
Quoted 8 lines
Quoted 4 lines
Sorry for the delay. I tested your V2 against Linux 4.20-rc1 and everything seems fine. FWIW, V2 is also
Tested-by Rui Salvaterra <[email protected]>Rui, thanks for your test on V2.
Jens, what do you think about this patchset?
I waffled on this a bit... I generally don't like cleanup patches for fixes that are going into the current series. Those kinds of patches should be as short and sweet as possible, and cleanup part usually ends up being the problematic one, ironically enough. But it looks fine to me, so I've put it in.
Signature · 1 line
Jens Axboe