All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] block: simplify blksize_bits() implementation
@ 2022-10-30  5:20 Dawei Li
  2022-10-30  7:36 ` Christoph Hellwig
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dawei Li @ 2022-10-30  5:20 UTC (permalink / raw)
  To: axboe; +Cc: bvanassche, 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.

v1: https://lore.kernel.org/all/TYCP286MB2323169D81A806A7C1F7FDF1CA309@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM

v2: Remove the ternary operator, based on Bart's suggestion
    But this may lead to break for corner cases below:
    BUILD_BUG_ON(blksize_bits(1025) != 11);
    So make a minor modification by adding (SECTOR_SIZE - 1) before
    shifting.

v3: Remove the rounding stuff.

base-commit: 30209debe98b6f66b13591e59e5272cb65b3945e

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 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)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] block: simplify blksize_bits() implementation
  2022-10-30  5:20 [PATCH v3] block: simplify blksize_bits() implementation Dawei Li
@ 2022-10-30  7:36 ` Christoph Hellwig
  2022-10-30 14:34 ` Bart Van Assche
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-10-30  7:36 UTC (permalink / raw)
  To: Dawei Li; +Cc: axboe, bvanassche, hch, linux-block, linux-kernel

I'm not sure if it matters, but the change does look fine to me:

Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] block: simplify blksize_bits() implementation
  2022-10-30  5:20 [PATCH v3] block: simplify blksize_bits() implementation Dawei Li
  2022-10-30  7:36 ` Christoph Hellwig
@ 2022-10-30 14:34 ` Bart Van Assche
  2022-10-31  2:03 ` Chaitanya Kulkarni
  2022-10-31 13:27 ` Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2022-10-30 14:34 UTC (permalink / raw)
  To: Dawei Li, axboe; +Cc: hch, linux-block, linux-kernel

On 10/29/22 22:20, Dawei Li wrote:
> @@ -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;
>   }

Reviewed-by: Bart Van Assche <bvanassche@acm.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] block: simplify blksize_bits() implementation
  2022-10-30  5:20 [PATCH v3] block: simplify blksize_bits() implementation Dawei Li
  2022-10-30  7:36 ` Christoph Hellwig
  2022-10-30 14:34 ` Bart Van Assche
@ 2022-10-31  2:03 ` Chaitanya Kulkarni
  2022-10-31 13:27 ` Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2022-10-31  2:03 UTC (permalink / raw)
  To: Dawei Li, axboe; +Cc: bvanassche, hch, linux-block, linux-kernel

On 10/29/2022 10:20 PM, 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.
> 

do you have a quantitative date to prove that ?
Also which arch benefits the most ? is it true for all ?

> 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.
> 

patches like this needs to be supported by the quantitative
data, else I've seen reviewers taking an objection ...

either way :-

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] block: simplify blksize_bits() implementation
  2022-10-30  5:20 [PATCH v3] block: simplify blksize_bits() implementation Dawei Li
                   ` (2 preceding siblings ...)
  2022-10-31  2:03 ` Chaitanya Kulkarni
@ 2022-10-31 13:27 ` Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2022-10-31 13:27 UTC (permalink / raw)
  To: Dawei Li; +Cc: hch, bvanassche, linux-block, linux-kernel

On Sun, 30 Oct 2022 13:20:08 +0800, 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.
> 
> 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.
> 
> [...]

Applied, thanks!

[1/1] block: simplify blksize_bits() implementation
      commit: adff215830fcf3ef74f2f0d4dd5a47a6927d450b

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-31 13:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-30  5:20 [PATCH v3] block: simplify blksize_bits() implementation Dawei Li
2022-10-30  7:36 ` Christoph Hellwig
2022-10-30 14:34 ` Bart Van Assche
2022-10-31  2:03 ` Chaitanya Kulkarni
2022-10-31 13:27 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.