linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/zswap.c: avoid partial LRU inversion by evicting pages earlier
@ 2021-05-11 12:54 Ruben Bremer
  0 siblings, 0 replies; only message in thread
From: Ruben Bremer @ 2021-05-11 12:54 UTC (permalink / raw)
  To: Seth Jennings, Dan Streetman, Vitaly Wool, linux-mm; +Cc: rb

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-11 12:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 12:54 [PATCH] mm/zswap.c: avoid partial LRU inversion by evicting pages earlier Ruben Bremer

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).