[dm-devel] [PARCH] dm-bufio: avoid division

Mikulas Patocka mpatocka at redhat.com
Sun Apr 30 21:32:28 UTC 2017


Division is slow, we can change it to shift because we have precalculated the
log2 of block size.

Signed-off-by: Mikulas Patocka <mpatocka at redhat.com>

---
 drivers/md/dm-bufio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-2.6/drivers/md/dm-bufio.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-bufio.c
+++ linux-2.6/drivers/md/dm-bufio.c
@@ -1599,7 +1599,7 @@ static bool __try_evict_buffer(struct dm
 static unsigned get_retain_buffers(struct dm_bufio_client *c)
 {
         unsigned retain_bytes = ACCESS_ONCE(dm_bufio_retain_bytes);
-        return retain_bytes / c->block_size;
+        return retain_bytes >> (c->sectors_per_block_bits + SECTOR_SHIFT);
 }
 
 static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan,




More information about the dm-devel mailing list