From patchwork Wed Nov 8 06:58:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13449621 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 676ECC4332F for ; Wed, 8 Nov 2023 06:59:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 046FC8D009C; Wed, 8 Nov 2023 01:59:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F39DB8D0058; Wed, 8 Nov 2023 01:59:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD9C78D009C; Wed, 8 Nov 2023 01:59:22 -0500 (EST) 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 C904B8D0058 for ; Wed, 8 Nov 2023 01:59:22 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A32CDC0BE7 for ; Wed, 8 Nov 2023 06:59:22 +0000 (UTC) X-FDA: 81433885764.09.EDE7BE4 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2092.outbound.protection.outlook.com [40.107.255.92]) by imf30.hostedemail.com (Postfix) with ESMTP id B606080011 for ; Wed, 8 Nov 2023 06:59:19 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=clmJ5Fma; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf30.hostedemail.com: domain of link@vivo.com designates 40.107.255.92 as permitted sender) smtp.mailfrom=link@vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1699426760; a=rsa-sha256; cv=pass; b=fjNy/jjJ6GL0iAQr0HwjCy/54gzF+QiZ9eUNO10hidSL6sIhmAlW3BfIzkvKkKe3KWqy34 0ZiRxBilj/NJwv69a9tUkwQoroeZz0IzJ51LnFvjRYG+mpEUlU6Gj8rO83KYslSYj6kOIH aPkK0NdKLXGySeo+V3UKeDXUknI+350= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=clmJ5Fma; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf30.hostedemail.com: domain of link@vivo.com designates 40.107.255.92 as permitted sender) smtp.mailfrom=link@vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699426760; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IY+4KZ/gKYHUwky0cc5tBRLchnjCs2TVZRgBQ1lHr2g=; b=6ugfKpxKfAf42Cv5itwCj6kybgUjVuo72cR/vtBJao+46psCJ4pc4ZvNYDmU8TRB4yaanH ZvbcDlApfCUV0dH1Cwpe9PdPDa6K8YM/XnRRcoPPpz3JsVLjrYFb3DZhlniAYKSmJr5JSp MjGKUst3x+9NRswx6Y+LiS949w7EkoA= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=og/7ipoEpj7QhCnqrKQBMKHou8aurJLOkJO6KmdLxw6jfrcLykOQdGSUd566prgNn+jaeJ+MjZHoagHO3OLgnJjSPaZ1q9OdiXxbbtxLh0S7qvjTx2EHS3X3aTweo4d1oOefXPzurd/ASNbcdQhjZxbkKo3QX88+DaoJMtGIoVsDDBqvy297qB1d4MrLXVwr1HAd4waH+hBdHiN7pw5DDE9NsE0WpfCDxyL7NfTQEiW3GufaP33XWzwm0aDxNrG0Xu9EBMCeDxjlhicXvD6AA8j5pD0Fofr4OuojRYj9F5wnf4tDzzoKxwLGdPAPi03cOXeFoC5BgCsXPsHmY5cDmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IY+4KZ/gKYHUwky0cc5tBRLchnjCs2TVZRgBQ1lHr2g=; b=UNTcquFMuWT1UNOXlPSym+DDlhbkUgIJ4+6zaIZvSo+FTEBPa29BJUcwKfz0t2B4qzN1skD/23iC8bZfc3A4sG1SbcylzBI3r8xo9oPNrXOOU23yr1GD4MGiNMKeLeOhiUQ+Y7jMpgP2upG/zjBUxJ4LYBUrTCVqpLpCu4bgwnQ9Cu8DEdinhyMUdmCrnBs0WussfWwJOGn0/B42smt7dX76DyT39Di7Pth7lZWn78phtp0rWwl+XDyilCtNI4mxY6dSYDDiBKGkREEmlLlUrq6VoSlJHAY9XkIGd53Zx2t3IGZs6ZHGrrUYr7Pufblt9yPvPZqQqtj74aL6tuiEoA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IY+4KZ/gKYHUwky0cc5tBRLchnjCs2TVZRgBQ1lHr2g=; b=clmJ5FmaB1ehw+6p9k6Y5/LZ7fFqPom8LAzeyK6h+b9sgyRs3bXqFpALvIEoHUEWiOUGC8lCDEJjzCSPztl3epdzaOVoVct8GZvzoXEA+BvSlEhjbrCu7X4iHNMe2Fjh+fqXkvbNDxJhKI1jzZoYT8L+K2Qi4w22qpJIDZnKj+h0BmfAg5MAnG0PRemm8pgS4SEs91AVHpjTrFyyUQtGcUk7XekLhz50rMw2XXHr1ghx/0HeBD5DtLRbXPFs/S8jKHORK91aohbwA/kVbhamtv6J50x/xOe9byLNu1AzrhAiLe/s8tL+KqXO9uP1G0sOJjT+z5P7/WKIyPMxnI7mtg== Received: from PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) by TYZPR06MB3983.apcprd06.prod.outlook.com (2603:1096:400:2a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.31; Wed, 8 Nov 2023 06:59:16 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::d754:7b3:dc4c:6b48]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::d754:7b3:dc4c:6b48%6]) with mapi id 15.20.6954.027; Wed, 8 Nov 2023 06:59:16 +0000 From: Huan Yang To: Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , David Hildenbrand , Matthew Wilcox , Huang Ying , Yosry Ahmed , Kefeng Wang , Peter Xu , "Vishal Moola (Oracle)" , Liu Shixin , Yue Zhao , Hugh Dickins , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: opensource.kernel@vivo.com, Huan Yang Subject: [PATCH 1/4] mm: vmscan: LRU unbalance cgroup reclaim Date: Wed, 8 Nov 2023 14:58:12 +0800 Message-Id: <20231108065818.19932-2-link@vivo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108065818.19932-1-link@vivo.com> References: <20231108065818.19932-1-link@vivo.com> X-ClientProxiedBy: SG2PR04CA0187.apcprd04.prod.outlook.com (2603:1096:4:14::25) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|TYZPR06MB3983:EE_ X-MS-Office365-Filtering-Correlation-Id: d59434f4-ddf3-471d-2eac-08dbe02838d3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OC10UwMzJq9lwG1MKCtZWBAljF2GRqDt06D4WRCPcyNK2NP38ig6PbFIu6Zicy+0fUuvyK+/srDyzxeEsJycynhKBxyMF7vO6ZBGenDkp27Va+t+xQyxR/QkkRXZ+A7+vKJjfy77/0pgmPjTYWasUdoUwWW770danrERLoXzLXBLjievpgxTX7f7gaQJrVrpZmd3mFoghjsjTfECUFx2ftKtXcP9XjngtLjZ9/rWKdONOe7yFWZSzsjjM8cvCL25ylsQWFZz3k++QRjPYNq121+63y67Gu53mf8Yi40GRrbyGFfLNFayAOZRnAMLG0lidtE66gHidjTeU0UMgCUbzLpqtQzCwDgtaX3rhGOi55VlcBb0TxDVD4MxEwBBDACos2sd6vA7PCyWY/vfst9pyOelt9B1hjgUzP13ru5x8HR2zWpWasNTaqMAqcMkanrLHnHD50oQBogI2Rr+y0fuq5UMC0XnGhphY3TvDTwwPCsDfOa0sFRv0jA1OoosdTWGPLFxz9bRMupKFk4dNIUSB/YMcuFTVkmLQmdbbepMIchZd9h690iJ21V+Vovr00nl0u8246AS7n85BUO1ItSJtTwJJ80zNcVbURxh03C0AEY5z4gGbgWgnDfbgKESucCanQ9nb7cBaiRUxLjWv3Xjjg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB5676.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(376002)(346002)(136003)(396003)(39850400004)(230922051799003)(64100799003)(186009)(1800799009)(451199024)(6486002)(6512007)(5660300002)(6506007)(478600001)(52116002)(6666004)(8936002)(8676002)(4326008)(7416002)(316002)(2906002)(26005)(110136005)(66556008)(66476007)(66946007)(86362001)(41300700001)(38100700002)(2616005)(107886003)(1076003)(38350700005)(921008)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3TtqxLh1Yc89LV/rI0is1nEgwXsPy5ho3SmJM0eSUXP7+gChf4WCxSDLCdQJwmVur1d2/sXmbl0n8ip2n8aBL7Omt45nyO7wkLdOCdNYurvuoRUmpGCwJrRp/h+PjzYRQPIQr19wGUQQD08fTszr4yqTIRabD7GY3jpkCTKOpCpr2/Yq0kQCkVcG2bbBrWpLBL6i4hxVp/PFrYevrBABVEd4STO0WdANJkyP7lwzXEeiThYr+NlCZFai648S+WFzNIEarxmEW12XNp7bP/6NpuC/FUUMBeO2An8qcxUCHkaQfZuAuzpWTAKXIss0o7gwgopUFiVTNWwraNAGfSlp++GuAuQJOX2ybhoph/Ea4Hl9OvXzflFbcvGAhzy2Bo41wWaNXN8pPWXvG+88qAFiwZfygWl6aBn6e4jm1FZ0OpWimXz1Ay6reteZjquf43HC9TptMvqjsPXawNOCAbEXPOj8DgGCFc1w5JtcBn3PGlnKOirPmNkqz1/ADnzq+kwi7LtewbweLx0n+OWK1bgSYWehRa01iXgk95xlZCWApKwpIwno7CHsdPW7UnC6kzIghXM22+OyyAafLuG47ymkzoRLgeY/63u5xupX6FZWRBqj5BcgCT4ErFdxSrgkzzTCE4b3z3TqJgalkvhjDdWSd5vSa4Gs1XuZUFWFO8fiL2vmp2j0blU8aVKG1uwKMdYoITfLXNfFrrQaIwEisjYG8CCmX4xSJif6A0WE6xUMRbHtozvv/vk8rN98vZNlOPLuXEZUYizHC/EbeLc1/QYCSdx2YdGfna8Ki0V4GndAnB9EMnOxXiUn2Yc0mUk/BAKT6GcJxldlmWjVweG8OQyK7oCYKhVP5vXHj/nS+gV2Jv9MwNeMiZ/RH0v7L4Gwe/cSV1zuNkCamaF2DGOvOYEUjnzI/1IIMrC6uTeHi3VAFKVOlLWViVGi6mPYMzfpK2Trfjy1y1fzGDVUoDbvT1AS4OqH9Vu2sMh0JIYZcZDDWJtZtqwljjRhj/v095i7NSf1+JfrdN5dvPPkIboPLK00M0OXcrpFZBtgBBI7STCb0gW6Ets0Evp4qTkP0BQHIAUkftyFw3JqirRFnjzGLqriJnWowi4cBZkLmgScQDsbOYPGrELWktLzneapz2CxIWQ1MP9I2qOy7vwDC9bJOdR6eWRJrYcrZ/JEcOD8us8NawNitKmbBd7V5Gc1ubHQFxzzb9rrp4W9uvoV+H0Gj43D0SIcRA+CDkd1QmDxaiHfghBZMafHuSYH7ME4LipKWW5EnHFOOl/oZKatbnb/MXDcgCRvxNb+M+DMpLhAAxf7zIpGl2jr1MbZj+2tLBiYY/v81KixcHSYpy4VmvEGytEVQ2zTT+fWVJ1FRmTjW60+r9d/TPqu17bius7eS0Fxb6BOTa1pzEWPVLqAQCHnUsVzrsjTonM3c4fe2xPfPhF7qfZycEfJAPvIiY0VPfRLLE1sFDVgy55O3to+0+y6tm5TwVNlTgaGgTP5D+W6qrG9UhHQqSzqV87j3SENAERexbuWYadgSiBKudOg9vZDphZyxySnf7fAXsUTD4ECigluFipHWQ7ul5ZO+M4irktOqsJC X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d59434f4-ddf3-471d-2eac-08dbe02838d3 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2023 06:59:16.1763 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: GCEiU6qf7qwij7S3RtyHN3QzsWYOHjWYQwDwoZtVVNdvMDAJ0zfPOsZJlbdNkCnUMN1JesXLoV6R73rGgioC4g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB3983 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B606080011 X-Stat-Signature: yjudfp7uhtumascf9yag8iqa6op7rh6g X-HE-Tag: 1699426759-210847 X-HE-Meta: U2FsdGVkX18+94Z8znk67KCTCfv04hBMkn1FoWrRHxzLHoCaxDj5sGTdXPC1sR49xg6y6GZt+hGMQpvh+kr2X/+U0FIpkHX2BahRfwZ04tUs0uEWw4Esk0hkpiU86zJJaWAuIg6Ucg51JfR6hAqxBAbCkDTqbIVuM5+iCmOexOorBVDE3nivMKcv4+K2Y78xgRUYNJRLqf5W11C+zVQIo0jhe96rqXMc+iej0GUqlspgQSTWjje7FK2SDn+k7TqErJ+RjmE/D81nI5L6KJn7nyJ22pWcIDI2u5ca1Mjy0V8dzAELNP0aIpGIfKEtX8yb//TIx5iWkYavc9xDKnlSmjsASxjiF3ukEf8P3tmks7QhePBWctL9Pym+g+24UsgOrov1jedVwweeLPC66SR/LftmX4cwjT9hg/swW8oTlBXTxr8hDbwTE7eJY7HG+MUpPsqaMewPm5z1PTxulBl51tANws1IlsneHAD9izl/Fn/rwuLCxBrSPV+guOnhehycD/xgPCIWqdCe4BT7fdpuNJsY0332lYzXrUocc/FMDSKPp2HeqPyKYh1fmbb+oXId9aiP+ArXe3WsenHp+eEEbkoUmTO+mLWQUXY13dJ9HiiwGaGfChsHHe7Y2nMeryhkTqgygY/z49J+pObmNBC70li4kJZ86lJZgobywVSqpkUk6UX9NoSRN5+C1sTFr0vuT/vAFZ1CKXjuZLvCGptPNF+XmFwDIIcOcniQJdO2gG2/LJMXUgF9gBJVBJJ6HWrp28o29bdbekmJwZxOJ/HNIA2GgWWFpFZp5sX0Jj26lO6dpyaQP+poQF1dCWuIteGBxwhHf1EDCqZGNpigzjutYW7F+3fFsBpjUxTIWGwChpDdCglsv2cYHbYNgPNykS2is5E0+bImD3vkyYkX1Zh2AwGXPvm9CeQpngOBd7ql8N5W2iVpCd60uzFoMdZvQERePHp2VnbW5H9UCWXNQ2D HhT4Gmq2 phUEe5aYtPMQlv6zFQgIgsP4Lu/9jppJv5UaFtv8t/B+K3IqyAZcjC5U9oISma7lQxzgdAkRVy8O77/6hk8orZ6pK/ahxMcLyQE98/RkcgzG4EHw8+EJ8fDpl7aMThlRHkfuC6pYEdBtx4xMG1Q70s5ozukj0O5imdNw/At1L48QZvncELOP5/mgBhzvDFU+FgDcxxTZoRzwJuTra4r5nuUOzJpkR0Khd9VGH8DpoNnizI2cV6A6IEdsxSuqQ2yiVtPDVG+ybnTWktnGmxRqTxRc8Nshl/vapBUorRhBMbkJfCW8kUZL1B8Cg6fmjZkwoyhob0prhWclDkOVQCPReW7g+p4nECJgv6wf1AS1go+S8tzmLgUJB9S36uTTqm0rtG4477EvQBA11THVSkzckn0hDkVXsAdhFYTBa2CMC9AqNcXwGFiK+2cMvaDN4nZoRIDe57xDTWSgfoOU= 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: This patch add unbalance flag into sc, and just allow cgroup reclaim trigger it. If flag set, LRU reclaim will only touch target type folios. Signed-off-by: Huan Yang --- mm/vmscan.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 2cc0cb41fb32..6ed06e73143a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -111,6 +111,10 @@ struct scan_control { /* Proactive reclaim invoked by userspace through memory.reclaim */ unsigned int proactive:1; + /* Unbalance reclaim pages. */ + unsigned int unbalance_anon:1; + unsigned int unbalance_file:1; + /* * Cgroup memory below memory.low is protected as long as we * don't threaten to OOM. If any cgroup is reclaimed at @@ -2338,6 +2342,18 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc) } } +static __always_inline bool unbalance_anon_reclaim(struct scan_control *sc, + int swappiness) +{ + return sc->unbalance_anon && cgroup_reclaim(sc); +} + +static __always_inline bool unbalance_file_reclaim(struct scan_control *sc, + int swappiness) +{ + return sc->unbalance_file && cgroup_reclaim(sc); +} + /* * Determine how aggressively the anon and file LRU lists should be * scanned. @@ -2358,6 +2374,16 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc, unsigned long ap, fp; enum lru_list lru; + if (unlikely(unbalance_file_reclaim(sc, swappiness))) { + scan_balance = SCAN_FILE; + goto out; + } + + if (unlikely(unbalance_anon_reclaim(sc, swappiness))) { + scan_balance = SCAN_ANON; + goto out; + } + /* If we have no swap space, do not bother scanning anon folios. */ if (!sc->may_swap || !can_reclaim_anon_pages(memcg, pgdat->node_id, sc)) { scan_balance = SCAN_FILE; From patchwork Wed Nov 8 06:58:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13449622 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 36185C4332F for ; Wed, 8 Nov 2023 06:59:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC1768D009D; Wed, 8 Nov 2023 01:59:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B69358D0058; Wed, 8 Nov 2023 01:59:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BC1A8D009D; Wed, 8 Nov 2023 01:59:31 -0500 (EST) 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 87B9A8D0058 for ; Wed, 8 Nov 2023 01:59:31 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4E2D1B5166 for ; Wed, 8 Nov 2023 06:59:31 +0000 (UTC) X-FDA: 81433886142.03.CFFB26A Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2115.outbound.protection.outlook.com [40.107.255.115]) by imf29.hostedemail.com (Postfix) with ESMTP id 62C00120004 for ; Wed, 8 Nov 2023 06:59:28 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=VpymtuJE; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf29.hostedemail.com: domain of link@vivo.com designates 40.107.255.115 as permitted sender) smtp.mailfrom=link@vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1699426768; a=rsa-sha256; cv=pass; b=JIGxEfHEiYDe0T51lFlOAdIqGW8cfJMlLaPpT/pktH6TPC3oGMOwsrjK0sQsPBbvJqq7ah F+iA9vRZRZ3f3V8UzLW95teZWiJFrQe8apRuQrUAKuO6wUW6iyx8jb44SM1otsdxezHufC HLXy61jaT+mCVOovU4QmF1hs61HX2FU= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=VpymtuJE; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf29.hostedemail.com: domain of link@vivo.com designates 40.107.255.115 as permitted sender) smtp.mailfrom=link@vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699426768; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IUB6Be0jevwGt8NeqUa3bfJfaaD7+VKX6fpXnVPCeZM=; b=x62NI+/z9QO+i0e1RGo7CMfawdO06JTlev6sJXWrF8m7rYEeBdI/1jt3zCgQjBvD9GwdCw h6mPFyrN93NaflFFpRNEaqZrTd1E9mkidNhQRLTz/RkSVcPC4UwYmejI73S4j/mV1dUWdO k8ccCx098vRtDls+lzQ4dW0+hEnVYBw= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jj3EYZdlPGcZlM93m2vGlfXD2WRSoSpdKDpHd69Cq/1fVq6TzQC6lGKZDpW95LF1JMHjBA66f3LwANv1jaoCWUcB8EZadJ39sxY2SmcWkQIxy/AyRn0W26wQibhuJRQ1CCVBpo4Odpcp7B6Ae5G9koEgQsoCAFLm+W1DIHJMayvi7c9+rdlJphGmrdhow8qKBJhnDzDHwwgA59150Jiomb1RoB4CEEiiekW/KVskk2DFrtHWtYKivG2gDDf9+ztFXlyT9XSVoxJ17ldguL8HnehVMi1pIBj8JcehamVQV+c0gyG7SIWbEUCPlXQk75HbXUayBc1mC9YdVzB2/Lfiyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IUB6Be0jevwGt8NeqUa3bfJfaaD7+VKX6fpXnVPCeZM=; b=ZjbPsMDOwLgMI+m2iTFDfGoQBdd8hZ+tymVjIPkdGzYe9VQkqmh+UFhdRXHFk2/ZH0bMb4+Hckx+nUfdYv7zzQLN36R4KPFXizN/CgP3vVnIEsgthnRgxsWSSu/voTCliMJLlzXPLu361whrRxJd6joAmoEo2VeY76BTpM3/xxol6YgPy231hjVtQd0Uf3vB48k+v9NZMbSo4p2m3YKiKsFKY+GydArmG5f9AUGJKlacT6C9VCl5FRHYhVkHQjXUXAU1/kLoAtjA/r7reT50Kn4yL3B1V7B4ge5cywp1T8QoqXZnB4AcnByrNYYYlvfAMQoaWn5y0MiZZun4kgIUvg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IUB6Be0jevwGt8NeqUa3bfJfaaD7+VKX6fpXnVPCeZM=; b=VpymtuJEQ1SAbFMJnNq0jXihnjCNI2NXNoKUnxHf7gfsSfVQV5OVu2E8YXjQreSAW0n3Ws/Sx4v1whmsja2WqsCzj1zQ74xOfL/fGAAbCEWq2neTdw/LGsd2HQ3w5cG3bVwwka+ZHRGTXjBAAVU7RzId3NnU0mVpj8ACS3OeSaD2kMllJNL6zyivojo745Iec8X/CXjYF1iDEVH2XDGDK6rvIzl/OakhU0KZlRtNKPZp5sT55N4x0m/2ZK6UQhVf+9V30TfWsVq4ZmifZb2waJ4j2RKYIryoROWJkI7jV/CJggGXWwURScPgVcKlG5QEh6UT1bRIW8naN7Xi3I+jYQ== Received: from PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) by TYZPR06MB3983.apcprd06.prod.outlook.com (2603:1096:400:2a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.31; Wed, 8 Nov 2023 06:59:23 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::d754:7b3:dc4c:6b48]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::d754:7b3:dc4c:6b48%6]) with mapi id 15.20.6954.027; Wed, 8 Nov 2023 06:59:23 +0000 From: Huan Yang To: Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , David Hildenbrand , Matthew Wilcox , Huang Ying , Yosry Ahmed , Kefeng Wang , Peter Xu , "Vishal Moola (Oracle)" , Liu Shixin , Yue Zhao , Hugh Dickins , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: opensource.kernel@vivo.com, Huan Yang Subject: [PATCH 2/4] mm: multi-gen LRU: MGLRU unbalance reclaim Date: Wed, 8 Nov 2023 14:58:13 +0800 Message-Id: <20231108065818.19932-3-link@vivo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108065818.19932-1-link@vivo.com> References: <20231108065818.19932-1-link@vivo.com> X-ClientProxiedBy: SG2PR04CA0187.apcprd04.prod.outlook.com (2603:1096:4:14::25) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|TYZPR06MB3983:EE_ X-MS-Office365-Filtering-Correlation-Id: f506a763-a0a4-427f-8a44-08dbe0283d19 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OIB58F67zvsEa5kDgR22kw9XiiibeYLh4UaPmd2yly1Pu41aePNxhJc1Xqv/wi+JO9bn2JEuSrFWM0xMePkjCYYvpNJMRd4oEkwuaIFXv55QFeaY6lNwgKsGc7n+b+db9O8J13dsJIJ7fgmYZUXG8Bop3cwVLQsgg7bWiITDC7FfswDSdN0IzBVjl3zgP8GJiMUU/CuvkuVboovoiNQ0DuYpNhC1RtfppAke2Wu/tmeg9NdC0WqX5riAubAM97g8rBpXlRx7maGIH+Qg5wVnOsmR5MimkBLXeAhdiXJEvdlyWVp0os1F67kQcdmBkn343gG3TLDZbarocgVmf/sm3/IXyVCdTWcBZxEjafQUdG+v0VEfkhphVawboRYEutVznFX7l609hhoYrP06AeAMI/4bNJ/Il8Uf99lDA7oiYFYoTRp/XOFLrg3hD+Ijz3cB4/+0ITwRcWRwWwNslNyoSa5e3smhUThIkYDzKZGjJ4q1jtFBON/BvzBS5zZoTuPlNXX77/+vyONfSlguhZkwQf/P3m5yplB9R04BKjS5/c2P3nE1rmk6qAkhSBTP1mbE8P37j8kIwgAdlpqGrpfa8N7jTJJS0zTxQfuTkjtzZhjXc8cvrWjHUNI0mqjjHVph8bKzgKbWmTYtobDgwimbAw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB5676.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(376002)(346002)(136003)(396003)(39850400004)(230922051799003)(64100799003)(186009)(1800799009)(451199024)(6486002)(6512007)(5660300002)(6506007)(478600001)(52116002)(6666004)(83380400001)(8936002)(8676002)(4326008)(7416002)(316002)(2906002)(26005)(110136005)(66556008)(66476007)(66946007)(86362001)(41300700001)(38100700002)(2616005)(107886003)(1076003)(38350700005)(921008)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1Jz3+P9rWw2w0tLsgYmtAU7PuNVnP5eSZVzYTkeHX/SYdqBOMTqVQESCRn6Nq50XFlqKJa/JSAO+UMB1ycAJG0eGhWwixd2U0cc3O6iUQLZYL8GYxrE386fQgAKvbtwvlMndvDHYESAQd7TLSGT5enJTO6TmCKYG9ZtZnEmzIyC7LMNOagfOJMhwD4xD2LNjGTLkqGbCdZv6et3bv1WQTINZTgHN4097oatPzjt9KyDzQIr2H8/eMaJwi6RM+E6CiqWH1Csmdiw0I5YHTyNodsEl+rYspjcKxB55nIICTzSP6MPdgIB71n9d2DNl0nQK5NGJdVH+NlMErRIRGP4hpR61QM4lFw7xd5YTb2BSGuVEzTN9AZUbyheuRD/spvt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lNJRsKrJjdwB2RHZasWXlHajWTwA4l3yDKDaa4X7utyitWtmw1OwB2446rO2P0YE2I9dVpU8wX9X3smSJXqBvsYWV8d3CvOmMYlUaTP2oik859qjOzGFRQIKlczxlZE6XQeVjhALMHW03iPJs X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f506a763-a0a4-427f-8a44-08dbe0283d19 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2023 06:59:23.3398 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Ug69hlALgR3GwUIA/+KIRoqdUDlRvTU77rJDAEmLouy0zHwxUB3+FWL8l6rYagluc3Lvmn8zvP0mvibh9eUCOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB3983 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 62C00120004 X-Stat-Signature: tskzi5rx9xrnngkzou3w8muiut9gd5cb X-HE-Tag: 1699426768-452661 X-HE-Meta: U2FsdGVkX18zRkWLe1AF4SxA9QPcxgvQMRhVLt+xqjprBBROGAlbAiEtribLIYm4b7Qrd3rC5YhUnb2uZ/nWNMFj9B9Y05kNTGTNZ+6sYoIvpm2Q/uaqn/5W/KeAHhXf6JKuBDoXrFMdGIY3xbUcau9w2oX691N7wessbDYn8se/Ql1PA2Sj0geSf0VTY6iztD98hRG2W+z87ZsHS72mbYS3n4XokuWH8AJz9NYDv5ToTXNoIrqwSD391yMqNGe8GOtrgEAupjY9FZsfhwOCQ8ioSN0e3dNblcaT+2Io+5drapfDppQwyMMBI7ACFvMz4bX5w7LwqsBTSpr4ajr3F8+WV8qkSd9wCTVVp1IyDXVVq9Ncyw3yvMb/nYq8Lx4Us/KfT85T/PTGBjhECSZf7GC7ry0HZXQisrxsLkkil611iLdOr3p65/8vFo1jPfElSdbi+0Qj3KVoTO69NaG7zgOHpmM4NYy88oLnD48NQEdB03un5NOsu+gG+yHuj/b3xQgKQS0xoPAzOAXc78Nj0/stjLcUbFvYh8RDyQW34BYInFsbtZt6OjtLnOWfjx7miGvov0ItoVr1o5DeCK9uvyuRZShiWQ5fwLqGp0i7GbA4JB94HAFwprzXKqiy8f2boT92XYG2sYGrS4I7iJw48kyZ20EIdnP2XXqdFHdJoy4om62Kq2nLf/4etnpLL7lrlcXnw156TCPqZF/nYrCjVp5apioaT4vwgymyj3Zm8p3kpMP+c81jzhn8/rlzdJ7txe5G20amgGXIhJL1hSK28/jRjcUfiO8wymxjdh2S5Lw+cXI6mZCK8UB9HPmjnhqHjoE5vkByEH27aXAFQlw6QzJ8VRVq6NHtjYrECX7SCtz88yRjL+inUOtIgGCl2kY9PwzYbWxPqsqjUCjSBP9IjJb28lFgkCsDALSP1o7DsUujC6+5wE0QNoCz5waxkOSBbm9c+/aWq8+otI6qHns laff78aZ 9HaXIZlDXsrjdy1N4+mtaGfYl8zQUsQKLlFj9e5plUtWqwGYbI1HxgapRQeTl4tJm3jWtA212epAzNrnJJ0VtG6EMQkp9r4yeoOoPrZ/HAxGV4PeUFme4XWscLu11x1Lrlz52ZT1LkoNgIyuvcgFJCLMZCWyBleKZY58NMY8itsaQR0QU03srt8bTNB//pRgxy0QeAvBsL7WCS0dJdIYwquxm7odlQvRY6/QGooHx0IDi/6vsGJHrE2iBTml8AsR6vW5Q0PKNBfDuWBTnmzwO/xqIYIZo+pNobUy9Ddz1x8m3OCetJ1WZ/uVmPEYwYWBrtFpPoPuU++uqYYE= 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: This patch apply unbalance reclaim into MGLRU, if unbalance reclaim, will not scan other type folios. Signed-off-by: Huan Yang --- mm/vmscan.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 6ed06e73143a..9243a1f0d606 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 type; int scanned; int tier = -1; + bool unbalance; DEFINE_MIN_SEQ(lruvec); /* @@ -4488,7 +4489,13 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw * available from the same generation, interpret swappiness 1 as file * first and 200 as anon first. */ - if (!swappiness) + if (unlikely(unbalance_file_reclaim(sc, swappiness))) { + unbalance = true; + type = LRU_GEN_FILE; + } else if (unlikely(unbalance_anon_reclaim(sc, swappiness))) { + unbalance = true; + type = LRU_GEN_ANON; + } else if (!swappiness) type = LRU_GEN_FILE; else if (min_seq[LRU_GEN_ANON] < min_seq[LRU_GEN_FILE]) type = LRU_GEN_ANON; @@ -4504,7 +4511,7 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw tier = get_tier_idx(lruvec, type); scanned = scan_folios(lruvec, sc, type, tier, list); - if (scanned) + if (scanned || unbalance) break; type = !type; From patchwork Wed Nov 8 06:58:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13449623 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 0634EC4167B for ; Wed, 8 Nov 2023 06:59:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 922598D009E; Wed, 8 Nov 2023 01:59:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D1598D0058; Wed, 8 Nov 2023 01:59:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 723F28D009E; Wed, 8 Nov 2023 01:59:36 -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 645658D0058 for ; Wed, 8 Nov 2023 01:59:36 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3030CC094C for ; Wed, 8 Nov 2023 06:59:36 +0000 (UTC) X-FDA: 81433886352.04.6F7F81D Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2119.outbound.protection.outlook.com [40.107.255.119]) by imf18.hostedemail.com (Postfix) with ESMTP id 4201E1C0005 for ; Wed, 8 Nov 2023 06:59:32 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=Sj8IDEbg; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf18.hostedemail.com: domain of link@vivo.com designates 40.107.255.119 as permitted sender) smtp.mailfrom=link@vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699426773; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=B/a3qGG+gxnMlTwRqqKpV2cYE/HaVgtTpeXXE6orwqA=; b=kQ2sxj4mAWllcsz42fLwR31u1CnVaR9pvNG4Gzmu/0S6t+HjVYRdYo9dR2tjtkxETOV5cJ fx15w97NK2+6V5jPhqPVT8yKtdOygwtl5IfJ4S8Dgz0rQxoleNBigOPP1PlNJCEdu/lyY/ 1CMviFolYOgjW7J9Q4CD/Vp0tmFTB1A= ARC-Authentication-Results: i=2; imf18.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=Sj8IDEbg; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf18.hostedemail.com: domain of link@vivo.com designates 40.107.255.119 as permitted sender) smtp.mailfrom=link@vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1699426773; a=rsa-sha256; cv=pass; b=sKl5rmpPV/Aa0gTvYX0LToPO9lgzXKrrSCVJLTGULfrElofuu3etiSeboji3ZUbIpE/v8M 8EEG2MUXsVQ4damDIKF6Kbds5L8cUgSwVpD/aigIQixMk67Qm+h7xS7XWG0DtAaWM6PB5O lTqbjR/K5Bu3iepw5VqWEC9/GMybHAE= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z/v/3DHoUM7PQJydUF0zXCw2oQGQznx7ooJ107rXM2INN8EPXeOmygABV49OxiNTZ3xsis+s5LeV6BLXkvfGiNO3UmJ/leUKttmVKe00+h58HZyADIU8VLpOlmD7TlD5kXIPM2QGvDSUk+h5m7u6wX6qC9UuFypKmpiAFdnPeJnovBVrB7mQNohOVtT3mG3+H5xvvLx4lDbouiOycnwcRdq9O2UeKxSJYuIzfmbFFL6/Yk636UWWqzqt6eVn67xPuoxluBpoh5Td5r2msxNERB6P0Sd3TzA6EgIAlBEd555LJGrHEQdvMxbWTfsiwJGazrAgOxTnGXIEAu/UbftpwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=B/a3qGG+gxnMlTwRqqKpV2cYE/HaVgtTpeXXE6orwqA=; b=SNw4AzEH82JxfSidnD3UxZ16kXprEWxThCUKsDA2roaag5ziB+oayFxX4tSsJ5hJywSRTFhSZfwbkkWuGQ2gF0JQm0o7v7FVi20xrJ2/OZjVCxplG6fXHXGvDtSgAm78q0JBJnxKvv7NRa5JGmfKz5aVGIJcP4pomG05Wq7NT1UWYmL7Goo+HoKU8jcn9D1ZpT8cnKzikApMvH2qjSsNLpKF8CGj3SSQ9EFbUQov86leWDNFxAEzD0TkgQsQoay3WcM2s91hfn/dpJUJMPsRPQR2bYVifyivyPY3MjIXpL2liHPmKnmPKQIC2r/k5Gtwl9yOsihYv44iiW4FaFVQdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=B/a3qGG+gxnMlTwRqqKpV2cYE/HaVgtTpeXXE6orwqA=; b=Sj8IDEbgtHPcGKQ05v584Fp3mcp3Z1zdzUYU0gVIgA10s3UaGuYvHna4AHg8pJqHEBqDMmr4gtRBSQ8Ms9UQhqOhayUkZ/Yyluqu/AzGUek4Xw8ldfv/ErYRzz/fKuelhNlkHMTtRa4VFVGHs39CCc8vEH32m24RjwOLsY26Q3Z3CdjDBspU7IbvaiPTNY7KjH7rviMsSRyiQ+q4mXdB6FZC/1OMJDpMbwxFDaiGpGcsdRIhD9q76e8TBcDlyrqDGg2BA5MhhyRMThNpsjlrdHiK4SLUrZUdUT0rRh6oYtKtzzqu6HjLZBbAEmK5UnB9ubnAckBvd8GWRVztfCkbaQ== Received: from PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) by TYZPR06MB3983.apcprd06.prod.outlook.com (2603:1096:400:2a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.31; Wed, 8 Nov 2023 06:59:30 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::d754:7b3:dc4c:6b48]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::d754:7b3:dc4c:6b48%6]) with mapi id 15.20.6954.027; Wed, 8 Nov 2023 06:59:30 +0000 From: Huan Yang To: Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , David Hildenbrand , Matthew Wilcox , Huang Ying , Kefeng Wang , "Vishal Moola (Oracle)" , Yosry Ahmed , Liu Shixin , Peter Xu , Hugh Dickins , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: opensource.kernel@vivo.com, Huan Yang Subject: [PATCH 3/4] mm: memcg: implement unbalance proactive reclaim Date: Wed, 8 Nov 2023 14:58:14 +0800 Message-Id: <20231108065818.19932-4-link@vivo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108065818.19932-1-link@vivo.com> References: <20231108065818.19932-1-link@vivo.com> X-ClientProxiedBy: SG2PR04CA0187.apcprd04.prod.outlook.com (2603:1096:4:14::25) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|TYZPR06MB3983:EE_ X-MS-Office365-Filtering-Correlation-Id: f00081a1-2242-4184-c1d2-08dbe028411a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H3auOJeIIWjtcC7WXVsZ3rGrFwz2HnOtxFLkdptslO/e/87jVncveHSPNPLRrW/Fa62/+D0owwn4wZfRibKrhFAmKZnSPCl2M2MNh4BVDxC665vFlfpo+RxdaN/9gsWlh8RnEcbj4Av27BtUBoQQMw+OYLIPolWR2Gqfr6vOAEjenw2sVM3qqexGXOTdeJjSAhuVZ4MFyXIG8YaAS+0q4sGSnw2vSuDc0WIUpcouTl482C5/fIeZBw4u3/tq7gQYMnZkrg+jENv2q13ShxnltlNVMuXB+VJw6aJ83CY7p9W4PVxwBSmaURmymEdRvKSZdzgSYix2JbtymJ1TdF68VREVyrL1cB5800s/j0KpzvMZbx637KDReCp/8xPxN+25OGAyAQIHaZeCmV1H9I/XfhHDbLXtbfhauci3Vwlzqjzhdin8Vx8/sGgIYb2Ssau2ckc7B8v294Zs/V4G32uCF4zaiJDWhzgEq/snMMokXlub8mVMMiCqu5LnkagtZe45g/3NSLKx0ahB+QwmRFxRARmEa1caZAB0S8BdIp1yxjopr9CYTnuOCwHpLyKeSg7puMm0ylE9vNdwW9MrfWsTKFswbNtv73egIkEDrBk0dGfBKIaOzpRrUh0MBiuWM1WlB9ElXsdYYNocbrb9QCmWgg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB5676.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(376002)(346002)(136003)(396003)(39850400004)(230922051799003)(64100799003)(186009)(1800799009)(451199024)(6486002)(6512007)(5660300002)(6506007)(478600001)(52116002)(6666004)(83380400001)(8936002)(8676002)(4326008)(7416002)(316002)(2906002)(26005)(110136005)(66556008)(66476007)(66946007)(86362001)(41300700001)(38100700002)(2616005)(107886003)(1076003)(38350700005)(921008)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /BS3Nsbd1Wt+eTrMDCWB47aIWx+76v6eyIIOgogKDDxRXbb5SyUh05lKj0JmuLkrt1pkQyNvrnLkW9rNCOI0YkoePhxJCEpzg82r9FJ7FZlBLEBTWLyTGDJaSf/dxYBanIbWHrEIBBWVayIhtMJDYeWpFn2/38aD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s7RqPt3xl/nTA4nE24g2QOcqyjJYRAF26kj1uqbK0GHanRv0+WCBuPaJjoqFJ1LOZHpC+qUSzmMoWj/v3J8UlVJzOpUKIdIrUqDut83QPJv5vMI9BYf1W58ZS38fmOdxQkbvI12pTzj+zcaIF6OI3HWTPfl/K49phR1a5sYLH1GLlVLW/HFaEyDlmX/8Jor9mmZat8LTrotxgWSws0PxPAqYMqPQJoXK0IdEzkwG0OMqTxogg6HGDwJUoqlUXl8C7cFN+hRF9UfMQxNdnJhVqRqJRdgHDqnUq78Xgkwfg1VWfrukgH7KyPBHFVVqw6Z7NeUTNl0PMdEvhc3Vtp7nOZffFBIhqGpI X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f00081a1-2242-4184-c1d2-08dbe028411a X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2023 06:59:30.0484 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: U9lbTUdfwed/zxPwztNYWJBon8MAeXOIEcPvXi2KMgAXQcTC00KcnSW46ar7mKHjU2PK9BmgFwOBFB2NTrKZ0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB3983 X-Rspam-User: X-Stat-Signature: wuzfhzqn5z4womp1ons69mqpy7q8fbo9 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4201E1C0005 X-HE-Tag: 1699426772-750175 X-HE-Meta: U2FsdGVkX1/ITSOEPpc3NzBBGsgsGEomRKkoeFlwXjPe2M4yetgdV55ahImWhKAdcCi+8w0dOv7hewQxUvidWfXikFf3rhK9q4Pc11e9eHkgnly8F/ZeltjBbEIWf8KXttGRF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OSyKHaXI/1V4bcffPBC+M6EC0Wz0ypZ91mdd9i5GHRzGFLSS73EJ+LGkTmMH8xSCjaivGHBqHBTnIfkJurn8IMGMkfhLLv9AUBg8= 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: This patch add swappiness arg into proactive reclaim interface. User can type "bytes swappiness" into memory.reclaim to control reclaim tendency. Specially, user can type below to only reclaim anon folios: `"100M" 200 > memory.reclaim` Or, type below to only reclaim file folios: `100M 1 > memory.reclaim` User can only type key into memory.reclaim to keep original use. Signed-off-by: Huan Yang --- Documentation/admin-guide/cgroup-v2.rst | 16 ++++--- include/linux/swap.h | 2 + mm/memcontrol.c | 55 +++++++++++++++++++++---- mm/vmscan.c | 2 + 4 files changed, 63 insertions(+), 12 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index c153d0c75f34..5a471ac7f0c3 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1275,16 +1275,22 @@ PAGE_SIZE multiple when read back. This is a simple interface to trigger memory reclaim in the target cgroup. - This file accepts a single key, the number of bytes to reclaim. - No nested keys are currently supported. + This file accepts a few key, the number of bytes to reclaim. + Few nested keys are currently supported. Example:: echo "1G" > memory.reclaim - The interface can be later extended with nested keys to - configure the reclaim behavior. For example, specify the - type of memory to reclaim from (anon, file, ..). + The interface extended with nested keys to configure the + reclaim behavior. For example, specify the swappiness of + memory to reclaim from (anon, file, ..). + + Example:: + + echo "1G" 200 > memory.reclaim (only reclaim anon) + echo "1G" 0 > memory.reclaim (only reclaim file) + echo "1G" 1 > memory.reclaim (only reclaim file) Please note that the kernel can over or under reclaim from the target cgroup. If less bytes are reclaimed than the diff --git a/include/linux/swap.h b/include/linux/swap.h index 3ba146ae7cf5..a024194301d4 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -407,6 +407,8 @@ extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order, #define MEMCG_RECLAIM_MAY_SWAP (1 << 1) #define MEMCG_RECLAIM_PROACTIVE (1 << 2) +#define MEMCG_RECLAIM_ANON (1 << 3) +#define MEMCG_RECLAIM_FILE (1 << 4) extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, unsigned long nr_pages, gfp_t gfp_mask, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index be2ad117515e..a0e460abd41c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6953,19 +6953,47 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, unsigned int nr_retries = MAX_RECLAIM_RETRIES; unsigned long nr_to_reclaim, nr_reclaimed = 0; unsigned int reclaim_options; + int swappiness = -1, org_swappiness, n; + char *tmpbuf; int err; - buf = strstrip(buf); - err = page_counter_memparse(buf, "", &nr_to_reclaim); + tmpbuf = kvzalloc(nbytes, GFP_KERNEL); + if (unlikely(!tmpbuf)) + return -ENOMEM; + + buf = skip_spaces(buf); + n = sscanf(buf, "%s %d", tmpbuf, &swappiness); + if (n < 1) { + err = -EINVAL; + goto out_free; + } + + if (n == 2 && (swappiness > 200 || swappiness < 0)) { + err = -EINVAL; + goto out_free; + } + + err = page_counter_memparse(tmpbuf, "", &nr_to_reclaim); if (err) - return err; + goto out_free; reclaim_options = MEMCG_RECLAIM_MAY_SWAP | MEMCG_RECLAIM_PROACTIVE; + if (swappiness != -1) { + org_swappiness = memcg->swappiness; + memcg->swappiness = swappiness; + if (swappiness == 200) + reclaim_options |= MEMCG_RECLAIM_ANON; + else if (swappiness == 0 || swappiness == 1) + reclaim_options |= MEMCG_RECLAIM_FILE; + } + while (nr_reclaimed < nr_to_reclaim) { unsigned long reclaimed; - if (signal_pending(current)) - return -EINTR; + if (signal_pending(current)) { + err = -EINTR; + goto out; + } /* * This is the final attempt, drain percpu lru caches in the @@ -6979,13 +7007,26 @@ static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, min(nr_to_reclaim - nr_reclaimed, SWAP_CLUSTER_MAX), GFP_KERNEL, reclaim_options); - if (!reclaimed && !nr_retries--) - return -EAGAIN; + if (!reclaimed && !nr_retries--) { + err = -EAGAIN; + goto out; + } nr_reclaimed += reclaimed; } + if (swappiness != -1) + memcg->swappiness = org_swappiness; + return nbytes; + +out: + if (swappiness != -1) + memcg->swappiness = org_swappiness; + +out_free: + kvfree(tmpbuf); + return err; } static struct cftype memory_files[] = { diff --git a/mm/vmscan.c b/mm/vmscan.c index 9243a1f0d606..f4221ec833db 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -6505,6 +6505,8 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg, .may_unmap = 1, .may_swap = !!(reclaim_options & MEMCG_RECLAIM_MAY_SWAP), .proactive = !!(reclaim_options & MEMCG_RECLAIM_PROACTIVE), + .unbalance_anon = !!(reclaim_options & MEMCG_RECLAIM_ANON), + .unbalance_file = !!(reclaim_options & MEMCG_RECLAIM_FILE), }; /* * Traverse the ZONELIST_FALLBACK zonelist of the current node to put From patchwork Wed Nov 8 06:58:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huan Yang X-Patchwork-Id: 13449624 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 28041C4332F for ; Wed, 8 Nov 2023 06:59:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 996668D009F; Wed, 8 Nov 2023 01:59:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 946588D0058; Wed, 8 Nov 2023 01:59:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 798D08D009F; Wed, 8 Nov 2023 01:59:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6256F8D0058 for ; Wed, 8 Nov 2023 01:59:45 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 35B7C1CB700 for ; Wed, 8 Nov 2023 06:59:45 +0000 (UTC) X-FDA: 81433886730.06.6844240 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2098.outbound.protection.outlook.com [40.107.255.98]) by imf27.hostedemail.com (Postfix) with ESMTP id 1885C4000D for ; Wed, 8 Nov 2023 06:59:41 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=T5g6S6Tl; dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf27.hostedemail.com: domain of link@vivo.com designates 40.107.255.98 as permitted sender) smtp.mailfrom=link@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699426782; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cpt3abWMWZL86cwkXtjUBIcD5jhjGiRn8Da7mv9vXpM=; b=XhhMIxAtodEuR/DmdFwHQCUDlY4LO+wRgie7WH7k+WvGasUT/w0LD+mqgvrfAimiaebl3r 8uQYpRCASrE5yad1YYs6BEGOwpGtD6spIW3ymPdwiM5dEd9v3s5g75hX/Rjj419XSL8Bpn LR/iEN97obcecHkHOYf3rfoHum1YTMU= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=T5g6S6Tl; dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf27.hostedemail.com: domain of link@vivo.com designates 40.107.255.98 as permitted sender) smtp.mailfrom=link@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1699426782; a=rsa-sha256; cv=pass; b=GqqmV91zSothJQtg8RBAUD42/vDNrXSNIIwXaspJFRmePrSYOOoH/fNtVMeEtOlocMXrun hkFw2cOqCVlLLAmtmrcpZTSeLMeLGWrl82aMLlDFZjjrW7q6m42stl5f5dyQhJENYQE2wD 9Zs9Iu0PeZkFAb9Aut07o/sPNOufS08= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kCraBDGS4nJwarZ3PkRvhZd8T/mhAFQIIROGgSIlLYDiOC/WmskRfqk6qfAscw3wSbp/UTLCQQVBv3ccRwvMbVuV0fXXJJlghCJ/4bCEKXMWpUSLv5rhACBqdAhcWWGvZbOJXuMljTlnsCekjzpguycCnx3diy6K8QGS/dp8lc+pDsdDLiBaRbshplypDDE1bQzHqhRTjnONWNre7HWOX891+6PnoGNGghAGgILS3emlPnqaVY6sa39DdhsPCBfDNf5bJCrwmM1Oh/Jb3INU/fHFRo3Le9v3zSU4HQ8rt0DGxF0bSQbOx9eSen/DjAZ3ggqqDScxXfAdRmbxcFk7Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cpt3abWMWZL86cwkXtjUBIcD5jhjGiRn8Da7mv9vXpM=; b=gL3lZEyVtmJWEIKiOJe0EBXFrpTe28Pk4dfVINXgw7Xdkmxxs+SA2ivCpVZsmaRiic6uXSyNH3mRc7PulyPJtjybJCOk7aStiSynB64VYUPo4AuFsDYHVZTkUes4LlNQifTgZ0GpzjSqT4zMttQg7aFjjQLj0RWCkv6XrKZC3w4A5dDKRlg3gAVe4DOhWIUX88V+n6hIftgsJDQ7ao/fWSWP3j89rbiHFVj17ATO5gWbO0T1gkjWOu6rXNS+JGCaDP8OY7wB/CBmrWuQtOMr6WcU0tO9M49x69ngjg+GuMpi/2JDafpSsXp4gqwXvg68S777y42nrjURfxE+cX8PxA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cpt3abWMWZL86cwkXtjUBIcD5jhjGiRn8Da7mv9vXpM=; b=T5g6S6Tlf3UWfalMHqwfDUd1akd+qmNpuWnyKPIcik7mlHhPmS3OsnUTQJAY0QloERNytsjhUxRk1WuNO8lHYxqn2Uq1qsNOhyzWophTUR0VB4QEHUANJmfXaFQH8SwIVPrmgw4EiDG1iYIXJkko11Az8egS8Nnw9zKy3mwwHDTmVHFAgWIcFcWO3eQkwwGifqMLHIffNJBIW+AotG0ovr8qcAelTH4D9u843wLi2kH2dNxdlF5resw3ImwFVRFAZqeaoPV7CNFUH85OpY/MjyTKfasqVWbHp4gqyWYn7l94e2FWrJKwUYfUJHAkL1gLlS1gwHD5nBqFv8SANnh6+g== Received: from PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) by TYZPR06MB3983.apcprd06.prod.outlook.com (2603:1096:400:2a::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.31; Wed, 8 Nov 2023 06:59:36 +0000 Received: from PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::d754:7b3:dc4c:6b48]) by PUZPR06MB5676.apcprd06.prod.outlook.com ([fe80::d754:7b3:dc4c:6b48%6]) with mapi id 15.20.6954.027; Wed, 8 Nov 2023 06:59:36 +0000 From: Huan Yang To: Tejun Heo , Zefan Li , Johannes Weiner , Jonathan Corbet , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , David Hildenbrand , Matthew Wilcox , Huang Ying , Kefeng Wang , "Vishal Moola (Oracle)" , Yosry Ahmed , Liu Shixin , Peter Xu , Hugh Dickins , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: opensource.kernel@vivo.com, Huan Yang Subject: [PATCH 4/4] mm: memcg: apply proactive reclaim into cgroupv1 Date: Wed, 8 Nov 2023 14:58:15 +0800 Message-Id: <20231108065818.19932-5-link@vivo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108065818.19932-1-link@vivo.com> References: <20231108065818.19932-1-link@vivo.com> X-ClientProxiedBy: SG2PR04CA0187.apcprd04.prod.outlook.com (2603:1096:4:14::25) To PUZPR06MB5676.apcprd06.prod.outlook.com (2603:1096:301:f8::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB5676:EE_|TYZPR06MB3983:EE_ X-MS-Office365-Filtering-Correlation-Id: 20acc9e2-58a7-4525-20d8-08dbe0284504 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m0d0S7dPrYxKIv/KvKIcZDpSuhQUlfqSF38FYFnQ9sMAibzE1RQ04hVvFBb1cPkaNn84TF0tP729kh5cDm5iRuB4SGFz0Q5V1m78wtJG9qZwHZOkXMBzyoQ12p/GsATf8jwTgmbxvMedHfu7SbFZxUWdI3cnCRK6MPdqeDcTS19sBponAL05mkGmO4teCz4W56lPKITUaWp7VgPpX6rIVmXe/fhC4XHVCQ9PNq8Afxsa/6grdww1ezMKRO/AAQ32rePxyqvHnfoxSvgsCed4ZMdHOerh0rpcA/vbZ7MC2vPebwf6JXy9rju9MhGmsSafx7SYmgPh7s/p58cNh8iPzRDD0ZUSycznujZreMeazcY8q7DwkTLDY1BeLiITIL3LdTJ2/Ku71R+pR+CxaxizwoFSw4OKKEo27bv7i2DvwzSs998w7b3jhfKMJnu59JdLIotH14ELHOk+/J4p0QDRMrTS5aQclaSRHmPkxVSdoTlRwtxAJE8LuvnFip4YAGekZUNbdNcE9Wy/xMsqqsNzIPDLQQZdy13s7LCXv+5wegzLlJKlu1eLhoIfBMGa1C2YdvqsgUIp/YysZyKXpcGOGWWwmkjFf8R21N8mqHLABiKzrBaX6BqLYyWk/ad7nGRFUzdz+4qm9PAr/qXXeOIiEg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR06MB5676.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(376002)(346002)(136003)(396003)(39850400004)(230922051799003)(64100799003)(186009)(1800799009)(451199024)(6486002)(6512007)(5660300002)(6506007)(478600001)(52116002)(6666004)(83380400001)(8936002)(8676002)(4326008)(7416002)(316002)(2906002)(26005)(110136005)(66556008)(66476007)(66946007)(86362001)(41300700001)(38100700002)(2616005)(107886003)(1076003)(38350700005)(921008)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VlPaXpZhkN6WqfJIzxQvj13oPxcigxKR51rIimCIRc15ghggxGoQCKX6chvJn2FYADzlaOfqhWNotGDp5lYl9PrMg10eCNCbvVgOLAK9j34ilnYd+CdVJ1z55n9KPhjnMw7THTcCN8e9PnZi9BJTxTkWskCHXrWUqtxw4GTHnrYkLBgW29hBYw4UU+oZXhRcU9XicMvaoVWqxwZg5J5hgNVQhBAsYgGPsVUpKW62FlY97XI0APrj+7cZ0CrBrQaQpcnTvFa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U2Zo3lwUeZ7FNnGb5U8KV29POxYGh8tpWvgAlrESNRr7c+Yds4Zksd954cUeAAJl4pqZwdOdSvfx6kc8/5dfyz0tM9Ue1znhmk68d5zMHkInbNcQsMqDCqcf861b11s6t8ZZPNj4vENt69q8zQn51P2AzISTeJ/hUZWHKjqlKeGdZpLsPnf9xeQd0H/AODOezyMrbDNDy6TGTxwvWFL6F0MuaIewp9qz0Yljc/9PC12zlg X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20acc9e2-58a7-4525-20d8-08dbe0284504 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB5676.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Nov 2023 06:59:36.6176 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XSS/k6YWNSQpN8HOWteW9MF3EkxY5wmnTwpXNJvyn9d3FdCwRi+q7gY/OPiSeUcwPsWYbIZSokxxEzzINpjYrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB3983 X-Rspamd-Queue-Id: 1885C4000D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 1t7oxa98ekgpyk6z7wgbeo8jd5byau7w X-HE-Tag: 1699426781-554377 X-HE-Meta: U2FsdGVkX1/ZbVP9lOEYBNCtZxOdo/8FF/Ulvh7M6739wwRk/AulMEoY/hieNCdfhSAEcCwBNdF/IY2W4zdbI8/Vsv4OVL7/12REc9bp3itkUEzL8ACRKYJcI7gTVAABItWZRz6sfXyo9NexrsAmaj2kJwFzj6MVK3Qp3qKylXYxgY7J5CQdbHYXD+FzH48zoqS3XEcX4z+tS25ZFRnSWq7JU5mImJDOjlW+iiSdlJUpzF9skLcUs9b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+/qZUJY= 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: For android use, apply proactive reclaim into cgroupv1 Signed-off-by: Huan Yang --- .../admin-guide/cgroup-v1/memory.rst | 38 +++- mm/memcontrol.c | 170 +++++++++--------- 2 files changed, 124 insertions(+), 84 deletions(-) diff --git a/Documentation/admin-guide/cgroup-v1/memory.rst b/Documentation/admin-guide/cgroup-v1/memory.rst index ca7d9402f6be..600bf26a470a 100644 --- a/Documentation/admin-guide/cgroup-v1/memory.rst +++ b/Documentation/admin-guide/cgroup-v1/memory.rst @@ -90,6 +90,7 @@ Brief summary of control files. This knob is deprecated and shouldn't be used. memory.oom_control set/show oom controls. + memory.memory proactive reclaim. memory.numa_stat show the number of memory usage per numa node memory.kmem.limit_in_bytes Deprecated knob to set and read the kernel @@ -972,7 +973,42 @@ Test: (Expect a bunch of notifications, and eventually, the oom-killer will trigger.) -12. TODO +12. Proactive Reclaim +======== +memory.reclaim A write-only nested-keyed file which exists for all cgroups. + +This is a simple interface to trigger memory reclaim in the +target cgroup. + +This file accepts a few key, the number of bytes to reclaim. +Few nested keys are currently supported. + +Example:: + + echo "1G" > memory.reclaim + +The interface extended with nested keys to configure the +reclaim behavior. For example, specify the swappiness of +memory to reclaim from (anon, file, ..). + +Example:: + + echo "1G" 200 > memory.reclaim (only reclaim anon) + echo "1G" 0 > memory.reclaim (only reclaim file) + echo "1G" 1 > memory.reclaim (only reclaim file) + +Please note that the kernel can over or under reclaim from +the target cgroup. If less bytes are reclaimed than the +specified amount, -EAGAIN is returned. + +Please note that the proactive reclaim (triggered by this +interface) is not meant to indicate memory pressure on the +memory cgroup. Therefore socket memory balancing triggered by +the memory reclaim normally is not exercised in this case. +This means that the networking layer will not adapt based on +reclaim induced by memory.reclaim. + +13. TODO ======== 1. Make per-cgroup scanner reclaim not-shared pages first diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a0e460abd41c..03de3387d714 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5209,6 +5209,89 @@ static int mem_cgroup_slab_show(struct seq_file *m, void *p) static int memory_stat_show(struct seq_file *m, void *v); +static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, + size_t nbytes, loff_t off) +{ + struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); + unsigned int nr_retries = MAX_RECLAIM_RETRIES; + unsigned long nr_to_reclaim, nr_reclaimed = 0; + unsigned int reclaim_options; + int swappiness = -1, org_swappiness, n; + char *tmpbuf; + int err; + + tmpbuf = kvzalloc(nbytes, GFP_KERNEL); + if (unlikely(!tmpbuf)) + return -ENOMEM; + + buf = skip_spaces(buf); + n = sscanf(buf, "%s %d", tmpbuf, &swappiness); + if (n < 1) { + err = -EINVAL; + goto out_free; + } + + if (n == 2 && (swappiness > 200 || swappiness < 0)) { + err = -EINVAL; + goto out_free; + } + + err = page_counter_memparse(tmpbuf, "", &nr_to_reclaim); + if (err) + goto out_free; + + reclaim_options = MEMCG_RECLAIM_MAY_SWAP | MEMCG_RECLAIM_PROACTIVE; + if (swappiness != -1) { + org_swappiness = memcg->swappiness; + memcg->swappiness = swappiness; + if (swappiness == 200) + reclaim_options |= MEMCG_RECLAIM_ANON; + else if (swappiness == 0 || swappiness == 1) + reclaim_options |= MEMCG_RECLAIM_FILE; + } + + while (nr_reclaimed < nr_to_reclaim) { + unsigned long reclaimed; + + if (signal_pending(current)) { + err = -EINTR; + goto out; + } + + /* + * This is the final attempt, drain percpu lru caches in the + * hope of introducing more evictable pages for + * try_to_free_mem_cgroup_pages(). + */ + if (!nr_retries) + lru_add_drain_all(); + + reclaimed = try_to_free_mem_cgroup_pages(memcg, + min(nr_to_reclaim - nr_reclaimed, SWAP_CLUSTER_MAX), + GFP_KERNEL, reclaim_options); + + if (!reclaimed && !nr_retries--) { + err = -EAGAIN; + goto out; + } + + nr_reclaimed += reclaimed; + } + + if (swappiness != -1) + memcg->swappiness = org_swappiness; + + return nbytes; + +out: + if (swappiness != -1) + memcg->swappiness = org_swappiness; + +out_free: + kvfree(tmpbuf); + return err; +} + static struct cftype mem_cgroup_legacy_files[] = { { .name = "usage_in_bytes", @@ -5272,6 +5355,10 @@ static struct cftype mem_cgroup_legacy_files[] = { .seq_show = mem_cgroup_oom_control_read, .write_u64 = mem_cgroup_oom_control_write, }, + { + .name = "reclaim", + .write = memory_reclaim, + }, { .name = "pressure_level", .seq_show = mem_cgroup_dummy_seq_show, @@ -6946,89 +7033,6 @@ static ssize_t memory_oom_group_write(struct kernfs_open_file *of, return nbytes; } -static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf, - size_t nbytes, loff_t off) -{ - struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of)); - unsigned int nr_retries = MAX_RECLAIM_RETRIES; - unsigned long nr_to_reclaim, nr_reclaimed = 0; - unsigned int reclaim_options; - int swappiness = -1, org_swappiness, n; - char *tmpbuf; - int err; - - tmpbuf = kvzalloc(nbytes, GFP_KERNEL); - if (unlikely(!tmpbuf)) - return -ENOMEM; - - buf = skip_spaces(buf); - n = sscanf(buf, "%s %d", tmpbuf, &swappiness); - if (n < 1) { - err = -EINVAL; - goto out_free; - } - - if (n == 2 && (swappiness > 200 || swappiness < 0)) { - err = -EINVAL; - goto out_free; - } - - err = page_counter_memparse(tmpbuf, "", &nr_to_reclaim); - if (err) - goto out_free; - - reclaim_options = MEMCG_RECLAIM_MAY_SWAP | MEMCG_RECLAIM_PROACTIVE; - if (swappiness != -1) { - org_swappiness = memcg->swappiness; - memcg->swappiness = swappiness; - if (swappiness == 200) - reclaim_options |= MEMCG_RECLAIM_ANON; - else if (swappiness == 0 || swappiness == 1) - reclaim_options |= MEMCG_RECLAIM_FILE; - } - - while (nr_reclaimed < nr_to_reclaim) { - unsigned long reclaimed; - - if (signal_pending(current)) { - err = -EINTR; - goto out; - } - - /* - * This is the final attempt, drain percpu lru caches in the - * hope of introducing more evictable pages for - * try_to_free_mem_cgroup_pages(). - */ - if (!nr_retries) - lru_add_drain_all(); - - reclaimed = try_to_free_mem_cgroup_pages(memcg, - min(nr_to_reclaim - nr_reclaimed, SWAP_CLUSTER_MAX), - GFP_KERNEL, reclaim_options); - - if (!reclaimed && !nr_retries--) { - err = -EAGAIN; - goto out; - } - - nr_reclaimed += reclaimed; - } - - if (swappiness != -1) - memcg->swappiness = org_swappiness; - - return nbytes; - -out: - if (swappiness != -1) - memcg->swappiness = org_swappiness; - -out_free: - kvfree(tmpbuf); - return err; -} - static struct cftype memory_files[] = { { .name = "current",