Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1429830 > unrolled thread
| Started by | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| First post | 2016-06-23 15:40 +0200 |
| Last post | 2016-06-27 18:40 +0200 |
| Articles | 4 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH v2 1/3] block: provide helpers for reading block count Arnd Bergmann <arnd@arndb.de> - 2016-06-23 15:40 +0200
Re: [PATCH v2 1/3] block: provide helpers for reading block count Christoph Hellwig <hch@infradead.org> - 2016-06-23 16:30 +0200
Re: [PATCH v2 1/3] block: provide helpers for reading block count Sagi Grimberg <sagi@grimberg.me> - 2016-06-23 18:00 +0200
Re: [PATCH v2 1/3] block: provide helpers for reading block count Davidlohr Bueso <dave@stgolabs.net> - 2016-06-27 18:40 +0200
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2016-06-23 15:40 +0200 |
| Subject | [PATCH v2 1/3] block: provide helpers for reading block count |
| Message-ID | <rNcRH-27f-3@gated-at.bofh.it> |
Several drivers use an expensive do_div() to compute the number
of logical or physical blocks in a blockdev, which can be done
more efficiently using a shift, since the blocksize is always
a power of two number.
Let's introduce bdev_logical_block_count() and bdev_physical_block_count()
helper functions mirroring the bdev_logical_block_size() and
bdev_physical_block_size() interfaces for the block size.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Suggested-by: Christoph Hellwig <hch@infradead.org>
---
include/linux/blkdev.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9d1e0a4650dc..ae8c408f6c22 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1226,6 +1226,13 @@ static inline unsigned short bdev_logical_block_size(struct block_device *bdev)
return queue_logical_block_size(bdev_get_queue(bdev));
}
+static inline sector_t bdev_logical_block_count(struct block_device *bdev)
+{
+ unsigned int block_shift = ilog2(bdev_logical_block_size(bdev));
+
+ return bdev->bd_inode->i_size >> block_shift;
+}
+
static inline unsigned int queue_physical_block_size(struct request_queue *q)
{
return q->limits.physical_block_size;
@@ -1236,6 +1243,13 @@ static inline unsigned int bdev_physical_block_size(struct block_device *bdev)
return queue_physical_block_size(bdev_get_queue(bdev));
}
+static inline sector_t bdev_physical_block_count(struct block_device *bdev)
+{
+ unsigned int block_shift = ilog2(bdev_physical_block_size(bdev));
+
+ return bdev->bd_inode->i_size >> block_shift;
+}
+
static inline unsigned int queue_io_min(struct request_queue *q)
{
return q->limits.io_min;
--
2.9.0
[toc] | [next] | [standalone]
| From | Christoph Hellwig <hch@infradead.org> |
|---|---|
| Date | 2016-06-23 16:30 +0200 |
| Message-ID | <rNdNM-2OV-13@gated-at.bofh.it> |
| In reply to | #1429830 |
Thanks Arnd, the series looks fine to me: Reviewed-by: Christoph Hellwig <hch@lst.de>
[toc] | [prev] | [next] | [standalone]
| From | Sagi Grimberg <sagi@grimberg.me> |
|---|---|
| Date | 2016-06-23 18:00 +0200 |
| Message-ID | <rNfcS-3Iu-11@gated-at.bofh.it> |
| In reply to | #1429830 |
Looks good, for the series: Reviewed-by: Sagi Grimbeg <sagi@grimbeg.me>
[toc] | [prev] | [next] | [standalone]
| From | Davidlohr Bueso <dave@stgolabs.net> |
|---|---|
| Date | 2016-06-27 18:40 +0200 |
| Message-ID | <rOHJM-2Ik-25@gated-at.bofh.it> |
| In reply to | #1429830 |
On Thu, 23 Jun 2016, Arnd Bergmann wrote: >Several drivers use an expensive do_div() to compute the number >of logical or physical blocks in a blockdev, which can be done >more efficiently using a shift, since the blocksize is always >a power of two number. > >Let's introduce bdev_logical_block_count() and bdev_physical_block_count() >helper functions mirroring the bdev_logical_block_size() and >bdev_physical_block_size() interfaces for the block size. >@@ -1226,6 +1226,13 @@ static inline unsigned short bdev_logical_block_size(struct block_device *bdev) > return queue_logical_block_size(bdev_get_queue(bdev)); > } > >+static inline sector_t bdev_logical_block_count(struct block_device *bdev) Curious, why not just return u64 instead for all these instead of sector_t (ie dealing with lba, it reads weird)? Thanks, Davidlohr
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web