linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Byungchul Park <byungchul@sk.com>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, kernel_team@skhynix.com, yuzhao@google.com,
	ying.huang@intel.com, Mel Gorman <mgorman@suse.de>,
	Vlastimil Babka <vbabka@suse.cz>,
	Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: [PATCH v3] mm, vmscan: do not turn on cache_trim_mode if it doesn't work
Date: Mon, 26 Feb 2024 14:06:30 +0100	[thread overview]
Message-ID: <ZdyM1nS8a8UR1dw_@tiehlicka> (raw)
In-Reply-To: <20240223054407.14829-1-byungchul@sk.com>

[CC Mel, Vlastimil and Johannes for awareness]

On Fri 23-02-24 14:44:07, Byungchul Park wrote:
> Changes from v2:
> 	1. Change the condition to stop cache_trim_mode.
> 
> 	   From - Stop it if it's at high scan priorities, 0 or 1.
> 	   To   - Stop it if it's at high scan priorities, 0 or 1, and
> 	          the mode didn't work in the previous turn.
> 
> 	   (feedbacked by Huang Ying)
> 
> 	2. Change the test result in the commit message after testing
> 	   with the new logic.
> 
> Changes from v1:
> 	1. Add a comment describing why this change is necessary in code
> 	   and rewrite the commit message with how to reproduce and what
> 	   the result is using vmstat. (feedbacked by Andrew Morton and
> 	   Yu Zhao)
> 	2. Change the condition to avoid cache_trim_mode from
> 	   'sc->priority != 1' to 'sc->priority > 1' to reflect cases
> 	   where the priority goes to zero all the way. (feedbacked by
> 	   Yu Zhao)
> 
> --->8---
> >From 05846e34bf02ac9b3e254324dc2d7afd97a025d9 Mon Sep 17 00:00:00 2001
> From: Byungchul Park <byungchul@sk.com>
> Date: Fri, 23 Feb 2024 13:47:16 +0900
> Subject: [PATCH v3] mm, vmscan: do not turn on cache_trim_mode if it doesn't work
> 
> With cache_trim_mode on, reclaim logic doesn't bother reclaiming anon
> pages.  However, it should be more careful to turn on the mode because
> it's going to prevent anon pages from being reclaimed even if there are
> a huge number of anon pages that are cold and should be reclaimed.  Even
> worse, that leads kswapd_failures to reach MAX_RECLAIM_RETRIES and
> stopping kswapd from functioning until direct reclaim eventually works
> to resume kswapd.
> 
> So do not turn on cache_trim_mode if the mode doesn't work, especially
> while the sytem is struggling against reclaim.
> 
> The problematic behavior can be reproduced by:
> 
>    CONFIG_NUMA_BALANCING enabled
>    sysctl_numa_balancing_mode set to NUMA_BALANCING_MEMORY_TIERING
>    numa node0 (8GB local memory, 16 CPUs)
>    numa node1 (8GB slow tier memory, no CPUs)
> 
>    Sequence:
> 
>    1) echo 3 > /proc/sys/vm/drop_caches
>    2) To emulate the system with full of cold memory in local DRAM, run
>       the following dummy program and never touch the region:
> 
>          mmap(0, 8 * 1024 * 1024 * 1024, PROT_READ | PROT_WRITE,
> 	      MAP_ANONYMOUS | MAP_PRIVATE | MAP_POPULATE, -1, 0);
> 
>    3) Run any memory intensive work e.g. XSBench.
>    4) Check if numa balancing is working e.i. promotion/demotion.
>    5) Iterate 1) ~ 4) until numa balancing stops.
> 
> With this, you could see that promotion/demotion are not working because
> kswapd has stopped due to ->kswapd_failures >= MAX_RECLAIM_RETRIES.
> 
> Interesting vmstat delta's differences between before and after are like:
> 
>    +-----------------------+-------------------------------+
>    | interesting vmstat	   | before	   | after	   |
>    +-----------------------+-------------------------------+
>    | nr_inactive_anon	   | 321935	   | 1636737	   |
>    | nr_active_anon	   | 1780700	   | 465913	   |
>    | nr_inactive_file	   | 30425	   | 35711	   |
>    | nr_active_file	   | 14961	   | 8698	   |
>    | pgpromote_success	   | 356	   | 1267785	   |
>    | pgpromote_candidate   | 21953245	   | 1745631	   |
>    | pgactivate		   | 1844523	   | 3309867	   |
>    | pgdeactivate	   | 50634	   | 1545041	   |
>    | pgfault		   | 31100294	   | 6411036	   |
>    | pgdemote_kswapd	   | 30856	   | 2267467	   |
>    | pgscan_kswapd	   | 1861981	   | 7729231	   |
>    | pgscan_anon	   | 1822930	   | 7667544	   |
>    | pgscan_file	   | 39051	   | 61687	   |
>    | pgsteal_anon	   | 386	   | 2227217	   |
>    | pgsteal_file	   | 30470	   | 40250	   |
>    | pageoutrun		   | 30		   | 457	   |
>    | numa_hint_faults	   | 27418279	   | 2752289	   |
>    | numa_pages_migrated   | 356	   | 1267785 	   |
>    +-----------------------+-------------------------------+
> 
> Signed-off-by: Byungchul Park <byungchul@sk.com>
> ---
>  mm/vmscan.c | 24 +++++++++++++++++++-----
>  1 file changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index bba207f41b14..f7312d831fed 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -127,6 +127,9 @@ struct scan_control {
>  	/* One of the zones is ready for compaction */
>  	unsigned int compaction_ready:1;
>  
> +	/* If the last try was reclaimable */
> +	unsigned int reclaimable:1;
> +
>  	/* There is easily reclaimable cold cache in the current node */
>  	unsigned int cache_trim_mode:1;
>  
> @@ -2266,9 +2269,14 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc)
>  	 * If we have plenty of inactive file pages that aren't
>  	 * thrashing, try to reclaim those first before touching
>  	 * anonymous pages.
> +	 *
> +	 * It doesn't make sense to keep cache_trim_mode on if the mode
> +	 * is not working while struggling against reclaim. So do not
> +	 * turn it on if so. Note the highest priority of kswapd is 1.
>  	 */
>  	file = lruvec_page_state(target_lruvec, NR_INACTIVE_FILE);
> -	if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE))
> +	if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE) &&
> +	    !(sc->cache_trim_mode && !sc->reclaimable && sc->priority <= 1))
>  		sc->cache_trim_mode = 1;
>  	else
>  		sc->cache_trim_mode = 0;
> @@ -5862,7 +5870,6 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
>  {
>  	unsigned long nr_reclaimed, nr_scanned, nr_node_reclaimed;
>  	struct lruvec *target_lruvec;
> -	bool reclaimable = false;
>  
>  	if (lru_gen_enabled() && root_reclaim(sc)) {
>  		lru_gen_shrink_node(pgdat, sc);
> @@ -5877,6 +5884,14 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
>  	nr_reclaimed = sc->nr_reclaimed;
>  	nr_scanned = sc->nr_scanned;
>  
> +	/*
> +	 * Reset to the default values at the start.
> +	 */
> +	if (sc->priority == DEF_PRIORITY) {
> +		sc->reclaimable = 1;
> +		sc->cache_trim_mode = 0;
> +	}
> +
>  	prepare_scan_control(pgdat, sc);
>  
>  	shrink_node_memcgs(pgdat, sc);
> @@ -5890,8 +5905,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
>  		vmpressure(sc->gfp_mask, sc->target_mem_cgroup, true,
>  			   sc->nr_scanned - nr_scanned, nr_node_reclaimed);
>  
> -	if (nr_node_reclaimed)
> -		reclaimable = true;
> +	sc->reclaimable = !!nr_node_reclaimed;
>  
>  	if (current_is_kswapd()) {
>  		/*
> @@ -5965,7 +5979,7 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
>  	 * sleep. On reclaim progress, reset the failure counter. A
>  	 * successful direct reclaim run will revive a dormant kswapd.
>  	 */
> -	if (reclaimable)
> +	if (sc->reclaimable)
>  		pgdat->kswapd_failures = 0;
>  }
>  
> -- 
> 2.17.1
> 

-- 
Michal Hocko
SUSE Labs


  parent reply	other threads:[~2024-02-26 13:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-23  5:44 Byungchul Park
2024-02-23  9:25 ` Huang, Ying
2024-02-23  9:34   ` Byungchul Park
2024-02-26 13:06 ` Michal Hocko [this message]
2024-02-28 22:36   ` Johannes Weiner
2024-02-29  6:10     ` Byungchul Park
2024-02-29  6:19       ` Huang, Ying
2024-02-29  6:32         ` Byungchul Park
2024-02-29  6:21     ` Huang, Ying
2024-02-29  8:39       ` Byungchul Park
2024-02-29  8:41         ` Huang, Ying
2024-02-29  8:50           ` Byungchul Park

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=ZdyM1nS8a8UR1dw_@tiehlicka \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=byungchul@sk.com \
    --cc=hannes@cmpxchg.org \
    --cc=kernel_team@skhynix.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=vbabka@suse.cz \
    --cc=ying.huang@intel.com \
    --cc=yuzhao@google.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