Block layer cleanup patches
cover Block layer cleanup patches
Hi Jens,
There are two cleanup patches in this series and one small performance improvement patch. Please consider these patches for the next merge window.
Changes compared to v1:
- Extracted these patches from a larger patch series.
- Added Mings' Reviewed-by.
Bart Van Assche (3):
block: Remove request.write_hint
block: Constify most queue limits pointers
block: Micro-optimize get_max_segment_size()
block/blk-map.c | 2 +- block/blk-merge.c | 44 ++++++++++++++++++++++++++---------------- block/blk-settings.c | 6 +++--- block/blk.h | 11 ++++++----- include/linux/blk-mq.h | 1 - 5 files changed, 37 insertions(+), 27 deletions(-)
PATCH v2 1/3 block: Remove request.write_hint
Commit c75e707fe1aa ("block: remove the per-bio/request write hint") removed all code that uses the struct request write_hint member. Hence also remove 'write_hint' itself.
--- include/linux/blk-mq.h | 1 - 1 file changed, 1 deletion(-)
include/linux/blk-mq.h +0 -1
@@ -140,7 +140,6 @@ struct request {struct blk_crypto_keyslot *crypt_keyslot;#endif -unsigned short write_hint;unsigned short ioprio;enum mq_rq_state state;
PATCH v2 2/3 block: Constify most queue limits pointers
In reply to Bart Van AsscheDocument which functions do not modify the queue limits.
--- block/blk-map.c | 2 +- block/blk-merge.c | 29 ++++++++++++++++------------- block/blk-settings.c | 6 +++--- block/blk.h | 11 ++++++----- 4 files changed, 26 insertions(+), 22 deletions(-)
block/blk-map.c +1 -1
@@ -555,7 +555,7 @@ static int blk_rq_map_user_bvec(struct request *rq, const struct iov_iter *iter)size_t nr_iter =iov_iter_count (iter);size_t nr_segs = iter->nr_segs;struct bio_vec *bvecs, *bvprvp =NULL ; -struct queue_limits *lim = &q->limits; +const struct queue_limits *lim = &q->limits;unsigned int nsegs =0 , bytes =0 ;struct bio *bio;size_t i;
block/blk-merge.c +16 -13
@@ -100,13 +100,14 @@ static inline bool req_gap_front_merge(struct request *req, struct bio *bio)* is defined as 'unsigned int', meantime it has to be aligned to with the * logical block size, which is the minimum accepted unit by hardware. */ -static unsigned int bio_allowed_max_sectors (struct queue_limits *lim) +static unsigned int bio_allowed_max_sectors (const struct queue_limits *lim) {return round_down (UINT_MAX , lim->logical_block_size) >>SECTOR_SHIFT ; } -static struct bio *bio_split_discard (struct bio *bio,struct queue_limits *lim, -unsigned *nsegs,struct bio_set *bs) +static struct bio *bio_split_discard (struct bio *bio, +const struct queue_limits *lim, +unsigned *nsegs,struct bio_set *bs) {unsigned int max_discard_sectors, granularity;sector_t tmp;
@@ -146,7 +147,8 @@ static struct bio *bio_split_discard(struct bio *bio, struct queue_limits *lim, }static struct bio *bio_split_write_zeroes (struct bio *bio, -struct queue_limits *lim,unsigned *nsegs,struct bio_set *bs) +const struct queue_limits *lim, +unsigned *nsegs,struct bio_set *bs) { *nsegs =0 ;if (!lim->max_write_zeroes_sectors)
@@ -165,7 +167,7 @@ static struct bio *bio_split_write_zeroes(struct bio *bio,* aligned to a physical block boundary. */ static inline unsigned get_max_io_size (struct bio *bio, -struct queue_limits *lim) +const struct queue_limits *lim) {unsigned pbs = lim->physical_block_size >>SECTOR_SHIFT ;unsigned lbs = lim->logical_block_size >>SECTOR_SHIFT ;
@@ -184,7 +186,7 @@ static inline unsigned get_max_io_size(struct bio *bio,return max_sectors & ~(lbs -1 ); } -static inline unsigned get_max_segment_size (struct queue_limits *lim, +static inline unsigned get_max_segment_size (const struct queue_limits *lim,struct page *start_page,unsigned long offset) {unsigned long mask = lim->seg_boundary_mask;
@@ -219,9 +221,9 @@ static inline unsigned get_max_segment_size(struct queue_limits *lim,* *@nsegs segments and *@sectors sectors would make that bio unacceptable for * the block driver. */ -static bool bvec_split_segs (struct queue_limits *lim,const struct bio_vec *bv, -unsigned *nsegs,unsigned *bytes,unsigned max_segs, -unsigned max_bytes) +static bool bvec_split_segs (const struct queue_limits *lim, +const struct bio_vec *bv,unsigned *nsegs,unsigned *bytes, +unsigned max_segs,unsigned max_bytes) {unsigned max_len =min (max_bytes,UINT_MAX ) - *bytes;unsigned len =min (bv->bv_len, max_len);
@@ -267,7 +269,7 @@ static bool bvec_split_segs(struct queue_limits *lim, const struct bio_vec *bv,* responsible for ensuring that @bs is only destroyed after processing of the * split bio has finished. */ -static struct bio *bio_split_rw (struct bio *bio,struct queue_limits *lim, +static struct bio *bio_split_rw (struct bio *bio,const struct queue_limits *lim,unsigned *segs,struct bio_set *bs,unsigned max_bytes) {struct bio_vec bv, bvprv, *bvprvp =NULL ;
@@ -331,8 +333,9 @@ static struct bio *bio_split_rw(struct bio *bio, struct queue_limits *lim,* The split bio is allocated from @q->bio_split, which is provided by the * block layer. */ -struct bio *__bio_split_to_limits (struct bio *bio,struct queue_limits *lim, -unsigned int *nr_segs) +struct bio *__bio_split_to_limits (struct bio *bio, +const struct queue_limits *lim, +unsigned int *nr_segs) {struct bio_set *bs = &bio->bi_bdev->bd_disk->bio_split;struct bio *split;
@@ -377,7 +380,7 @@ struct bio *__bio_split_to_limits(struct bio *bio, struct queue_limits *lim,*/ struct bio *bio_split_to_limits (struct bio *bio) { -struct queue_limits *lim = &bdev_get_queue (bio->bi_bdev)->limits; +const struct queue_limits *lim = &bdev_get_queue (bio->bi_bdev)->limits;unsigned int nr_segs;if (bio_may_exceed_limits (bio, lim))
block/blk-settings.c +3 -3
@@ -481,7 +481,7 @@ void blk_queue_io_opt(struct request_queue *q, unsigned int opt) }EXPORT_SYMBOL (blk_queue_io_opt); -static int queue_limit_alignment_offset (struct queue_limits *lim, +static int queue_limit_alignment_offset (const struct queue_limits *lim,sector_t sector) {unsigned int granularity =max (lim->physical_block_size, lim->io_min);
@@ -491,8 +491,8 @@ static int queue_limit_alignment_offset(struct queue_limits *lim,return (granularity + lim->alignment_offset - alignment) % granularity; } -static unsigned int queue_limit_discard_alignment (struct queue_limits *lim, -sector_t sector) +static unsigned int queue_limit_discard_alignment ( +const struct queue_limits *lim,sector_t sector) {unsigned int alignment, granularity, offset;
block/blk.h +6 -5
@@ -104,7 +104,7 @@ static inline bool biovec_phys_mergeable(struct request_queue *q,return true; } -static inline bool __bvec_gap_to_prev (struct queue_limits *lim, +static inline bool __bvec_gap_to_prev (const struct queue_limits *lim,struct bio_vec *bprv,unsigned int offset) { return (offset & lim->virt_boundary_mask) ||
@@ -115,7 +115,7 @@ static inline bool __bvec_gap_to_prev(struct queue_limits *lim,* Check if adding a bio_vec after bprv with offset would create a gap in * the SG list. Most drivers don't care about this, but some do. */ -static inline bool bvec_gap_to_prev (struct queue_limits *lim, +static inline bool bvec_gap_to_prev (const struct queue_limits *lim,struct bio_vec *bprv,unsigned int offset) {if (!lim->virt_boundary_mask)
@@ -297,7 +297,7 @@ ssize_t part_timeout_store(struct device *, struct device_attribute *, const char *, size_t);static inline bool bio_may_exceed_limits (struct bio *bio, -struct queue_limits *lim) +const struct queue_limits *lim) {switch (bio_op (bio)) {case REQ_OP_DISCARD :
@@ -320,8 +320,9 @@ static inline bool bio_may_exceed_limits(struct bio *bio, bio->bi_io_vec->bv_len + bio->bi_io_vec->bv_offset >PAGE_SIZE ; } -struct bio *__bio_split_to_limits (struct bio *bio,struct queue_limits *lim, -unsigned int *nr_segs); +struct bio *__bio_split_to_limits (struct bio *bio, +const struct queue_limits *lim, +unsigned int *nr_segs);int ll_back_merge_fn (struct request *req,struct bio *bio,unsigned int nr_segs); bool blk_attempt_req_merge(struct request_queue *q, struct request *rq,
PATCH v2 3/3 block: Micro-optimize get_max_segment_size()
In reply to Bart Van AsscheThis patch removes a conditional jump from get_max_segment_size(). The x86-64 assembler code for this function without this patch is as follows:
206 return min_not_zero(mask - offset + 1,
0x0000000000000118 <+72>: not %rax 0x000000000000011b <+75>: and 0x8(%r10),%rax 0x000000000000011f <+79>: add $0x1,%rax 0x0000000000000123 <+83>: je 0x138 <bvec_split_segs+104> 0x0000000000000125 <+85>: cmp %rdx,%rax 0x0000000000000128 <+88>: mov %rdx,%r12 0x000000000000012b <+91>: cmovbe %rax,%r12 0x000000000000012f <+95>: test %rdx,%rdx 0x0000000000000132 <+98>: mov %eax,%edx 0x0000000000000134 <+100>: cmovne %r12d,%edx
With this patch applied:
206 return min(mask - offset, (unsigned long)lim->max_segment_size - 1) + 1;
0x000000000000003f <+63>: mov 0x28(%rdi),%ebp 0x0000000000000042 <+66>: not %rax 0x0000000000000045 <+69>: and 0x8(%rdi),%rax 0x0000000000000049 <+73>: sub $0x1,%rbp 0x000000000000004d <+77>: cmp %rbp,%rax 0x0000000000000050 <+80>: cmova %rbp,%rax 0x0000000000000054 <+84>: add $0x1,%eax
--- block/blk-merge.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
block/blk-merge.c +11 -4
@@ -186,6 +186,14 @@ static inline unsigned get_max_io_size(struct bio *bio,return max_sectors & ~(lbs -1 ); } +/** +* get_max_segment_size() - maximum number of bytes to add as a single segment +* @lim: Request queue limits. +* @start_page: See below. +* @offset: Offset from @start_page where to add a segment. +* +* Returns the maximum number of bytes that can be added as a single segment. +*/ static inline unsigned get_max_segment_size (const struct queue_limits *lim,struct page *start_page,unsigned long offset) {
@@ -194,11 +202,10 @@ static inline unsigned get_max_segment_size(const struct queue_limits *lim, offset = mask & (page_to_phys (start_page) + offset);/* -* overflow may be triggered in case of zero page physical address -* on 32bit arch, use queue's max segment size when that happens. +* Prevent an overflow if mask = ULONG_MAX and offset = 0 by adding 1 +* after having calculated the minimum. */ -return min_not_zero (mask - offset +1 , - (unsigned long )lim->max_segment_size); +return min (mask - offset, (unsigned long )lim->max_segment_size -1 ) +1 ; }/**
This series looks good to me.
Quoted 8 lines · Bart Van Assche
There are two cleanup patches in this series and one small performance improvement patch. Please consider these patches for the next merge window.
Changes compared to v1:
- Extracted these patches from a larger patch series.
- Added Mings' Reviewed-by.[...]
Applied, thanks!
[1/3] block: Remove request.write_hint
commit: b179c98f76978a0fae072c2b2dad8e143218afd8
[2/3] block: Constify most queue limits pointers
commit: aa261f20589d894eb08b9a2b11c9672c548387cd
[3/3] block: Micro-optimize get_max_segment_size()
commit: 95465318849f7525f4dce1b720e4627f48963327Best regards,
Signature · 1 line
Jens Axboe