Skip to contentSkip to conversation

zram: reduce load operation in page_same_filled

PATCH New [email protected] 1 participant 1 message May 3, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 85/102 zram: reduce load operation in page_same_filled

From: Sangwoo Park <[email protected]>
Subject: zram: reduce load operation in page_same_filled

In page_same_filled function, all elements in the page is compared with next index value. The current comparison routine compares the (i)th and (i+1)th values of the page.

In this case, two load operaions occur for each comparison. But if we store first value of the page stores at 'val' variable and using it to compare with others, the load opearation is reduced. It reduce load operation per page by up to 64times.

---

 drivers/block/zram/zram_drv.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/block/zram/zram_drv.c renamed from drivers/block/zram/zram_drv.c~zram-reduce-load-operation-in-page_same_filled +5 -3
diff -puN drivers/block/zram/zram_drv.c~zram-reduce-load-operation-in-page_same_filled drivers/block/zram/zram_drv.c
@@ -195,15 +195,17 @@ static bool page_same_filled(void *ptr,
 {
 	unsigned int pos;
 	unsigned long *page;
+	unsigned long val;
 
 	page = (unsigned long *)ptr;
+	val = page[0];
 
-	for (pos = 0; pos < PAGE_SIZE / sizeof(*page) - 1; pos++) {
-		if (page[pos] != page[pos + 1])
+	for (pos = 1; pos < PAGE_SIZE / sizeof(*page); pos++) {
+		if (val != page[pos])
 			return false;
 	}
 
-	*element = page[pos];
+	*element = val;
 
 	return true;
 }

_