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 BCA4CC48BF8 for ; Thu, 22 Feb 2024 09:49:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DCAD6B006E; Thu, 22 Feb 2024 04:49:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 28C8B6B0071; Thu, 22 Feb 2024 04:49:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1550C6B0072; Thu, 22 Feb 2024 04:49:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 076606B006E for ; Thu, 22 Feb 2024 04:49:12 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CE1E61C0D91 for ; Thu, 22 Feb 2024 09:49:11 +0000 (UTC) X-FDA: 81818966502.11.D64A376 Received: from invmail4.hynix.com (exvmail4.skhynix.com [166.125.252.92]) by imf12.hostedemail.com (Postfix) with ESMTP id B814F4000E for ; Thu, 22 Feb 2024 09:49:07 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf12.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708595350; 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; bh=lsRAIn9V6wKssbaf0Cw1zLR7vGVMeGfrlGrRI76zxnA=; b=dP6zHGOmAzEEQG/rDHDXkc0Gr/d98BHfO8sg84NleQVFfJyg9JFQ0nPXHIDwoC+7URu4+C Pv+G+zexPEPGN078jX1uJq7jxId7vtkWh5XtmQFQ7M8JL8fG7S5gTz5Blpykh8kbS9kEdA O/5w7i0w6Mlm4YVcc2kQhmRsz34kCK0= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf12.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708595350; a=rsa-sha256; cv=none; b=n9JzXMI/J2OPuAJ4pzuy/wCctbMKno+zuCntFpdYjhossGyTkLvex9fjgFl4AvW1QGkudu JqFd2VDLBvgEgMe7tqpEzSVG3v+d1CWskuEP/ll7NR6J09xQTg6tmlPInP8T2DSqicZzEl lYOpI4tf6ANs5kFRujmrfa9O/cBK0DU= X-AuditID: a67dfc5b-d85ff70000001748-5e-65d71891f90d Date: Thu, 22 Feb 2024 18:49:00 +0900 From: Byungchul Park To: "Huang, Ying" Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel_team@skhynix.com, yuzhao@google.com Subject: Re: [PATCH v2] mm, vmscan: don't turn on cache_trim_mode at high scan priorities Message-ID: <20240222094900.GA13076@system.software.com> References: <20240222070817.70515-1-byungchul@sk.com> <87sf1kj3nn.fsf@yhuang6-desk2.ccr.corp.intel.com> <20240222092042.GA33967@system.software.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240222092042.GA33967@system.software.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNLMWRmVeSWpSXmKPExsXC9ZZnke5EieupBlM+K1rMWb+GzeLyrjls FvfW/Ge1ODlrMovFuwlfWB1YPRZsKvVYvOclk8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Eguq/0zcQfjl8vuhxgF OBiVeHgfMF5LFWJNLCuuzD3EKMHBrCTCy1J+JVWINyWxsiq1KD++qDQntfgQozQHi5I4r1d4 aoKQQHpiSWp2ampBahFMlomDU6qB8Wzh8QldK/fw/j9waM2GB8c3t3Ty2757JVaX/qfweH2d dNRD57a1LxJ3nj/9rMlmWZwg37cM161OBgqTXD+/urp634ozjr/+f2wT5D9W9yvQfkqWqPjF j1mnEwSPfeM8WZifsjFHackx8e93V1/+cts9lLleaMmroo6dHMWLNhkfaHx/VvmNnIASS3FG oqEWc1FxIgBZ0m3IRQIAAA== X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: B814F4000E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: jd7fuzo9ancmcpco6gak7nyai3eq6uai X-HE-Tag: 1708595347-992568 X-HE-Meta: U2FsdGVkX18Wmbt1hpLAN/pF8/+lzE2mh/SKoAWqiDJ+R51Va+dsvh+eJSUQ7MVTD0It+I0Ax9OIlxlAN7h+BqFdLEUcik+bCjx8eiDg3BiHQP1XFwdsRQeuf1tI57E8ksf1BTY3forDc5kpL7PPuvNlQUfwcsgZUxLu5GjqwmDWC3qfD4uY05b5NxZzUo5q/MY1F1vrSf86rueMhOr1Rx7Dgke8BCIAEfeEsyJDbDgl1+RUY0ngKrgZRY8M4um3BDoTYNqyCxDqY6VnwhuhwVchHjZucmn83Q06+qKFl7KS5MXvjQ9oC/IsiUAR8DikrwmF1F9hvZKJYDTVS3gpRqTbfRzuFrrf75Y0KOvUkQbeLFR8R/amTFqc893fa3JIU0WHuNJnr5Z+4S3SK9L0DafDEqrJD98BDHD3UT4sMSizF28icpT7T2fW2YdohiWimAAfHkYZir540JkiRajm9pPNHCK3++4pUEAqiTdmHler0AjHnIKpA5yguenbreQjs2vJp8FMPs4iDvIBvNi/sgnOKezC44y4E9Gr6TeAhIRa7dLiKW3C2luEFpdjp0CGM820Pn7ePlCqawoqknRVCRG6Yuz5qxkZ3pqduE1vAMq1FdPF37l/WqOMEo9fnbMQz8lWZOrErPxmoy4RYQBUyIoKaPu3jy8kflk374NEzz7GipR7mfpz00W2l19a+HDGvc34iM5zz1WpmXcPiYrbsQ== 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: On Thu, Feb 22, 2024 at 06:20:42PM +0900, Byungchul Park wrote: > On Thu, Feb 22, 2024 at 04:37:16PM +0800, Huang, Ying wrote: > > Byungchul Park writes: > > > > > 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 07e0baab368160e50b6ca35d95745168aa60e217 Mon Sep 17 00:00:00 2001 > > > From: Byungchul Park > > > Date: Thu, 22 Feb 2024 14:50:17 +0900 > > > Subject: [PATCH v2] mm, vmscan: don't turn on cache_trim_mode at high scan priorities > > > > > > 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 can lead kswapd_failures to reach MAX_RECLAIM_RETRIES and > > > stopping kswapd until direct reclaim eventually works to resume kswapd. > > > So this is more like a bug fix than a performance improvement. > > > > > > 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 kswapd stops. > > > > > > With this, you could eventually 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: > > > > > > -nr_inactive_anon 321935 > > > -nr_active_anon 1780700 > > > -nr_inactive_file 30425 > > > -nr_active_file 14961 > > > -pgpromote_success 356 > > > -pgpromote_candidate 21953245 > > > -pgactivate 1844523 > > > -pgdeactivate 50634 > > > -pgfault 31100294 > > > -pgdemote_kswapd 30856 > > > -pgscan_kswapd 1861981 > > > -pgscan_anon 1822930 > > > -pgscan_file 39051 > > > -pgsteal_anon 386 > > > -pgsteal_file 30470 > > > -pageoutrun 30 > > > -numa_hint_faults 27418279 > > > -numa_pages_migrated 356 > > > > > > +nr_inactive_anon 1662306 > > > +nr_active_anon 440303 > > > +nr_inactive_file 27669 > > > +nr_active_file 1654 > > > +pgpromote_success 1314102 > > > +pgpromote_candidate 1892525 > > > +pgactivate 3284457 > > > +pgdeactivate 1527504 > > > +pgfault 6847775 > > > +pgdemote_kswapd 2142047 > > > +pgscan_kswapd 7496588 > > > +pgscan_anon 7462488 > > > +pgscan_file 34100 > > > +pgsteal_anon 2115661 > > > +pgsteal_file 26386 > > > +pageoutrun 378 > > > +numa_hint_faults 3220891 > > > +numa_pages_migrated 1314102 > > > > > > where -: before this patch, +: after this patch > > > > > > Signed-off-by: Byungchul Park > > > --- > > > mm/vmscan.c | 10 +++++++++- > > > 1 file changed, 9 insertions(+), 1 deletion(-) > > > > > > diff --git a/mm/vmscan.c b/mm/vmscan.c > > > index bba207f41b14..6eda59fce5ee 100644 > > > --- a/mm/vmscan.c > > > +++ b/mm/vmscan.c > > > @@ -2266,9 +2266,17 @@ 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. > > > + * > > > + * However, the condition 'sc->cache_trim_mode == 1' all through > > > + * the scan priorties might lead reclaim failure. If it keeps > > > + * MAX_RECLAIM_RETRIES times, then kswapd would get stopped even > > > + * if there are still plenty anon pages to reclaim, which is not > > > + * desirable. So do not use cache_trim_mode when reclaim is not > > > + * smooth e.i. high scan priority. > > > */ > > > file = lruvec_page_state(target_lruvec, NR_INACTIVE_FILE); > > > - if (file >> sc->priority && !(sc->may_deactivate & DEACTIVATE_FILE)) > > > + if (sc->priority > 1 && file >> sc->priority && > > > + !(sc->may_deactivate & DEACTIVATE_FILE)) > > > sc->cache_trim_mode = 1; > > > else > > > sc->cache_trim_mode = 0; > > > > In get_scan_count(), there's following code, > > > > /* > > * Do not apply any pressure balancing cleverness when the > > * system is close to OOM, scan both anon and file equally > > * (unless the swappiness setting disagrees with swapping). > > */ > > if (!sc->priority && swappiness) { > > scan_balance = SCAN_EQUAL; > > goto out; > > } > > > > So, swappiness is 0 in you system? Please check it. If it's not 0, > > please check why this doesn't help. > > Nice information! Then the change should be: > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index bba207f41b14..91f9bab86e92 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2357,7 +2357,7 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, > * system is close to OOM, scan both anon and file equally > * (unless the swappiness setting disagrees with swapping). > */ > - if (!sc->priority && swappiness) { > + if (sc->priority <= 1 && swappiness) { > scan_balance = SCAN_EQUAL; > goto out; > } Or: diff --git a/mm/vmscan.c b/mm/vmscan.c index bba207f41b14..c54371a398b1 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -6896,7 +6896,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx) if (raise_priority || !nr_reclaimed) sc.priority--; - } while (sc.priority >= 1); + } while (sc.priority >= 0); if (!sc.nr_reclaimed) pgdat->kswapd_failures++; --- Byungchul > Worth noting that the priority goes from DEF_PRIORITY to 1 in > balance_pgdat() of kswapd. I will change how to fix to this if this > looks more reasonable. > > Byungchul