From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5627CC48BF6 for ; Mon, 4 Mar 2024 03:31:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBF326B00A1; Sun, 3 Mar 2024 22:31:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C6FA86B00A2; Sun, 3 Mar 2024 22:31:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B37276B00A3; Sun, 3 Mar 2024 22:31:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A49E36B00A1 for ; Sun, 3 Mar 2024 22:31:08 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 200B11C06AE for ; Mon, 4 Mar 2024 03:31:08 +0000 (UTC) X-FDA: 81857930616.25.A1FC051 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by imf17.hostedemail.com (Postfix) with ESMTP id 99D6E4001B for ; Mon, 4 Mar 2024 03:31:04 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="A/j20S10"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf17.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.16 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709523066; a=rsa-sha256; cv=none; b=sEdPIxvpmaV2Egdu7q3gskEC0tGPccf4vpByKJG/ph/NCDM+Xb+Ai23hjF2FhFpKwdUNYq 1uuotlPTHiQ2coDbOnUPrVCD54hww3MreXj0oLJ4sglb1UJQlBB5jS2EV53dR5lb4M33PV 3sZ+LGMPx3P5xlxEHVDjM6voMZ47KEo= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="A/j20S10"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf17.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.16 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709523066; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j5e04E5NheCDPAFfPzsq4c/dj8J2Ig6yoZ0ifxahqGE=; b=MzUiht4aGe+kc2Gg/jNCg6+qLhI4SWezqmyT3IBAFvaE0j1RMqbs/rDeBMa7ycfc+JO/cu jkz0FjwAjEUczX5HL1pshG+v1EmT0tRMbJX78zCU0kVGYo9XguWYUiqwhf5+CBAlha9cDG /adBrfUzYauGqqXT5SbjA5BqXycdfzI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709523065; x=1741059065; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=ZqFN2UEEI55o9pl/dH9NvM4/qaNRkfnnNBV+14OUoxg=; b=A/j20S10Z3A/pa7vd3UovQucGiCtmMN/etP4Bf5wPujlTl6hLu19942a WDs86XY5G2p6wCXFvXfA/Tpx/Oejn1BfOqF1qmE9Pe34+GVUlgfYtMNOR rqxVyfK3BvxTxa1eV7ADuII+qkqDlYRIFHjFVwdNwxogRfHL3Ijt5hh5p a4esPT6lp1rRZfX5aNo4RaTtg/U91tmUqAU24asLzfb8J6AUFmMV4UQZB 5LoUSsklAvHU3F2wJh7G/2xVQ9ulePToLepOCUGkXXPtL9QDayDqTJlgV l54mkk18ACUgjBtvbg/99BSKa0wrm2InQ38UqfKA9497Hr/K7nRPP+Ezq g==; X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="4118236" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="4118236" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2024 19:31:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="8793144" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2024 19:31:01 -0800 From: "Huang, Ying" To: Byungchul Park Cc: , , , , , Subject: Re: [PATCH v5] mm, vmscan: retry kswapd's priority loop with cache_trim_mode off on failure In-Reply-To: <20240304030413.GC13332@system.software.com> (Byungchul Park's message of "Mon, 4 Mar 2024 12:04:13 +0900") References: <20240304023018.69705-1-byungchul@sk.com> <87bk7ubtd4.fsf@yhuang6-desk2.ccr.corp.intel.com> <20240304030413.GC13332@system.software.com> Date: Mon, 04 Mar 2024 11:29:06 +0800 Message-ID: <877ciibrp9.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 99D6E4001B X-Stat-Signature: 16m3o1zcxqywjhn5dr4myxxgitg7c7fz X-HE-Tag: 1709523064-222561 X-HE-Meta: U2FsdGVkX18e0vmU+mdMlGiTQhZDXE5g5IiNwAz1EIS7PuxQ9hR4b49Vis80M04MUZLg1Z2YnvEnPcz/R6ARexZFbIEiS+DQL9d9iNj2An8+wXpT8nRKewK9I7xom0IAQuEnWFbY3b1P5wFDprZAE8XsbhuPvwXm3RhBnyidLopCJvIOjd/EV5qGAdoN5Vet6B+gwPrOmN73GQAOKY7HCbQJXs+vXnKAnetV0968pLoKnoCS2DWM6nUE9s7eqOt4RwE7vDpkuww8cUj/IjmDEB4xzhwhKVCue7i4DnVJfLapALqypqw1x4iljVoGZn5k1Jqn1n+jjkOWLYeXMFhmmlmruf5SiJ6roMI61+Ib8CvjBLefSozcNRc4LdFEGMJYBBzO3b7DlLUohwp56oyzbICyxHn3InaWdtjULnDsrzsoR3gBlpwkpYiBibrvmMWYer/YGasb8s7OKanxpWkqEOwGBFlkEtazoZdJ++5jHgNLKKX4Hu0DrRniLn2IssaPgo65rHFAk6ijd7o8IlTQXNQuZaqWaa0rLRu7yd3pZlUtkRXxrwxBTWagFAYuZXwAVUK98erSacg60Yon5aLAKzOGDN2MKJmFBaJld5zFszsI8HRP1YmvjSTeQRhWHpNV6bfggH3ZWxaqpdv6Nqj2oRWo6RvrOIHnsm9eNbE7qffXMMVf9XqPmNcy4jilvpejLTaWr5wvD4+iex49ZHjH92xOXhrfldIvyIHlLvYoUpZErZHb1ukIGTk2O5IAiRoCV3velna70fYcIigB84H3hsD/VbkuvbXwxRqbJAHDUynq6ZbSRaXPtgFA9HVFGQvLpC1iDmdejb7cslom6cYES2I2RgGcwKEUnekcZhlHGZyQ9Kh0fop8F1B5UCUh0yCqfcEVUkuWwrM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Byungchul Park writes: > On Mon, Mar 04, 2024 at 10:53:11AM +0800, Huang, Ying wrote: >> Byungchul Park writes: >> >> > Sorry for noise. I should've applied v5's change in v4. >> > >> > Changes from v4: >> > 1. Make other scans start with may_cache_trim_mode = 1. >> > >> > Changes from v3: >> > 1. Update the test result in the commit message with v4. >> > 2. Retry the whole priority loop with cache_trim_mode off again, >> > rather than forcing the mode off at the highest priority, >> > when the mode doesn't work. (feedbacked by Johannes Weiner) >> > >> > 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 58f1a0e41b9feea72d7fd4bd7bed1ace592e6e4c Mon Sep 17 00:00:00 2001 >> > From: Byungchul Park >> > Date: Mon, 4 Mar 2024 11:24:40 +0900 >> > Subject: [PATCH v5] mm, vmscan: retry kswapd's priority loop with cache_trim_mode off on failure >> > >> > With cache_trim_mode on, reclaim logic doesn't bother reclaiming anon >> > pages. However, it should be more careful to use 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 kswapd needs to retry its scan priority loop with cache_trim_mode >> > off again if the mode doesn't work for 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 | 1646193 | >> > | nr_active_anon | 1780700 | 456388 | >> > | nr_inactive_file | 30425 | 27836 | >> > | nr_active_file | 14961 | 1217 | >> > | pgpromote_success | 356 | 1310120 | >> > | pgpromote_candidate | 21953245 | 1736872 | >> > | pgactivate | 1844523 | 3292443 | >> > | pgdeactivate | 50634 | 1526701 | >> > | pgfault | 31100294 | 6715375 | >> > | pgdemote_kswapd | 30856 | 1954199 | >> > | pgscan_kswapd | 1861981 | 7100099 | >> > | pgscan_anon | 1822930 | 7061135 | >> > | pgscan_file | 39051 | 38964 | >> > | pgsteal_anon | 386 | 1925214 | >> > | pgsteal_file | 30470 | 28985 | >> > | pageoutrun | 30 | 500 | >> > | numa_hint_faults | 27418279 | 3090773 | >> > | numa_pages_migrated | 356 | 1310120 | >> > +-----------------------+-------------------------------+ >> > >> > Signed-off-by: Byungchul Park >> > --- >> > mm/vmscan.c | 23 +++++++++++++++++++++-- >> > 1 file changed, 21 insertions(+), 2 deletions(-) >> > >> > diff --git a/mm/vmscan.c b/mm/vmscan.c >> > index bba207f41b14..77948b0f8b5b 100644 >> > --- a/mm/vmscan.c >> > +++ b/mm/vmscan.c >> > @@ -108,6 +108,9 @@ struct scan_control { >> > /* Can folios be swapped as part of reclaim? */ >> > unsigned int may_swap:1; >> > >> > + /* Can cache_trim_mode be turned on as part of reclaim? */ >> > + unsigned int may_cache_trim_mode:1; >> > + >> >> Although it's generally not good to use negative logic, I think that >> it's better to name the flag as something like "no_cache_trim_mode" to >> make it easier to initialize the flag to its default value ("0"). > > No preference to me. But don't think it's better to use another of may_* > in scan_control as Johannes Weiner suggested? > >> > /* Proactive reclaim invoked by userspace through memory.reclaim */ >> > unsigned int proactive:1; >> > >> > @@ -1500,6 +1503,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone, >> > struct scan_control sc = { >> > .gfp_mask = GFP_KERNEL, >> > .may_unmap = 1, >> > + .may_cache_trim_mode = 1, >> > }; >> > struct reclaim_stat stat; >> > unsigned int nr_reclaimed; >> > @@ -2094,6 +2098,7 @@ static unsigned int reclaim_folio_list(struct list_head *folio_list, >> > .may_writepage = 1, >> > .may_unmap = 1, >> > .may_swap = 1, >> > + .may_cache_trim_mode = 1, >> > .no_demotion = 1, >> > }; >> > >> > @@ -2268,7 +2273,8 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc) >> > * anonymous pages. >> > */ >> > 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->may_cache_trim_mode) >> > sc->cache_trim_mode = 1; >> > else >> > sc->cache_trim_mode = 0; >> > @@ -5435,6 +5441,7 @@ static ssize_t lru_gen_seq_write(struct file *file, const char __user *src, >> > .may_writepage = true, >> > .may_unmap = true, >> > .may_swap = true, >> > + .may_cache_trim_mode = 1, >> > .reclaim_idx = MAX_NR_ZONES - 1, >> > .gfp_mask = GFP_KERNEL, >> > }; >> > @@ -6394,6 +6401,7 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order, >> > .may_writepage = !laptop_mode, >> > .may_unmap = 1, >> > .may_swap = 1, >> > + .may_cache_trim_mode = 1, >> > }; >> > >> > /* >> > @@ -6439,6 +6447,7 @@ unsigned long mem_cgroup_shrink_node(struct mem_cgroup *memcg, >> > .may_unmap = 1, >> > .reclaim_idx = MAX_NR_ZONES - 1, >> > .may_swap = !noswap, >> > + .may_cache_trim_mode = 1, >> > }; >> > >> > WARN_ON_ONCE(!current->reclaim_state); >> > @@ -6482,6 +6491,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, >> > .may_writepage = !laptop_mode, >> > .may_unmap = 1, >> > .may_swap = !!(reclaim_options & MEMCG_RECLAIM_MAY_SWAP), >> > + .may_cache_trim_mode = 1, >> > .proactive = !!(reclaim_options & MEMCG_RECLAIM_PROACTIVE), >> > }; >> > /* >> > @@ -6744,6 +6754,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx) >> > .gfp_mask = GFP_KERNEL, >> > .order = order, >> > .may_unmap = 1, >> > + .may_cache_trim_mode = 1, >> > }; >> > >> > set_task_reclaim_state(current, &sc.reclaim_state); >> > @@ -6898,8 +6909,14 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx) >> > sc.priority--; >> > } while (sc.priority >= 1); >> > >> > - if (!sc.nr_reclaimed) >> > + if (!sc.nr_reclaimed) { >> > + if (sc.may_cache_trim_mode) { >> >> sc.may_cache_trim_mode && cache_trim_mode ? > > I don't think so. cache_trim_mode has a chance to switch every > prepare_scan_control() like: > > if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE) && > sc->may_cache_trim_mode) > sc->cache_trim_mode = 1; > else > sc->cache_trim_mode = 0; > > So referring to the last value is not a good idea. We should only restart without cache_trim_mode if cache_trim_mode causes issue. If it isn't enabled with highest priority (lowest value), it doesn't help to disable cache_trim_mode. And, please take care of other "break" in the loop, for example, if kthread_should_stop(), etc. -- Best Regards, Huang, Ying > Byungchul > >> > + sc.may_cache_trim_mode = 0; >> > + goto restart; >> > + } >> > + >> > pgdat->kswapd_failures++; >> > + } >> > >> > out: >> > clear_reclaim_active(pgdat, highest_zoneidx); >> > @@ -7202,6 +7219,7 @@ unsigned long shrink_all_memory(unsigned long nr_to_reclaim) >> > .may_writepage = 1, >> > .may_unmap = 1, >> > .may_swap = 1, >> > + .may_cache_trim_mode = 1, >> > .hibernation_mode = 1, >> > }; >> > struct zonelist *zonelist = node_zonelist(numa_node_id(), sc.gfp_mask); >> > @@ -7360,6 +7378,7 @@ static int __node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned in >> > .may_writepage = !!(node_reclaim_mode & RECLAIM_WRITE), >> > .may_unmap = !!(node_reclaim_mode & RECLAIM_UNMAP), >> > .may_swap = 1, >> > + .may_cache_trim_mode = 1, >> > .reclaim_idx = gfp_zone(gfp_mask), >> > }; >> > unsigned long pflags; >> >> -- >> Best Regards, >> Huang, Ying