diff options
author | Dawei Li <set_pte_at@outlook.com> | 2022-10-30 06:20:08 +0100 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2022-10-31 14:26:27 +0100 |
commit | adff215830fcf3ef74f2f0d4dd5a47a6927d450b (patch) | |
tree | 1e00cfc3a9df9f40146a5b34dfa492a097437223 /include | |
parent | blk-mq: avoid double ->queue_rq() because of early timeout (diff) | |
download | linux-adff215830fcf3ef74f2f0d4dd5a47a6927d450b.tar.xz linux-adff215830fcf3ef74f2f0d4dd5a47a6927d450b.zip |
block: simplify blksize_bits() implementation
Convert current looping-based implementation into bit operation,
which can bring improvement for:
1) bitops is more efficient for its arch-level optimization.
2) Given that blksize_bits() is inline, _if_ @size is compile-time
constant, it's possible that order_base_2() _may_ make output
compile-time evaluated, depending on code context and compiler behavior.
Signed-off-by: Dawei Li <set_pte_at@outlook.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/TYCP286MB23238842958D7C083D6B67CECA349@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/blkdev.h | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 57ed49f20d2e..32137d85c9ad 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1349,12 +1349,7 @@ static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr, /* assumes size > 256 */ static inline unsigned int blksize_bits(unsigned int size) { - unsigned int bits = 8; - do { - bits++; - size >>= 1; - } while (size > 256); - return bits; + return order_base_2(size >> SECTOR_SHIFT) + SECTOR_SHIFT; } static inline unsigned int block_size(struct block_device *bdev) |