* [PATCH] block: simplify blksize_bits() implementation
@ 2022-10-26 15:14 Dawei Li
2022-10-26 16:29 ` Bart Van Assche
0 siblings, 1 reply; 3+ messages in thread
From: Dawei Li @ 2022-10-26 15:14 UTC (permalink / raw)
To: axboe; +Cc: hch, linux-block, linux-kernel, Dawei Li
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>
---
include/linux/blkdev.h | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 50e358a19d98..117061c8b9a1 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 size > 512 ? order_base_2(size) : 9;
}
static inline unsigned int block_size(struct block_device *bdev)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] block: simplify blksize_bits() implementation
2022-10-26 15:14 [PATCH] block: simplify blksize_bits() implementation Dawei Li
@ 2022-10-26 16:29 ` Bart Van Assche
2022-10-26 16:34 ` Keith Busch
0 siblings, 1 reply; 3+ messages in thread
From: Bart Van Assche @ 2022-10-26 16:29 UTC (permalink / raw)
To: Dawei Li, axboe; +Cc: hch, linux-block, linux-kernel
On 10/26/22 08:14, Dawei Li wrote:
> Convert current looping-based implementation into bit operation,
> which can bring improvement for:
>
> 1) bitops is more efficient for its arch-level optimization.
As far as I know blksize_bits() is not used in the hot path so
performance of this function is not critical.
> 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>
> ---
> include/linux/blkdev.h | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index 50e358a19d98..117061c8b9a1 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 size > 512 ? order_base_2(size) : 9;
> }
How about optimizing this function even further by eliminating the
ternary operator, e.g. as follows (untested)?
return order_base_2(size >> SECTOR_SHIFT) + SECTOR_SHIFT;
Thanks,
Bart.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: simplify blksize_bits() implementation
2022-10-26 16:29 ` Bart Van Assche
@ 2022-10-26 16:34 ` Keith Busch
0 siblings, 0 replies; 3+ messages in thread
From: Keith Busch @ 2022-10-26 16:34 UTC (permalink / raw)
To: Bart Van Assche; +Cc: Dawei Li, axboe, hch, linux-block, linux-kernel
On Wed, Oct 26, 2022 at 09:29:21AM -0700, Bart Van Assche wrote:
> On 10/26/22 08:14, Dawei Li wrote:
> > Convert current looping-based implementation into bit operation,
> > which can bring improvement for:
> >
> > 1) bitops is more efficient for its arch-level optimization.
>
> As far as I know blksize_bits() is not used in the hot path so performance
> of this function is not critical.
blksize_bits() is used on every IO going through iomap_dio_bio_iter(),
though the usage there is completely unnecessary and can be removed.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-26 16:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26 15:14 [PATCH] block: simplify blksize_bits() implementation Dawei Li
2022-10-26 16:29 ` Bart Van Assche
2022-10-26 16:34 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).