From: "zhaoyang.huang" <zhaoyang.huang@unisoc.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Yu Zhao <yuzhao@google.com>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>,
Zhaoyang Huang <huangzhaoyang@gmail.com>, <steve.kang@unisoc.com>
Subject: [RFC PATCHv2] mm: introduce reclaim throttle in MGLRU
Date: Tue, 16 Jul 2024 17:43:48 +0800 [thread overview]
Message-ID: <20240716094348.2451312-1-zhaoyang.huang@unisoc.com> (raw)
From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
Being like legacy LRU management, direct reclaim threads could isolate
over-sized folios and then be rescheduled, which could lead to
unwanted generation update as well as the thrashing things like before.
This commit would like to have direct_reclaim be throttled by judging
the numbers of isolated and inactive folios.
This patch is verified by launching 8 costmem(malloc and access 1GB VM
in an 5.5GB v6.6 Android system) concurrently and got no system hang
any more(adb shell recovered in 10s which hanged 100% in mainline).
test script under Android14
Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
---
v2: fix a possible unpaired spin_lock/unlock and commit message
---
---
mm/vmscan.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 2e34de9cd0d4..13e5ed9060ad 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4481,6 +4481,7 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw
int scanned;
int tier = -1;
DEFINE_MIN_SEQ(lruvec);
+ bool stalled = false;
/*
* Try to make the obvious choice first, and if anon and file are both
@@ -4503,6 +4504,16 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw
else
type = get_type_to_scan(lruvec, swappiness, &tier);
+ spin_unlock_irq(&lruvec->lru_lock);
+ while (unlikely(too_many_isolated(lruvec_pgdat(lruvec), type, sc))) {
+ if (stalled) {
+ spin_lock_irq(&lruvec->lru_lock);
+ return 0;
+ }
+ reclaim_throttle(lruvec_pgdat(lruvec), VMSCAN_THROTTLE_ISOLATED);
+ }
+ spin_lock_irq(&lruvec->lru_lock);
+
for (i = !swappiness; i < ANON_AND_FILE; i++) {
if (tier < 0)
tier = get_tier_idx(lruvec, type);
@@ -4550,8 +4561,10 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap
if (list_empty(&list))
return scanned;
retry:
+ __mod_node_page_state(lruvec_pgdat(lruvec), NR_ISOLATED_ANON + type, scanned);
reclaimed = shrink_folio_list(&list, pgdat, sc, &stat, false);
sc->nr_reclaimed += reclaimed;
+ __mod_node_page_state(lruvec_pgdat(lruvec), NR_ISOLATED_ANON + type, -scanned);
trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id,
scanned, reclaimed, &stat, sc->priority,
type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);
--
2.25.1
reply other threads:[~2024-07-16 9:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240716094348.2451312-1-zhaoyang.huang@unisoc.com \
--to=zhaoyang.huang@unisoc.com \
--cc=akpm@linux-foundation.org \
--cc=huangzhaoyang@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=steve.kang@unisoc.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