Linux block layer
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Dawei Li <set_pte_at@outlook.com>
Cc: axboe@kernel.dk, hch@lst.de, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] block: simplify blksize_bits() implementation
Date: Sat, 29 Oct 2022 20:33:22 -0700	[thread overview]
Message-ID: <bc8cf710-c0ad-24e8-7849-6282c8e3bcff@acm.org> (raw)
In-Reply-To: <TYCP286MB23234B5C344600A604B17242CA349@TYCP286MB2323.JPNP286.PROD.OUTLOOK.COM>

On 10/29/22 20:25, Dawei Li wrote:
> On Sat, Oct 29, 2022 at 08:00:58PM -0700, Bart Van Assche wrote:
>> On 10/29/22 19:17, Dawei Li wrote:
>>> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
>>> index 57ed49f20d2e..7b537afe8b38 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_SIZE - 1) >> SECTOR_SHIFT) + SECTOR_SHIFT;
>>>    }
>>
>> Why the rounding ("+ SECTOR_SIZE - 1")? The blksize_bits() argument should
>> be an argument of two.
> 
> Yeah, that's what's supposed to be.
> But I thought maybe a "just in case" is more robust?
> Should we consider these corner cases(!is_power_of_2())?

I don't think that the Linux kernel supports block sizes that are not a 
power of two. Hence my request to leave out the rounding code. Keeping 
that code would be misleading because it would suggest that the 
blksize_bits() argument can be something else than a power of two.

Thanks,

Bart.


  reply	other threads:[~2022-10-30  3:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-30  2:17 [PATCH v2] block: simplify blksize_bits() implementation Dawei Li
2022-10-30  3:00 ` Bart Van Assche
2022-10-30  3:25   ` Dawei Li
2022-10-30  3:33     ` Bart Van Assche [this message]
2022-10-30  3:52       ` Dawei Li

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=bc8cf710-c0ad-24e8-7849-6282c8e3bcff@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