From patchwork Tue Jul 16 09:43:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13734230 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 D27F6C3DA49 for ; Tue, 16 Jul 2024 09:44:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08AA46B008C; Tue, 16 Jul 2024 05:44:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 03A646B0092; Tue, 16 Jul 2024 05:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6B876B0093; Tue, 16 Jul 2024 05:44:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C886F6B008C for ; Tue, 16 Jul 2024 05:44:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3AC841216F3 for ; Tue, 16 Jul 2024 09:44:20 +0000 (UTC) X-FDA: 82345130280.22.51FE74D Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf30.hostedemail.com (Postfix) with ESMTP id 6350980022 for ; Tue, 16 Jul 2024 09:44:17 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721123039; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=hFaE5EV42RuJcyGob3PVgZgS9IO8pKHDWSukjJphU5k=; b=wgAeh0M0uLYJHOn/kL4JE1eebfOM/ibchd5xkvIJxY6FzhkKW70xKsc+uH3RSoM7POjzY9 pr3D2IL4IapOUh9450LrkwHrZYm121GzGh45iyd6S4WFnOG2Oe9/3e1fGdjaKLCaT36Blv U1MdpaxsRRXd95x3zlzVC07vI5s1sTI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721123039; a=rsa-sha256; cv=none; b=7xcG2PCiPnml/8kgv7ub0rxaVfUqN6UTt/wsXk0Ivul7cCWfAP26+CX6C0dGmqKOVCKvwg V8THpU02bH/d/1Uo2PPnEbReKyEwYEziVLd1BZSMcGKmMauD0+MWZzPtmFH1tXRcdzD0U3 eD6bsY5TQEHdE4oiiw76kJpKKCmVk6s= Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 46G9huGX055900; Tue, 16 Jul 2024 17:43:56 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4WNYsk3wkTz2KmSNc; Tue, 16 Jul 2024 17:38:34 +0800 (CST) Received: from bj03382pcu01.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Tue, 16 Jul 2024 17:43:54 +0800 From: "zhaoyang.huang" To: Andrew Morton , Yu Zhao , , , Zhaoyang Huang , Subject: [RFC PATCHv2] mm: introduce reclaim throttle in MGLRU Date: Tue, 16 Jul 2024 17:43:48 +0800 Message-ID: <20240716094348.2451312-1-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.0.73.40] X-ClientProxiedBy: SHCAS01.spreadtrum.com (10.0.1.201) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 46G9huGX055900 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 6350980022 X-Stat-Signature: 3radt6m437ay6664kqpknf71jejqermw X-Rspam-User: X-HE-Tag: 1721123057-756792 X-HE-Meta: U2FsdGVkX19sOzv4Ygq6ocq4uMIZDyd5WMBhbs99aOMVeORDxaQnE/JjUYPJiK9YHSBP50j9XBxep4CcQduMvNXdTGs/NnAdgtYRLbg+mjptCJmU07wGdvrqof4CRTWeSZ8zmVcegJSX8HWGcfpYP4r6v6jmQRw46m8tjbcgcrypvBfhyaAh8T37rjBkNerGaRl62XN9hqG+kj6csk5V+nnPl3zRGg/EgSKfszG50N9m3i3voQ2ehYP5JQPpLCPJyFP2+k+MCXT8zcUXLhpizrj6w1Vx0NnHDaTTNbp4uY/qpO7zVjA+14ZwKrYoeTr3vZvwcTuzoAjoDH6W+rO6wy0v2ZuNgzm6OnawjnsIr/fojixv/6su69kusT/BrTl4QG5v1EBCcZPLCIjMhPN7jXzswDLzx1B1Hp+78wwk7tmrAWJ21zVlJE0cKPd1LIRKgwt1Og+GaoWWkUJmYFrRyS5aXnFU8AP9qOXUUHtAYPEJ5iedBbI/6nx3pJAFuVo9Ig5LNiQyhcqLb/xrKcc2GO8LfL5+lAqRPPWScgiDQpEA6W7q5H7vrnlZGw7Be5P+wuQ5nk/vGEuWKgo1wJEhim6eHjV7CgriNX0OeAbJEOtwTM2/Be8Ymnm6KNODhs24r8dCaNi0odhXf5zcMI4jctB8dLoMjuwsWe3jXUGYejFbPrI8WNQI1SFGNEur7ZiUfr73tdppgOxWd32dS77lotDtbmGVSLPbHEV64UrFY4ShUohl5qcXC6c/H617bEnsFiShI36jzYaI8WtmmRA1fSwXLGvIYZgFKdE6QGgZRXWPSatIEvOCaJ1niHd9UzypRPkWURsCpK/Qt3dG/HDW5HtYykF/p+upeJXDf3hFjpRH98bLbSL33czLGS3UAxrj8jJGhVFPXojMn+seJO0NSQ0m4GqCl23Fz2qLYdtKmO/OMfTAZkDka7n8nD8BMKoSF/x3JBwcvOTNxisRL+p 9sHoQhEw K9HJK5Hq3nIRJy0jaoJIJ0LPiEp13lXtta8DpoEN1udIQ6jFD3wBR4CdCAfKka7AsOScuKNz5o73xl+GAJulmVzNhdbRNHpdTzR3P+OdeGwde57Q5TUMA3D1QYZdacHIdQqNazmthJUq09ArA1TVwX63LdSNBGZy1mbwNQzD/994jtFCgiSkVda7Ql17Xdl5rrPE4 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: From: Zhaoyang Huang 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 --- 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);