From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jens Axboe Date: Fri, 29 May 2020 16:39:26 -0600 Subject: [Ocfs2-devel] [PATCH v2] blkdev: Replace blksize_bits() with ilog2() In-Reply-To: References: <20200529141100.37519-1-pilgrimtao@gmail.com> <20200529202713.GC19604@bombadil.infradead.org> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Bart Van Assche , Matthew Wilcox , Kaitao Cheng Cc: hch@lst.de, sth@linux.ibm.com, viro@zeniv.linux.org.uk, clm@fb.com, jaegeuk@kernel.org, hch@infradead.org, mark@fasheh.com, dhowells@redhat.com, balbi@kernel.org, damien.lemoal@wdc.com, ming.lei@redhat.com, martin.petersen@oracle.com, satyat@google.com, chaitanya.kulkarni@wdc.com, houtao1@huawei.com, asml.silence@gmail.com, ajay.joshi@wdc.com, linux-kernel@vger.kernel.org, songmuchun@bytedance.com, hoeppner@linux.ibm.com, heiko.carstens@de.ibm.com, gor@linux.ibm.com, borntraeger@de.ibm.com, linux-s390@vger.kernel.org, sagi@grimberg.me, linux-nvme@lists.infradead.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, josef@toxicpanda.com, dsterba@suse.com, linux-btrfs@vger.kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, darrick.wong@oracle.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, ocfs2-devel@oss.oracle.com, deepa.kernel@gmail.com On 5/29/20 4:27 PM, Bart Van Assche wrote: > On 2020-05-29 13:27, Matthew Wilcox wrote: >> On Fri, May 29, 2020 at 10:11:00PM +0800, Kaitao Cheng wrote: >>> There is a function named ilog2() exist which can replace blksize. >>> The generated code will be shorter and more efficient on some >>> architecture, such as arm64. And ilog2() can be optimized according >>> to different architecture. >> >> We'd get the same benefit from a smaller patch with just: >> >> --- a/include/linux/blkdev.h >> +++ b/include/linux/blkdev.h >> @@ -1502,15 +1502,9 @@ static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr, >> return !(addr & alignment) && !(len & alignment); >> } >> >> -/* 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) > > Hi Matthew, > > I had suggested to change all blksize_bits() calls into ilog2() calls > because I think that a single function to calculate the logarithm base 2 > is sufficient. I think this should be a two-parter: 1) Use the inode blkbits where appropriate 2) Then do this change I'm leaning towards just doing it in blksize_bits() instead of updating every caller, unless there aren't that many left once we've gone through patch 1. -- Jens Axboe