From: Bart Van Assche <bvanassche@acm.org>
To: Dawei Li <set_pte_at@outlook.com>, axboe@kernel.dk
Cc: hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] block: simplify blksize_bits() implementation
Date: Wed, 26 Oct 2022 09:29:21 -0700 [thread overview]
Message-ID: <30ea2fa3-0e4d-788b-b990-3bdb9e687377@acm.org> (raw)
In-Reply-To: <TYCP286MB2323169D81A806A7C1F7FDF1CA309@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM>
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.
next prev parent reply other threads:[~2022-10-26 16:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-26 15:14 [PATCH] block: simplify blksize_bits() implementation Dawei Li
2022-10-26 16:29 ` Bart Van Assche [this message]
2022-10-26 16:34 ` Keith Busch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=30ea2fa3-0e4d-788b-b990-3bdb9e687377@acm.org \
--to=bvanassche@acm.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=set_pte_at@outlook.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox