linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Streetman <ddstreet@ieee.org>
To: Seth Jennings <sjennings@variantweb.net>
Cc: Dan Streetman <ddstreet@ieee.org>,
	linux-mm@kvack.org, linux-kernel <linux-kernel@vger.kernel.org>,
	Bob Liu <bob.liu@oracle.com>, Minchan Kim <minchan@kernel.org>,
	Weijie Yang <weijie.yang@samsung.com>
Subject: [PATCH] mm/zswap: don't allow entry eviction if in use by load
Date: Wed, 20 Nov 2013 14:48:29 -0500	[thread overview]
Message-ID: <1384976909-32671-1-git-send-email-ddstreet@ieee.org> (raw)

The changes in commit 0ab0abcf511545d1fddbe72a36b3ca73388ac937
introduce a bug in writeback, if an entry is in use by load
it will be evicted anyway, which isn't correct (technically,
the code currently in zbud doesn't actually care much what the
zswap evict function returns, but that could change).

This changes the check in the writeback function to prevent eviction
if the entry is still in use (with a nonzero refcount).  The
refcount is used instead of searching the rb tree beacuse we're
holding the tree lock (which is required for any changes to refcount)
and it's faster than a tree search.

Signed-off-by: Dan Streetman <ddstreet@ieee.org>
---
 mm/zswap.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/zswap.c b/mm/zswap.c
index e55bab9..e154f1e 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -600,14 +600,18 @@ static int zswap_writeback_entry(struct zbud_pool *pool, unsigned long handle)
 	zswap_entry_put(tree, entry);
 
 	/*
-	* There are two possible situations for entry here:
+	* There are three possible situations for entry here:
 	* (1) refcount is 1(normal case),  entry is valid and on the tree
 	* (2) refcount is 0, entry is freed and not on the tree
 	*     because invalidate happened during writeback
-	*  search the tree and free the entry if find entry
+	* (3) refcount is 2, entry is in use by load, prevent eviction
 	*/
-	if (entry == zswap_rb_search(&tree->rbroot, offset))
+	if (likely(entry->refcount > 0))
 		zswap_entry_put(tree, entry);
+	if (unlikely(entry->refcount > 0)) {
+		spin_unlock(&tree->lock);
+		return -EAGAIN;
+	}
 	spin_unlock(&tree->lock);
 
 	goto end;
-- 
1.8.3.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

             reply	other threads:[~2013-11-20 19:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20 19:48 Dan Streetman [this message]
2013-11-21  1:59 ` Weijie Yang
2013-11-21 21:44   ` Dan Streetman
2013-11-21 22:18     ` Dan Streetman

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=1384976909-32671-1-git-send-email-ddstreet@ieee.org \
    --to=ddstreet@ieee.org \
    --cc=bob.liu@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=sjennings@variantweb.net \
    --cc=weijie.yang@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