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 9BE22C48BF6 for ; Thu, 29 Feb 2024 06:23:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13D3C6B007B; Thu, 29 Feb 2024 01:23:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0C5976B0081; Thu, 29 Feb 2024 01:23:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E80B96B009B; Thu, 29 Feb 2024 01:23:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D28666B007B for ; Thu, 29 Feb 2024 01:23:16 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 9B402C021A for ; Thu, 29 Feb 2024 06:23:16 +0000 (UTC) X-FDA: 81843849192.15.3229096 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by imf13.hostedemail.com (Postfix) with ESMTP id 8608520005 for ; Thu, 29 Feb 2024 06:23:14 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="Fnto/yeo"; spf=pass (imf13.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.10 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709187794; 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=lRsZsHrFvakZ5etQXOozHVCK2vTCQKcRoDWp3r22HHw=; b=TpBFJOe0vAsbygwvpatfXgEWBO98rADu+gZUVmloEnM6jd7uuKO2Rf10aPQKtmNLRF5lq1 SpiLOZBKi5+OvVjCgdJ7h3RBCMjel3faK+A35YXXGop8I34ZfWEncfO2sJsVoWzKOVbQrd epqxP4hVYWRFG0Xv5z29aBgTrkIYCWI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709187794; a=rsa-sha256; cv=none; b=ypyApAk4c05sZ1eZt3TQo+D/OpguVIntZ29UVi6GTQGWtNqhXngZwoDReJy/wxFQov3u4p 2DPlbDShA7Tc8XNk9M/pFf85AzCv9i2n82tvekmqlo16APuQqRtiy2O0b0WGancrtRLpms +Kst/GQoZ8YK1e16B5pvpdkFi8KDV1k= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="Fnto/yeo"; spf=pass (imf13.hostedemail.com: domain of ying.huang@intel.com designates 198.175.65.10 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709187794; x=1740723794; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=vE8NafTn3vOUKgnZ/vVeV0fqWc145zT7+13M30pUdy8=; b=Fnto/yeoIJ5dJhkbvXP72NymXNqgQlldKJwQq8w0k+b4rMp2CsmdIb6m uAQJFl/XXuz65/ZEkG8mNGUuZtFCN1+M8kR3tRjpoaHlymPy7wxhevC5g Kbth4rtKhZf6EAEv5KjKfxC3Ih3KiZsdQo8/otaPvISAJbLrCtebtMIbn OkJ9TMUfkeQX28zknnJTq38NhGO29EspVHXPaAK7eKV4icfFQ19mJxgP2 tsL/JmRM2LCMiPxHS03wMM4e85CoO49ICnvf17o+qagdP7Hi0/O51Jzq0 croYfkIivtg47maQRiK50b1hbz9Srs7DWnkDb0nTFjZBCRdowMUaExYp0 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="21094537" X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="21094537" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 22:23:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,192,1705392000"; d="scan'208";a="7925166" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 22:23:10 -0800 From: "Huang, Ying" To: Johannes Weiner Cc: Michal Hocko , Byungchul Park , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel_team@skhynix.com, yuzhao@google.com, Mel Gorman , Vlastimil Babka Subject: Re: [PATCH v3] mm, vmscan: do not turn on cache_trim_mode if it doesn't work In-Reply-To: <20240228223601.GA53666@cmpxchg.org> (Johannes Weiner's message of "Wed, 28 Feb 2024 17:36:01 -0500") References: <20240223054407.14829-1-byungchul@sk.com> <20240228223601.GA53666@cmpxchg.org> Date: Thu, 29 Feb 2024 14:21:15 +0800 Message-ID: <87jzmndc4k.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-Rspamd-Queue-Id: 8608520005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: kyqym6p1zo6c78ad7miw8cb1xdujaagk X-HE-Tag: 1709187794-586775 X-HE-Meta: U2FsdGVkX1+vyis+o32Y+emJ5Kn7W7yfAz7LrYODzA5+VGultPmTW5/OvEZVzyLb7/9Dd4S706P55kvWLoal+JuL7uq21NQW4bsr0MG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ftXLpkpKHgzDa8CgORhO4pkDzm+u0DNY/qnHBkPCMgdOzVs4WdeHCdOabk68ELDP5KiQS0byELUn96GQNpt7CrTQHJov1I3Og4QJi881BnvHNLasX8ydUlsB16odTmXvLB72Q1Nf+0vF9bOaFWdv6XDnhlIY4rKV9/2XVsRn6QM8mF1BFvzfAXg/4nIhYHVgOjM5A5f42dM/d8P 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: Johannes Weiner writes: > On Mon, Feb 26, 2024 at 02:06:30PM +0100, Michal Hocko wrote: >> [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 >> > 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 >> > --- >> > 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; > > The overall goal makes sense to me. > > file >> priority is just a heuristic that there are enough potential > candidate pages, not a guarantee that any forward progress will > happen. So it makes sense to retry without before failing. > > The way you wrote this conditional kind of hurts my head, > though. Please don't write negations of complex terms like this. > > It expands to this: > > !sc->cache_trim_mode || sc->reclaimable || sc->priority > 1 > > which I'm not sure makes sense. Surely it should be something like > > !sc->cache_trim_mode && sc->reclaimable && sc->priority > 1 > > instead? > > Also > > if (!sc->cache_trim_mode) > sc->cache_trim_mode = 1 > else > sc->cache_trim_mode = 0 > > will toggle on every loop. So if direct reclaim runs through a > zonelist, it'll cache trim every other numa node...? > >> > @@ -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; > > The scope of this doesn't quite make sense. If direct reclaim scans > multiple nodes, reclaim failure on the first node would disable cache > trim mode on the second node, which is totally unrelated. > > I think it needs separate paths for direct reclaim and kswapd. For > direct reclaim, the retry should be before these similar retry catches > in do_try_to_free_pages(), after all zones have been considered: > > /* > * We make inactive:active ratio decisions based on the node's > * composition of memory, but a restrictive reclaim_idx or a > * memory.low cgroup setting can exempt large amounts of > * memory from reclaim. Neither of which are very common, so > * instead of doing costly eligibility calculations of the > * entire cgroup subtree up front, we assume the estimates are > * good, and retry with forcible deactivation if that fails. > */ > if (sc->skipped_deactivate) { > sc->priority = initial_priority; > sc->force_deactivate = 1; > sc->skipped_deactivate = 0; > goto retry; > } > > /* Untapped cgroup reserves? Don't OOM, retry. */ > if (sc->memcg_low_skipped) { > sc->priority = initial_priority; > sc->force_deactivate = 0; > sc->memcg_low_reclaim = 1; > sc->memcg_low_skipped = 0; > goto retry; > } In get_scan_count(), we have if (!sc->priority && swappiness) { scan_balance = SCAN_EQUAL; goto out; } So, we don't really need the heuristics in direct reclaim path. So, one choice is to constrain this in kswapd reclaim only. -- Best Regards, Huang, Ying > and for kswapd it looks like it should be in balance_pgdat(), after > the priority loop, before increasing kswapd_failures. > > Instead of sc->reclaimable, which is very broad, it would be better to > call it sc->may_cache_trim_mode. This is in line with a bunch of other > such mechanisms in scan_control.