[PATCH] mm/zswap.c: avoid partial LRU inversion by evicting pages earlier

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux