linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Srividya Desireddy" <srividya.dr@samsung.com>
To: sjenning@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: "Dinakar Reddy Pathireddy" <dinakar.p@samsung.com>,
	샤란 <sharan.allur@samsung.com>,
	"SUNEEL KUMAR SURIMANI" <suneel@samsung.com>,
	김주훈 <juhunkim@samsung.com>
Subject: [PATCH 3/4] zswap: Zero-filled pages handling
Date: Wed, 17 Aug 2016 10:18:19 +0000	[thread overview]
Message-ID: <570065255.35200.1471429099337.JavaMail.weblogic@epwas3e2> (raw)
In-Reply-To: CGME20160817101819epcms5p25ad7d8a53c761ffff62993ca4d4bf129@epcms5p2

[-- Attachment #1: Type: text/plain, Size: 5024 bytes --]

From: Srividya Desireddy <srividya.dr@samsung.com>
Date: Wed, 17 Aug 2016 14:34:14 +0530
Subject: [PATCH 3/4] zswap: Zero-filled pages handling

This patch adds a check in zswap_frontswap_store() to identify zero-filled
page before compression of the page. If the page is a zero-filled page, set
zswap_entry.zeroflag and skip the compression of the page and alloction
of memory in zpool. In zswap_frontswap_load(), check if the zeroflag is
set for the page in zswap_entry. If the flag is set, memset the page with
zero. This saves the decompression time during load.

The overall overhead caused due to zero-filled page check is very minimal
when compared to the time saved by avoiding compression and allocation in
case of zero-filled pages. The load time of a zero-filled page is reduced
by 80% when compared to baseline.

Signed-off-by: Srividya Desireddy <srividya.dr@samsung.com>
---
 mm/zswap.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 50 insertions(+), 8 deletions(-)

diff --git a/mm/zswap.c b/mm/zswap.c
index ae39c77..d0c3f96 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -58,6 +58,9 @@ static atomic_t zswap_stored_pages = ATOMIC_INIT(0);
  */
 static atomic_t zswap_duplicate_pages = ATOMIC_INIT(0);
 
+/* The number of zero filled pages swapped out to zswap */
+static atomic_t zswap_zero_pages = ATOMIC_INIT(0);
+
 /*
  * The statistics below are not protected from concurrent access for
  * performance reasons so they may not be a 100% accurate.  However,
@@ -172,6 +175,8 @@ struct zswap_handle {
  *            be held, there is no reason to also make refcount atomic.
  * pool - the zswap_pool the entry's data is in
  * zhandle - pointer to struct zswap_handle
+ * zeroflag - the flag is set if the content of the page is filled with
+ *            zeros
  */
 struct zswap_entry {
 	struct rb_node rbnode;
@@ -179,6 +184,7 @@ struct zswap_entry {
 	int refcount;
 	struct zswap_pool *pool;
 	struct zswap_handle *zhandle;
+	unsigned char zeroflag;
 };
 
 struct zswap_header {
@@ -269,6 +275,7 @@ static struct zswap_entry *zswap_entry_cache_alloc(gfp_t gfp)
 	if (!entry)
 		return NULL;
 	entry->refcount = 1;
+	entry->zeroflag = 0;
 	entry->zhandle = NULL;
 	RB_CLEAR_NODE(&entry->rbnode);
 	return entry;
@@ -477,13 +484,17 @@ static bool zswap_handle_is_unique(struct zswap_handle *zhandle)
  */
 static void zswap_free_entry(struct zswap_entry *entry)
 {
-	if (zswap_handle_is_unique(entry->zhandle)) {
-		zpool_free(entry->pool->zpool, entry->zhandle->handle);
-		zswap_handle_cache_free(entry->zhandle);
-		zswap_pool_put(entry->pool);
-	} else {
-		entry->zhandle->ref_count--;
-		atomic_dec(&zswap_duplicate_pages);
+	if (entry->zeroflag)
+		atomic_dec(&zswap_zero_pages);
+	else {
+		if (zswap_handle_is_unique(entry->zhandle)) {
+			zpool_free(entry->pool->zpool, entry->zhandle->handle);
+			zswap_handle_cache_free(entry->zhandle);
+			zswap_pool_put(entry->pool);
+		} else {
+			entry->zhandle->ref_count--;
+			atomic_dec(&zswap_duplicate_pages);
+		}
 	}
 	zswap_entry_cache_free(entry);
 	atomic_dec(&zswap_stored_pages);
@@ -1140,6 +1151,21 @@ static int zswap_shrink(void)
 	return ret;
 }
 
+static int zswap_is_page_zero_filled(void *ptr)
+{
+	unsigned int pos;
+	unsigned long *page;
+
+	page = (unsigned long *)ptr;
+
+	for (pos = 0; pos != PAGE_SIZE / sizeof(*page); pos++) {
+		if (page[pos])
+			return 0;
+	}
+
+	return 1;
+}
+
 /*********************************
 * frontswap hooks
 **********************************/
@@ -1183,6 +1209,13 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
 	}
 
 	src = kmap_atomic(page);
+	if (zswap_is_page_zero_filled(src)) {
+		kunmap_atomic(src);
+		entry->offset = offset;
+		entry->zeroflag = 1;
+		atomic_inc(&zswap_zero_pages);
+		goto insert_entry;
+	}
 
 	if (zswap_same_page_sharing) {
 		checksum = jhash2((const u32 *)src, PAGE_SIZE / 4, 17);
@@ -1314,6 +1347,13 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset,
 	}
 	spin_unlock(&tree->lock);
 
+	if (entry->zeroflag) {
+		dst = kmap_atomic(page);
+		memset(dst, 0, PAGE_SIZE);
+		kunmap_atomic(dst);
+		goto freeentry;
+	}
+
 	/* decompress */
 	dlen = PAGE_SIZE;
 	src = (u8 *)zpool_map_handle(entry->pool->zpool, entry->zhandle->handle,
@@ -1327,6 +1367,7 @@ static int zswap_frontswap_load(unsigned type, pgoff_t offset,
 	zpool_unmap_handle(entry->pool->zpool, entry->zhandle->handle);
 	BUG_ON(ret);
 
+freeentry:
 	spin_lock(&tree->lock);
 	zswap_entry_put(tree, entry);
 	spin_unlock(&tree->lock);
@@ -1446,7 +1487,8 @@ static int __init zswap_debugfs_init(void)
 			zswap_debugfs_root, &zswap_stored_pages);
 	debugfs_create_atomic_t("duplicate_pages", S_IRUGO,
 			zswap_debugfs_root, &zswap_duplicate_pages);
-
+	debugfs_create_atomic_t("zero_pages", S_IRUGO,
+			zswap_debugfs_root, &zswap_zero_pages);
 
 	return 0;
 }
-- 
1.7.9.5


       reply	other threads:[~2016-08-17 10:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20160817101819epcms5p25ad7d8a53c761ffff62993ca4d4bf129@epcms5p2>
2016-08-17 10:18 ` Srividya Desireddy [this message]
2016-08-17 12:25   ` [PATCH 3/4] zswap: Zero-filled pages handling Pekka Enberg
2016-08-17 12:32     ` Pekka Enberg
2017-02-17 20:06   ` Dan Streetman
2016-08-19 13:30 ` Srividya Desireddy
     [not found] <CGME20160817101819epcms5p25ad7d8a53c761ffff62993ca4d4bf129@epcms5p1>
2016-08-19  5:51 ` Srividya Desireddy

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=570065255.35200.1471429099337.JavaMail.weblogic@epwas3e2 \
    --to=srividya.dr@samsung.com \
    --cc=dinakar.p@samsung.com \
    --cc=juhunkim@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sharan.allur@samsung.com \
    --cc=sjenning@redhat.com \
    --cc=suneel@samsung.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).