[PATCH 3/6] mm/zswap: stop lru list shrinking when encounter warm region

Chengming Zhou posted 6 patches 1 year, 10 months ago
There is a newer version of this series
[PATCH 3/6] mm/zswap: stop lru list shrinking when encounter warm region
Posted by Chengming Zhou 1 year, 10 months ago
When the shrinker encounter an existing folio in swap cache, it means
we are shrinking into the warmer region. We should terminate shrinking
if we're in the dynamic shrinker context.

This patch add LRU_STOP to support this, to avoid overshrinking.

Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
---
 include/linux/list_lru.h | 1 +
 mm/list_lru.c            | 3 +++
 mm/zswap.c               | 4 +++-
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
index f2882a820690..5633e970144b 100644
--- a/include/linux/list_lru.h
+++ b/include/linux/list_lru.h
@@ -24,6 +24,7 @@ enum lru_status {
 	LRU_SKIP,		/* item cannot be locked, skip */
 	LRU_RETRY,		/* item not freeable. May drop the lock
 				   internally, but has to return locked. */
+	LRU_STOP,		/* stop lru list walking */
 };
 
 struct list_lru_one {
diff --git a/mm/list_lru.c b/mm/list_lru.c
index 61f3b6b1134f..3fd64736bc45 100644
--- a/mm/list_lru.c
+++ b/mm/list_lru.c
@@ -243,6 +243,9 @@ __list_lru_walk_one(struct list_lru *lru, int nid, int memcg_idx,
 			 */
 			assert_spin_locked(&nlru->lock);
 			goto restart;
+		case LRU_STOP:
+			assert_spin_locked(&nlru->lock);
+			goto out;
 		default:
 			BUG();
 		}
diff --git a/mm/zswap.c b/mm/zswap.c
index d8bb0e06e2b0..4381b7a2d4d6 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -1315,8 +1315,10 @@ static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_o
 		 * into the warmer region. We should terminate shrinking (if we're in the dynamic
 		 * shrinker context).
 		 */
-		if (writeback_result == -EEXIST && encountered_page_in_swapcache)
+		if (writeback_result == -EEXIST && encountered_page_in_swapcache) {
+			ret = LRU_STOP;
 			*encountered_page_in_swapcache = true;
+		}
 	} else {
 		zswap_written_back_pages++;
 	}

-- 
b4 0.10.1
Re: [PATCH 3/6] mm/zswap: stop lru list shrinking when encounter warm region
Posted by Yosry Ahmed 1 year, 10 months ago
On Thu, Feb 01, 2024 at 03:49:03PM +0000, Chengming Zhou wrote:
> When the shrinker encounter an existing folio in swap cache, it means
> we are shrinking into the warmer region. We should terminate shrinking
> if we're in the dynamic shrinker context.
> 
> This patch add LRU_STOP to support this, to avoid overshrinking.
> 
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>

LGTM with one comment below.

Reviewed-by: Yosry Ahmed <yosryahmed@google.com>

> ---
>  include/linux/list_lru.h | 1 +
>  mm/list_lru.c            | 3 +++
>  mm/zswap.c               | 4 +++-
>  3 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
> index f2882a820690..5633e970144b 100644
> --- a/include/linux/list_lru.h
> +++ b/include/linux/list_lru.h
> @@ -24,6 +24,7 @@ enum lru_status {
>  	LRU_SKIP,		/* item cannot be locked, skip */
>  	LRU_RETRY,		/* item not freeable. May drop the lock
>  				   internally, but has to return locked. */
> +	LRU_STOP,		/* stop lru list walking */

nit: Should we add "May drop the lock internally, but has to return
locked" like LRU_RETRY and LRU_REMOVED_RETRY?

>  };
>  
>  struct list_lru_one {
[..]
Re: [PATCH 3/6] mm/zswap: stop lru list shrinking when encounter warm region
Posted by Chengming Zhou 1 year, 10 months ago
On 2024/2/2 08:15, Yosry Ahmed wrote:
> On Thu, Feb 01, 2024 at 03:49:03PM +0000, Chengming Zhou wrote:
>> When the shrinker encounter an existing folio in swap cache, it means
>> we are shrinking into the warmer region. We should terminate shrinking
>> if we're in the dynamic shrinker context.
>>
>> This patch add LRU_STOP to support this, to avoid overshrinking.
>>
>> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
> 
> LGTM with one comment below.
> 
> Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
> 
>> ---
>>  include/linux/list_lru.h | 1 +
>>  mm/list_lru.c            | 3 +++
>>  mm/zswap.c               | 4 +++-
>>  3 files changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
>> index f2882a820690..5633e970144b 100644
>> --- a/include/linux/list_lru.h
>> +++ b/include/linux/list_lru.h
>> @@ -24,6 +24,7 @@ enum lru_status {
>>  	LRU_SKIP,		/* item cannot be locked, skip */
>>  	LRU_RETRY,		/* item not freeable. May drop the lock
>>  				   internally, but has to return locked. */
>> +	LRU_STOP,		/* stop lru list walking */
> 
> nit: Should we add "May drop the lock internally, but has to return
> locked" like LRU_RETRY and LRU_REMOVED_RETRY?

Right, will add.

Thanks.
Re: [PATCH 3/6] mm/zswap: stop lru list shrinking when encounter warm region
Posted by Nhat Pham 1 year, 10 months ago
On Thu, Feb 1, 2024 at 7:50 AM Chengming Zhou
<zhouchengming@bytedance.com> wrote:
>
> When the shrinker encounter an existing folio in swap cache, it means
> we are shrinking into the warmer region. We should terminate shrinking
> if we're in the dynamic shrinker context.
>
> This patch add LRU_STOP to support this, to avoid overshrinking.
>
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>

Nice!
Acked-by: Nhat Pham <nphamcs@gmail.com>
Re: [PATCH 3/6] mm/zswap: stop lru list shrinking when encounter warm region
Posted by Johannes Weiner 1 year, 10 months ago
On Thu, Feb 01, 2024 at 03:49:03PM +0000, Chengming Zhou wrote:
> When the shrinker encounter an existing folio in swap cache, it means
> we are shrinking into the warmer region. We should terminate shrinking
> if we're in the dynamic shrinker context.
> 
> This patch add LRU_STOP to support this, to avoid overshrinking.
> 
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>

LGTM.

Acked-by: Johannes Weiner <hannes@cmpxchg.org>