From patchwork Mon Jul 15 10:19:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13733273 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 AB53BC3DA59 for ; Mon, 15 Jul 2024 10:24:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAB866B00A0; Mon, 15 Jul 2024 06:24:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5BD86B00A2; Mon, 15 Jul 2024 06:24:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C4A086B00A4; Mon, 15 Jul 2024 06:24:15 -0400 (EDT) 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 AC2C86B00A0 for ; Mon, 15 Jul 2024 06:24:15 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2F023414E6 for ; Mon, 15 Jul 2024 10:24:15 +0000 (UTC) X-FDA: 82341602070.11.35ED7A0 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf14.hostedemail.com (Postfix) with ESMTP id A0774100004 for ; Mon, 15 Jul 2024 10:24:11 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.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=1721039034; 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=w4YeTFtc+sST+nAXQiMfM+NA8hlP89lFwtnXMIKJ9s8=; b=ZrtAeGIgPazzeeo2RPiIQlzFzdf0Qnwqr8ky18MT4mwfvKSrzfrPEyRDvN7YtNKqNNKSX5 GRISzKHUSwlcpY4XEibjodYyV9M3T/DJ0LnQH/Z/xltxYeDh1pjgpudp8p0FiVhgYc4Epy AcHS9aA5hnjTs3W3ckAKVlBOq8HRI7w= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.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=1721039034; a=rsa-sha256; cv=none; b=U847ZTa393VIDTH5JfaGITbnrHawgcQ/lzY+Xrs7o9Zn1Gsf6u3fNBEUIgPe0P4tnIFK5A n5Ilvea8umzZ/AADTZeZyfk0e/EgAOQOkpDAlYmcYBMPfs6kJPjgfxB4EaRHoZPtEWrFBn /H+9b607CeeXuye9klvud/sFUpjT1uQ= Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 46FAK3YJ063713; Mon, 15 Jul 2024 18:20:03 +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 4WMyjv2lsgz2KfjQx; Mon, 15 Jul 2024 18:14:43 +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; Mon, 15 Jul 2024 18:20:01 +0800 From: "zhaoyang.huang" To: Andrew Morton , Yu Zhao , , , Zhaoyang Huang , Subject: [RFC PATCH] mm: introduce reclaim throttle in MGLRU Date: Mon, 15 Jul 2024 18:19:54 +0800 Message-ID: <20240715101954.2433102-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: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 46FAK3YJ063713 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: A0774100004 X-Stat-Signature: unogfoneeqheb8teceyuboo4y616xj7o X-HE-Tag: 1721039051-622717 X-HE-Meta: U2FsdGVkX1+vUe+vZuLAOp3KHjEb9T3e9Tw0YCj1DiY3rM4c51cTFO1Sv0MLBK0GTlPI89Z+bPX9G5J1rWGPjYUtI+oBGIQeM9y9MqZ/hPCwe1F44azCWSEpiBCbvBf1cryx1j8qNM7MMps+cEjfL8MVILcnOTLqhyfkKOOGzvSKPdprhbHcv25DlKq30ULWf2H663Oe4acczYM7SWPB+sf65zuFZCraI3cORCAeQgQJhJDcha4ttUDdjALlkf9kgIzeEs34iTxncgA6SOHDMIQymbeRS+UwEPJa2DNgSV9r3Pu6GgcIqtBmgOveKpw3yLjmAMl/ztGcMpQUiLw6CPHfXih73b0EbC3KTXWVc5NpVJwVRI5ipuh2yvA1zV539V7fI2G0f9FteaCzues9B9unW6U/h/3gz/3m7uqNSiR7e2oZPZl5HlZMZC6VewegKTiXaDzafvuml+h3QkrUO75N8uwpP4yWGH07scencDdfFTrKpytyDavOohGZBl0m4qq02ihBjhL1/o5BU/eYWGNzyDojKiuTSqhWpNwx9NsxMGmTx6RfvjezdgjSRaH+9o40evJI5rYVFfKRxQbB02eTs8l0KB0Kic+934xy75JH2Bd6BlsqNC0SfYLu+ZK036wGuvXwlpErl8NL2PuQtv/QyQwfl2UyNMz8VgJN6F52XDM6/rMK/Pj5bRaZlTefxyK2qNny3jeke8tHaTv8SNdfb3oSI3hWBR8KDab11T0XvKI+c4rl2FNofrIbpBHBUqjV1EdeAtoS/LNXohGWwVb0ai5Qx+CzrIY03byrW+FOGHQaRqPTz3QwtzArcDSGIBUeTUdszQ9hKGeLYoXfdE2TbdGnGDEtaTkICPlMKWq26zeoy2uHQtMssUrNmHRcile+W6hykl0XHqPoMFu7ftAgtpyBSLp6A0kD6CUckQVoLAjV62OQLal4RkKMUhQzYAulrXxbCVHNWvrBsx4 nlpFHZPn 7l4NNzdybbY60B8bLhVqrAMZExegFJO39woVp7i8zH0jCT6X4VemyuyurwQGJkEjGpFJY7TwUOOpKcyRXMayJu+hpkKSJ/6u4+SBEhTHTYd2K1k/9lkrNzSA9PPpvdxcHQb4NIbeWBdEj+iXpz9ZuxhWZDqma8IX3Za7M1nclyhQi3hnTzN/f8xzGwGHs0RiHp2oX 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 proved to be helpful by launching 8 costmem(an exe in Android) concurrently and got no system hang like before. Signed-off-by: Zhaoyang Huang --- mm/vmscan.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 2e34de9cd0d4..a7fdad1b2a78 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,14 @@ 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) + 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 +4559,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);