linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Ruben Bremer <rb@mail.ee>
To: Seth Jennings <sjenning@redhat.com>,
	Dan Streetman <ddstreet@ieee.org>,
	Vitaly Wool <vitaly.wool@konsulko.com>,
	linux-mm@kvack.org
Cc: rb@mail.ee
Subject: [PATCH] mm/zswap.c: avoid partial LRU inversion by evicting pages earlier
Date: Tue, 11 May 2021 14:54:47 +0200	[thread overview]
Message-ID: <43912f1a-c607-ff55-50c7-3285cfb5e7c0@mail.ee> (raw)

Zswap can evict stored pages on an LRU basis when its pool is full. 
However, new incoming pages will then simultaneously also be rejected 
and thus sent directly to swap, thereby effectively partially inversing 
LRU caching behavior.
In order to avoid this LRU inversion, this patch allows zswap to begin 
evicting pages earlier when its pool is only 90 % full but still accept 
new incoming pages. There may be more elegant solutions.

---

--- a/mm/zswap.c~mm-zswap-avoid-lru-inversion-by-earlier-eviction
+++ a/mm/zswap.c
@@ -228,6 +228,12 @@ static const struct zpool_ops zswap_zpoo
  	.evict = zswap_writeback_entry
  };

+static bool zswap_is_almost_full(void)
+{
+	return totalram_pages() * zswap_max_pool_percent / 111 <
+			DIV_ROUND_UP(zswap_pool_total_size, PAGE_SIZE);
+}
+
  static bool zswap_is_full(void)
  {
  	return totalram_pages() * zswap_max_pool_percent / 100 <
@@ -1109,20 +1115,24 @@ static int zswap_frontswap_store(unsigne
  	}

  	/* reclaim space if needed */
-	if (zswap_is_full()) {
+	if (zswap_is_almost_full()) {
  		struct zswap_pool *pool;

-		zswap_pool_limit_hit++;
-		zswap_pool_reached_full = true;
  		pool = zswap_pool_last_get();
-		if (pool)
+		if (pool) {
  			queue_work(shrink_wq, &pool->shrink_work);
-		ret = -ENOMEM;
-		goto reject;
+		}
+
+		if (zswap_is_full()) {
+			zswap_pool_limit_hit++;
+			zswap_pool_reached_full = true;
+			ret = -ENOMEM;
+			goto reject;
+		}
  	}

  	if (zswap_pool_reached_full) {
-	       if (!zswap_can_accept()) {
+		if (!zswap_can_accept()) {
  			ret = -ENOMEM;
  			goto reject;
  		} else


                 reply	other threads:[~2021-05-11 12:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=43912f1a-c607-ff55-50c7-3285cfb5e7c0@mail.ee \
    --to=rb@mail.ee \
    --cc=ddstreet@ieee.org \
    --cc=linux-mm@kvack.org \
    --cc=sjenning@redhat.com \
    --cc=vitaly.wool@konsulko.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).