All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sangwoo <sangwoo2.park@lge.com>
To: <minchan@kernel.org>, <ngupta@vflare.org>
Cc: <sergey.senozhatsky.work@gmail.com>,
	<linux-kernel@vger.kernel.org>, Sangwoo <sangwoo2.park@lge.com>
Subject: [PATCH] zram: reduce load operation in page_same_filled
Date: Thu, 2 Mar 2017 13:15:04 +0900	[thread overview]
Message-ID: <1488428104-7257-1-git-send-email-sangwoo2.park@lge.com> (raw)

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.

Signed-off-by: Sangwoo <sangwoo2.park@lge.com>
---
 drivers/block/zram/zram_drv.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index e27d89a..87581d1 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -177,15 +177,17 @@ static bool page_same_filled(void *ptr, unsigned long *element)
 {
 	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;
 }
-- 
2.6.2

             reply	other threads:[~2017-03-02  4:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-02  4:15 Sangwoo [this message]
2017-03-02  7:02 ` [PATCH] zram: reduce load operation in page_same_filled Minchan Kim
2017-03-02  7:11   ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1488428104-7257-1-git-send-email-sangwoo2.park@lge.com \
    --to=sangwoo2.park@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.org \
    --cc=ngupta@vflare.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.