[dm-devel] [PATCH] dm: optimize modulo max_io_len

Mikulas Patocka mpatocka at redhat.com
Mon Jun 18 13:19:52 UTC 2012


Hi

This patch should be applied after 
dm-support-non-power-of-two-target-max_io_len.patch. It optimizes a case 
when max_io_len is a power of two.

Mikulas

---

dm: optimize modulo max_io_len

Change slow modulo operation to fast bitwise and when max_io_len is a
power of two.

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

---
 drivers/md/dm.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Index: linux-3.4.2-fast/drivers/md/dm.c
===================================================================
--- linux-3.4.2-fast.orig/drivers/md/dm.c	2012-06-18 11:40:17.000000000 +0200
+++ linux-3.4.2-fast/drivers/md/dm.c	2012-06-18 11:41:05.000000000 +0200
@@ -1004,7 +1004,11 @@ static sector_t max_io_len(sector_t sect
 	 */
 	if (ti->max_io_len) {
 		offset = dm_target_offset(ti, sector);
-		max_len = ti->max_io_len - sector_div(offset, ti->max_io_len);
+		if (unlikely(ti->max_io_len & (ti->max_io_len - 1)))
+			max_len = sector_div(offset, ti->max_io_len);
+		else
+			max_len = offset & (ti->max_io_len - 1);
+		max_len = ti->max_io_len - max_len;
 
 		if (len > max_len)
 			len = max_len;




More information about the dm-devel mailing list