Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp139052lqs; Mon, 4 Mar 2024 18:47:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXxis4xz6DLL6gBiS7y4WDqtDZhdlQMUsTDo+fKwMKxwlZcBC+AXv3BMCoeWXe2YORkyvir98QTM1YkUlMvIYfWb7cPGS8UPVYe0OXSGg== X-Google-Smtp-Source: AGHT+IFaInImj+NbnA3cNat/4VC3gkADmjJ2M17/YlNpxQEz82wG8eobLaYo/vZtfX2Vd6QQTrSU X-Received: by 2002:a05:6358:5924:b0:179:f2:daa4 with SMTP id g36-20020a056358592400b0017900f2daa4mr539229rwf.24.1709606848800; Mon, 04 Mar 2024 18:47:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709606848; cv=pass; d=google.com; s=arc-20160816; b=SjC4IT6plLWW5hHFY9f5YcQKcHLb+/2u6jGW5933ifW5fkSHznF0J/Xyrdp2pPbhq/ msvZPCLnDm7tcpYEYNPGeJN2iJkm2YkLXr5USCMYyezQkEVgndqdtAb/EVZ5yhz5fm3J Z9Crmnd1TOb+gcwcvL+Ygfnpyjx0wABnY4PU6Uaaedpby3ZmZb966WSU6s5BrD5obcqZ AS841PXNis0ZndzZTKuRHxMk5Ap99Al8DabP6GoeXQvgCBFG+uCEVAQOGQvCebGAzTPV vlWVUCRdCpkTcM5QL3pu1sEbqnDRWn9DiLnShsXOOrAvkb2mYQCUF5Ck/qqclAvR2Fps TsEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=T4N4ai2fUYeTi17bmaqa5sNo2EZA38HXgMSv68D79fE=; fh=b7E6qJQEaT0YqznI/GU/tVTlq9CWMnQaRHnPm098a94=; b=LoLQERkhBFjiec0pEov8r8pd6maPIFTNJhn5ZF4jPko6myQOv2RELcStz+mTiuHvYd APWNTwxLrKIex3VAXiOmne6I8cmIRNZkqqtAzSt1WRWigmkxW5WEflPIgH9VyqKTWRbw LEGrOHL3tjQv+63LCgEGv9GizX3W+NX+O4Kp2lqN55a+lWdb8zlnYQL4cWOk8kkc/yId iGFJPhw74cjL85+twearjZHC5qpPM/L2AuomHdFEVgZE9c4XDuluBTBf0rAdevMu5ggW Au16rjc4wj7rQB/Ay0WuZkghAVPTBgGx9Vqo9mFHij/Q7BM45y8V5OeO5gbIvEvwnS1C 8D1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=axAeY9Sy; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-91567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91567-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l6-20020a656806000000b005dc85a7eb1dsi9262607pgt.299.2024.03.04.18.47.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 18:47:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=axAeY9Sy; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-91567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91567-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 3FCE1B219A5 for ; Tue, 5 Mar 2024 02:42:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2173E28DB5; Tue, 5 Mar 2024 02:42:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="axAeY9Sy" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0E4C11183 for ; Tue, 5 Mar 2024 02:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709606539; cv=none; b=ahj3Sb0nMri+/7VuJAuiAu0PqPK+G2eYJfo4xtWRxPafw/I/cbzVTWPNLgTRsZtA4GZgyn26nXJLTieemj5OVo8gmwSd4Diy1ebkWklW68gMehUAMUzzk5TAbW3zbWCr+bZS/H1rwhkoY+g3v3BR9jemEj4yHmFNtz2xzmSdt8E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709606539; c=relaxed/simple; bh=U0H7QWtBAWqPBlvTxscDhOVI9EoPYqvERlla0Um5xqs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=GD/rBEmiYia8s2CZ03vufutBA6Pam9DI1QQiSdlNiPe/VbebTXqSmU4f9p9JvxOtF1eQvqIyac/7hLtFo36dUw7N8y+1PEnKkSZF5FRvJNhIxQI9lQLCyRvrq5X9RHH0a5G7xjbvLlBqGy0nEf7qHGM95O7THQdN757PMPq7aTA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=axAeY9Sy; arc=none smtp.client-ip=198.175.65.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709606537; x=1741142537; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=U0H7QWtBAWqPBlvTxscDhOVI9EoPYqvERlla0Um5xqs=; b=axAeY9SyAg7jyUMeDJuPDwAd44lldIJoMm/CeXopA9xhXKGEiCHtgqPU tWllHUwsOhWpWEZQwmDkFkNMZsZ9YpV6RL2MzPmqtUUXW/pYeizUbzsht e4zWo3beEVG0ZpdlzE7pwphWb38KqwakkdFID8c/6yy62waRPQLnL56Rj TbGdv3lFY97z6ca872l4GrywwJIP5KMfmGEiT8m+s6zm6MhBb4zfrj830 w8hIPIZd3C+9+RDo8Uk6Smc9pF3c0Ly1mcf4u4qpdYmkwTxF9MDOZfMCf rFv3W+HMq5wVwmadfUInlQWUszhtcvnTm4qWW/+ITHUvPJSnGxCocNWbI w==; X-IronPort-AV: E=McAfee;i="6600,9927,11003"; a="4292108" X-IronPort-AV: E=Sophos;i="6.06,205,1705392000"; d="scan'208";a="4292108" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 18:42:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,205,1705392000"; d="scan'208";a="9387868" 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; 04 Mar 2024 18:42:13 -0800 From: "Huang, Ying" To: Byungchul Park Cc: , , , , , Subject: Re: [PATCH v6] mm, vmscan: retry kswapd's priority loop with cache_trim_mode off on failure In-Reply-To: <20240305023708.GA60719@system.software.com> (Byungchul Park's message of "Tue, 5 Mar 2024 11:37:08 +0900") References: <20240304033611.GD13332@system.software.com> <20240304082118.20499-1-byungchul@sk.com> <87zfvda1f8.fsf@yhuang6-desk2.ccr.corp.intel.com> <20240305023708.GA60719@system.software.com> Date: Tue, 05 Mar 2024 10:40:19 +0800 Message-ID: <87v8619zak.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ascii Byungchul Park writes: > On Tue, Mar 05, 2024 at 09:54:19AM +0800, Huang, Ying wrote: >> Byungchul Park writes: >> >> > Changes from v5: >> > 1. Make it retry the kswapd's scan priority loop with >> > cache_trim_mode off *only if* the mode didn't work in the >> > previous loop. (feedbacked by Huang Ying) >> > 2. Take into account 'break's from the priority loop when making >> > the decision whether to retry. (feedbacked by Huang Ying) >> > 3. Update the test result in the commit message. >> > >> > 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 f811ee583158fd53d0e94d32ce5948fac4b17cfe Mon Sep 17 00:00:00 2001 >> > From: Byungchul Park >> > Date: Mon, 4 Mar 2024 15:27:37 +0900 >> > Subject: [PATCH v6] 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 | 1664772 | >> > | nr_active_anon | 1780700 | 437834 | >> > | nr_inactive_file | 30425 | 40882 | >> > | nr_active_file | 14961 | 3012 | >> > | pgpromote_success | 356 | 1293122 | >> > | pgpromote_candidate | 21953245 | 1824148 | >> > | pgactivate | 1844523 | 3311907 | >> > | pgdeactivate | 50634 | 1554069 | >> > | pgfault | 31100294 | 6518806 | >> > | pgdemote_kswapd | 30856 | 2230821 | >> > | pgscan_kswapd | 1861981 | 7667629 | >> > | pgscan_anon | 1822930 | 7610583 | >> > | pgscan_file | 39051 | 57046 | >> > | pgsteal_anon | 386 | 2192033 | >> > | pgsteal_file | 30470 | 38788 | >> > | pageoutrun | 30 | 412 | >> > | numa_hint_faults | 27418279 | 2875955 | >> > | numa_pages_migrated | 356 | 1293122 | >> > +-----------------------+-------------------------------+ >> > >> > Signed-off-by: Byungchul Park >> > --- >> > mm/vmscan.c | 21 ++++++++++++++++++++- >> > 1 file changed, 20 insertions(+), 1 deletion(-) >> > >> > diff --git a/mm/vmscan.c b/mm/vmscan.c >> > index bba207f41b14..6fe45eca7766 100644 >> > --- a/mm/vmscan.c >> > +++ b/mm/vmscan.c >> > @@ -108,6 +108,12 @@ struct scan_control { >> > /* Can folios be swapped as part of reclaim? */ >> > unsigned int may_swap:1; >> > >> > + /* Not allow cache_trim_mode to be turned on as part of reclaim? */ >> > + unsigned int no_cache_trim_mode:1; >> > + >> > + /* Has cache_trim_mode failed at least once? */ >> > + unsigned int cache_trim_mode_failed:1; >> > + >> > /* Proactive reclaim invoked by userspace through memory.reclaim */ >> > unsigned int proactive:1; >> > >> > @@ -2268,7 +2274,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->no_cache_trim_mode) >> > sc->cache_trim_mode = 1; >> > else >> > sc->cache_trim_mode = 0; >> > @@ -5967,6 +5974,8 @@ static void shrink_node(pg_data_t *pgdat, struct scan_control *sc) >> > */ >> > if (reclaimable) >> > pgdat->kswapd_failures = 0; >> > + else if (sc->cache_trim_mode) >> > + sc->cache_trim_mode_failed = 1; >> > } >> > >> > /* >> > @@ -6898,6 +6907,16 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx) >> > sc.priority--; >> > } while (sc.priority >= 1); >> > >> > + /* >> > + * Restart only if it went through the priority loop all the way, >> > + * but cache_trim_mode didn't work. >> > + */ >> > + if (!sc.nr_reclaimed && sc.priority < 1 && >> > + !sc.no_cache_trim_mode && sc.cache_trim_mode_failed) { >> >> Can we just use sc.cache_trim_mode (instead of >> sc.cache_trim_mode_failed) here? That is, if cache_trim_mode is enabled > > As Johannes mentioned, within a priority scan, all the numa nodes are > scanned each with its own value of cache_trim_mode. So we cannot use > cache_trim_mode for that purpose. For direct reclaim, this is true. But, balance_pgdat() works for one node only. -- Best Regards, Huang, Ying > Byungchul > >> for priority == 1 and failed to reclaim, we will restart. If this >> works, we can avoid to add another flag. >> >> > + sc.no_cache_trim_mode = 1; >> > + goto restart; >> > + } >> > + >> > if (!sc.nr_reclaimed) >> > pgdat->kswapd_failures++; >> >> -- >> Best Regards, >> Huang, Ying