diff options
author | Bart Van Assche <bvanassche@acm.org> | 2019-08-01 18:50:44 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2019-08-04 23:41:29 -0400 |
commit | 9cc5169cd478bc596902a57580804f1da3dfd74e (patch) | |
tree | 98fedd293733a36dae88142eafd518688ada4fbd /block | |
parent | 708b25b344fd9bedd02ccc0f8eee71f7006d7d07 (diff) |
block: Improve physical block alignment of split bios
Consider the following example:
* The logical block size is 4 KB.
* The physical block size is 8 KB.
* max_sectors equals (16 KB >> 9) sectors.
* A non-aligned 4 KB and an aligned 64 KB bio are merged into a single
non-aligned 68 KB bio.
The current behavior is to split such a bio into (16 KB + 16 KB + 16 KB
+ 16 KB + 4 KB). The start of none of these five bio's is aligned to a
physical block boundary.
This patch ensures that such a bio is split into four aligned and
one non-aligned bio instead of being split into five non-aligned bios.
This improves performance because most block devices can handle aligned
requests faster than non-aligned requests.
Since the physical block size is larger than or equal to the logical
block size, this patch preserves the guarantee that the returned
value is a multiple of the logical block size.
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block')
-rw-r--r-- | block/blk-merge.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/block/blk-merge.c b/block/blk-merge.c index a6bc08255b1b..48e6725b32ee 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c | |||
@@ -132,16 +132,29 @@ static struct bio *blk_bio_write_same_split(struct request_queue *q, | |||
132 | return bio_split(bio, q->limits.max_write_same_sectors, GFP_NOIO, bs); | 132 | return bio_split(bio, q->limits.max_write_same_sectors, GFP_NOIO, bs); |
133 | } | 133 | } |
134 | 134 | ||
135 | /* | ||
136 | * Return the maximum number of sectors from the start of a bio that may be | ||
137 | * submitted as a single request to a block device. If enough sectors remain, | ||
138 | * align the end to the physical block size. Otherwise align the end to the | ||
139 | * logical block size. This approach minimizes the number of non-aligned | ||
140 | * requests that are submitted to a block device if the start of a bio is not | ||
141 | * aligned to a physical block boundary. | ||
142 | */ | ||
135 | static inline unsigned get_max_io_size(struct request_queue *q, | 143 | static inline unsigned get_max_io_size(struct request_queue *q, |
136 | struct bio *bio) | 144 | struct bio *bio) |
137 | { | 145 | { |
138 | unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector); | 146 | unsigned sectors = blk_max_size_offset(q, bio->bi_iter.bi_sector); |
139 | unsigned mask = queue_logical_block_size(q) - 1; | 147 | unsigned max_sectors = sectors; |
148 | unsigned pbs = queue_physical_block_size(q) >> SECTOR_SHIFT; | ||
149 | unsigned lbs = queue_logical_block_size(q) >> SECTOR_SHIFT; | ||
150 | unsigned start_offset = bio->bi_iter.bi_sector & (pbs - 1); | ||
140 | 151 | ||
141 | /* aligned to logical block size */ | 152 | max_sectors += start_offset; |
142 | sectors &= ~(mask >> 9); | 153 | max_sectors &= ~(pbs - 1); |
154 | if (max_sectors > start_offset) | ||
155 | return max_sectors - start_offset; | ||
143 | 156 | ||
144 | return sectors; | 157 | return sectors & (lbs - 1); |
145 | } | 158 | } |
146 | 159 | ||
147 | static unsigned get_max_segment_size(const struct request_queue *q, | 160 | static unsigned get_max_segment_size(const struct request_queue *q, |