From patchwork Wed Oct 9 07:49:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13827675 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 54635CED61D for ; Wed, 9 Oct 2024 07:50:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A73806B0088; Wed, 9 Oct 2024 03:50:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A25896B008A; Wed, 9 Oct 2024 03:50:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EA9A6B0093; Wed, 9 Oct 2024 03:50:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 71B806B0088 for ; Wed, 9 Oct 2024 03:50:50 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B7C93AC456 for ; Wed, 9 Oct 2024 07:50:45 +0000 (UTC) X-FDA: 82653292218.13.A8DC5B1 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf15.hostedemail.com (Postfix) with ESMTP id 2A72FA000B for ; Wed, 9 Oct 2024 07:50:46 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.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=1728460178; a=rsa-sha256; cv=none; b=zD8z6lGNZQtLV2edNTwGPpaY/dsZsIv48dFNOmB4gwCZbPB79mIft8xIHP12heQoL1j1+D ohHjEd8kPCmP8ypbOVK0C7dSxHukKkTPOjVQDhEsbSBg06EZiJacfZekkcBSUBhNIYXVl6 KeA+G+HAvHW513rJshMevt8R1i3R370= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.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=1728460178; 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=AL2rPrYpv6TpwHfsJc9YM1GtDT6Ib5UkjGNFDA/mE74=; b=r8PV8iz1TaTAHvhLDjgTPIIEfOXz+eBEZOmJryGUvSMeaWN9UXTd/VLWHJHMslOPOdfDwT WZXD/KSIxZ7mnUMbvtu6fBl/YLtmgc98mjODEIflynzYOQGsKQvumsy3i6u6LLUcgI4Xim 7rOGM5VbydCDJy7Jz5T177ohme/O+yw= Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 4997oJR8056751; Wed, 9 Oct 2024 15:50:19 +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 4XNlG63rdRz2PD1VF; Wed, 9 Oct 2024 15:42:06 +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; Wed, 9 Oct 2024 15:50:16 +0800 From: "zhaoyang.huang" To: Andrew Morton , Yu Zhao , , , Zhaoyang Huang , Subject: [PATCH] mm: throttle and inc min_seq when both page types reach MIN_NR_GENS Date: Wed, 9 Oct 2024 15:49:53 +0800 Message-ID: <20241009074953.608591-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 4997oJR8056751 X-Stat-Signature: 4xzwwhywsefezedib3f63kbw113kgcfu X-Rspamd-Queue-Id: 2A72FA000B X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1728460246-977585 X-HE-Meta: U2FsdGVkX18+WurrJXb91rTOEy2etiPsqdxhYWnIvqWubxyU5NV0Zi1iO+hCKCsIXFQy9ZmiUSro77Kbl6oe6JCs4t2myqHlnvcdWs+lkOUyH06veyNoYUuqfu8m08MsG24jEh39Vatjr3H2OJhEPSi9toFjzmZxDgBypbj7lueEUfJ8LLCICbPW1xirWJcjstr/Q3Vid4b6HfTBmeTi8cKMe0oQ6131oGKO6K3v7rMRXczcqMr/deSzI+67tL2aEdcrqqeNSPMLm7YEYzSw5L/QLCfp0KiQB3l3kDL3E4i8J9itQL4OL8viF0cXBPgG+4qrkJxcRQqT7uzorQoc+sOozLZSnbMDaWoJSZgnDjWHfxnRrk5gyrs7zxvdTvXOr3+Q+lgJpCN/DEk4ACulMLbmk7tR3+swAbRcqQhxLhQ0EK/W3l8U1dcCiCA7s7PyZQUqXq8JB38nQ4ZUnr7/uRD2+zlu1rKcvRbnF1ta99gzg6+zvxWxQTLVrze5Ro3z9AK6FJ0yQ0qYFOTuRrD7rff0Jd7VisrMiju3uo9mFJRDKAQk3uLrhklQyVXqjMNxDARggr4rnY0IwLiXO9Od2QAep6OdtDgHQ4J21F5oAaVJRMJiRX/7uCT5VzPykKZ7UT7mvCZp/y9G6uEyXOFi/jD5Ty34eoOnC1gagSGiOayGbjCcZicSb5gqpycC0kWdF4h28WUbFyEfSPTCp/WDTtSv59CmAKUwv+NQKYThVb7yAmnaPoRexmb3kiZw1JvEp06s08RXHbCQ2XJl/g+TMtVnF0rd0gXPC6arUgjCxwMKoos7viL8pONiMHxdBtkJmU2tGf8IByIUEP6NoeRVZFq2lf0HwfjX4N+OGH5NAGM+VWUMC/yDBIfOaDixuVD7r/EKz4Ea8YoCAB4bdmxYyweCfkV0Wa/Jl9OOp/UrCxPSz4oND2iVGweyGweUkLrCIw+ZzJIAjJPjcRb39Gh U7EtBlFg P2SvTRbGfJAIfmW6X30IjVBRnXF6SgBSZ6l0bHDFWkZXvVnRix9xY14dGH+EznNMWaWFHcNVWbiIpHyo+VKRPcmTAOEhGHePJfIxS3w9x1dltUh2bKSLrMltTHC3gDuC/IogiKfamRDds8isEdWeX6KCk+NcCRvDyfmmIKHtcZoXRE8egTcyv6HJWJtn5ILQvO/PVQTYT+HuRN5Q8CG38TWX6jHAjI2qT20ljvKU5zc9pYvPJqfcnFnTD2w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.005296, 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 The test case of [1] leads to system hang which caused by a local watchdog thread starved over 20s on a 5.5GB RAM ANDROID15(v6.6) system. This commit solve the issue by have the reclaimer be throttled and increase min_seq if both page types reach MIN_NR_GENS, which may introduce a livelock of switching type with holding lruvec->lru_lock. [1] launch below script 8 times simutanously which allocates 1GB virtual memory and access it from user space by each thread. $ costmem -c1024000 -b12800 -o0 & Signed-off-by: Zhaoyang Huang --- mm/vmscan.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index cfa839284b92..83e450d0ce3c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4384,11 +4384,23 @@ static int scan_folios(struct lruvec *lruvec, struct scan_control *sc, int remaining = MAX_LRU_BATCH; struct lru_gen_folio *lrugen = &lruvec->lrugen; struct mem_cgroup *memcg = lruvec_memcg(lruvec); + struct pglist_data *pgdat = lruvec_pgdat(lruvec); VM_WARN_ON_ONCE(!list_empty(list)); - if (get_nr_gens(lruvec, type) == MIN_NR_GENS) - return 0; + if (get_nr_gens(lruvec, type) == MIN_NR_GENS) { + /* + * throttle for a while and then increase the min_seq since + * both page types reach the limit. + */ + if (get_nr_gens(lruvec, !type) == MIN_NR_GENS) { + spin_unlock_irq(&lruvec->lru_lock); + reclaim_throttle(pgdat, VMSCAN_THROTTLE_ISOLATED); + spin_lock_irq(&lruvec->lru_lock); + try_to_inc_min_seq(lruvec, get_swappiness(lruvec, sc)); + } else + return 0; + } gen = lru_gen_from_seq(lrugen->min_seq[type]);