Skip to contentSkip to conversation

linux/blkdev.h: Use ilog2() directly in blksize_bits()

PATCH In review Kaitao Cheng 3 participants 4 messages May 23, 2020 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux/blkdev.h: Use ilog2() directly in blksize_bits()

blksize_bits() can be achieved through ilog2(), and ilog2() is more efficient.

---
 include/linux/blkdev.h | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
include/linux/blkdev.h +1 -6
index 2b33166b9daf..cce96abac4d4 100644
@@ -1505,12 +1505,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 ilog2(size);
 }
 
 static inline unsigned int block_size(struct block_device *bdev)
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 2 lines · Kaitao Cheng

blksize_bits() can be achieved through ilog2(), and ilog2() is more efficient.

I like the simplification, but do you have any results to back up that claim? Is the generated code shorter? Runs faster?

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to Kaitao Cheng
Quoted 2 lines · Kaitao Cheng

blksize_bits() can be achieved through ilog2(), and ilog2() is more efficient.

If Jens agrees, how about removing the blksize_bits() function entirely and to make all callers use ilog2() instead of blksize_bits()?

Thanks,

Bart.

maintainer
#3 lore raw
Quoted 6 lines · Bart Van Assche
Quoted 2 lines · Kaitao Cheng

blksize_bits() can be achieved through ilog2(), and ilog2() is more efficient.

If Jens agrees, how about removing the blksize_bits() function entirely and to make all callers use ilog2() instead of blksize_bits()?

Yeah, if we are going this path, then let's just kill the function completely.

Signature · 1 line
Jens Axboe