@@ -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