From patchwork Mon Jul 8 03:15:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13726150 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 037EEC38150 for ; Mon, 8 Jul 2024 03:15:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DC586B007B; Sun, 7 Jul 2024 23:15:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 68CFB6B0082; Sun, 7 Jul 2024 23:15:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 506646B0089; Sun, 7 Jul 2024 23:15:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2EB676B007B for ; Sun, 7 Jul 2024 23:15:38 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CDD6F1C25B8 for ; Mon, 8 Jul 2024 03:15:37 +0000 (UTC) X-FDA: 82315120314.17.A6597E8 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2043.outbound.protection.outlook.com [40.107.215.43]) by imf06.hostedemail.com (Postfix) with ESMTP id 6E7C7180012 for ; Mon, 8 Jul 2024 03:15:34 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=RU9GPRMs; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf06.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.215.43 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720408506; 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: references:dkim-signature; bh=UPFP51JCeqfAvS9UIvZ0yuvgLIug3a2MS+BuOmMlhZ8=; b=OjLfXNtOdFUrXCREdjznbFSHzcyaEBqcZ0qHP8jrrC9f6bySsqTQIsRaNzH6uVkJXeLZjT Y9lLlWazGmq21AJMc7knZolKHRjurN84FZzqjZQ3kBntE59TpqAsEaW1oDcuzQucR+qGPw zHdRNrBka366ySqc8v7kLQ23YJcpv8Y= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1720408506; a=rsa-sha256; cv=pass; b=eS0oj3bNkVz0m8bjL5mSUEv7UNnfLASsyOCGyd4FO6H3+kD/7vGjsqHyo6r4x3rTlEwKEl QeU82U/V5XHJKvtdaqrAFzt+hIapSIEcHIv5MdhmDR06SpaXxKVqIQE/SSqhOEsOQUMg0X 53qEjLqqB5jd6RCawRmqgjs54F57LPE= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=RU9GPRMs; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf06.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.215.43 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f0NM8fZIVL6FKh8K5TsS/dyvvxgS7I78YbyrOvGd7t4Xc950ggeu+dmFbrp6XisiqStKKaHVwqPe2bcfn+SJqS5HU8AbwG4nljc51xZ3siAu/2+AWlk2XhhhEbtwr4fKI+KokqZlDHQpBSOIiYL/Q7XFMu2fm+M1v+XBSMuc0lb84rC24h/UFAMT0rwA4fqC05lyW0bN6jC0CAggsNK0IAIGwiXIWZuOY6AGpl+XMsTKsh8pHNngNL8Sd5iNlu0WEL+24qf6Xx9G50PSyoVRGRBCrQ+k2RANl8e6Aj0ZQiC52do/71OqIU1Umz1MoZ2/WovBAltoR8rTuyV/v0Mdxw== 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=UPFP51JCeqfAvS9UIvZ0yuvgLIug3a2MS+BuOmMlhZ8=; b=X1ic23yorM94ujta36yMzVxDmSC+oI38T8WZRiZuoSVpzbS0stfTJuypxraZmDEzYQgYMFSW5+enEBGGtb0KH0AsnWdjA31QKJHxZognR6Rfy1kqadjwUnlDSkHJXPLLxE4MALRSs/8YLWtSI3zY8z16sJ7CdeDIYJl+XEnrANjDSrVLKYXuUSGVSLwiFVlQx8DR+96RK/Yno71dLUMUvUwvYJ1f2AzjfFtsTXcAAXkjUjnMB8L6Lq1dAXhb1CzHaA3iunMTWv+nKfdgDnPI53+SA2kC+RGSMlV7+fe//1XxhPbVhrEWEQXDo/fp3FolFDhnd0mXd79BkPeYbsrfsQ== 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=UPFP51JCeqfAvS9UIvZ0yuvgLIug3a2MS+BuOmMlhZ8=; b=RU9GPRMs3UTNfEx18BhU+2CPzOzuNCSxBXOHBrXh48FWDFJDCWGYBFKJ6GWK2gDjopAzL9r9dzDK1bj9ShV78P36mYuW1G4Bp9oS+k68F5CAH34z9qeBC5VDLM+1TYjKCYVFRqjG/v8IBOHyXMiZEnRMtNalp+9fehe501NOk6GxKC4okEeB2AaY9rRo03Nib1rQogluuQ5NcLGwA7Ib6gGQIpGCNoBx9+BFnKAruLuxxK7YVOgVlFk+1irI0NOK94mYP9A2jSph0QattZENGLBFAEomsjA4nSKMMC5gw06ay1vI9/cjLe4C8cd2KgeJKVlAaOJlJl+ZYb71qCWMNg== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by KL1PR06MB6671.apcprd06.prod.outlook.com (2603:1096:820:100::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.35; Mon, 8 Jul 2024 03:15:26 +0000 Received: from JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::ed24:a6cd:d489:c5ed]) by JH0PR06MB6849.apcprd06.prod.outlook.com ([fe80::ed24:a6cd:d489:c5ed%3]) with mapi id 15.20.7741.033; Mon, 8 Jul 2024 03:15:26 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song Cc: opensource.kernel@vivo.com, Zhiguo Jiang , Qianfeng Rong Subject: [PATCH v4] mm: shrink skip folio mapped by an exiting task Date: Mon, 8 Jul 2024 11:15:17 +0800 Message-ID: <20240708031517.856-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SI2P153CA0032.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::23) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|KL1PR06MB6671:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a714525-60e2-4b9f-c3d7-08dc9efc368c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antisp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7uuZ4FdKNDbNr+HFuHj+jwaW+MptDkFd34tVeyLe0UL8Rr+M0JTdHxd46+EjxH37b2ayEHL/DfUZPLDiyjjdKpPUlsWDmSO6cCUo2OBqEKroowjJpjOcKVXXdqzS5G8UbldvykOHnE/pu32bulAmu3JrMU26QxUX+5WtqbRF6xgKZ1Bu6RXylkhOYlukkKkXQrnF2xAVDQMZuPoFmwnryfmbU1sNeiedChZx969FisogKBMnnjS46CTyFRNhLHMRw7W+8W3re5bBKvxTJk40s3H/06DkUC9LzNYJdf/ajjnslrtjXyHmaJCGGAcwLOxLDmyR2CS/axh1f5JvFatJL6NSZidFRqmOaUFuNLdqe3ElCQXp+QWrjFQUbc9ulkUreMHZO9ql9o8EOIqPyfWlU1vg6+zZy36Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:JH0PR06MB6849.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nmjxn9WuargAL7rrS91QPpwGwkXLcYGAqrpDFN8sgKXmHHeOZwURbdwcYUKBwBZe/NiADPL2S+6/QJTIIr32lax4Gf8W18ayuo6CBXQjiHRrqbV/78Fjwe6S/lMVDsUf+kxoVYGvksxH5CqSW5xBbrgWEIiALD06+v3YGGokP1N2Dkbc+2Kf7VE7w/boPGoUvzW5QYCDjek9cKMuKjjlqrRf4P3hPVoaeO69lLssfvDJK3BJTtCC4OX7WOoXrQ4Q8PDTwHIwZGSD/BqYe1ua9xZi8WAdLQ2DQJwMVtzUQI1/mao9TkaN+TiEUZwaImn+TycOcuTrFiF/t/v6SXEByNKYCt2A7zTMcVBxzWcWkkNoPjXmIRLQZfgUgCEQ9xqyEeLdqF9ayAZ5ijHSqpy04TKxb+d7WFBO2sn4uwpcCe4x0Aw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X5Jrsyojl2suCjqquM8pm+0L1nnBTTdAZf/Rtcqst+8sTapHrNRRdFZkIRp7zzIv+HmjIHjEj/TgiZ X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a714525-60e2-4b9f-c3d7-08dc9efc368c X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2024 03:15:26.4752 (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: 79mFgI30Cv5rq6kftCVkOy6a7WLrJVrYiKDM/I4Kb0bKcLUgNmje4x58K4aVc8gYSCNBwYUvw/75d+kN+FPfpQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6671 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6E7C7180012 X-Stat-Signature: fndrf9atsemx41h3p46yzihqotnubmx4 X-HE-Tag: 1720408534-150633 X-HE-Meta: U2FsdGVkX1/qV/OQx35Jv6ci3Kp+ulF/qp1l5OB3I6nQ6eBfnBgvhcM9GM5S5cwowJ0YEiQAU6LqK4bEsARUbGglO1IaceCdBI33ZOo9L8lq2kAo38VQetMeFU4TU5nwbZlUtNL/kioUHAjgkQqw6XLLIHntdz+3KyKJ8zLTPxIzI9gDaPV53HdiYup3clU9sy7FjytUhIWYyuGKNFNHKc5VU7Ek6UE1NZgbxOPOGZ683kdpiERbf4F8ARaoLmHHRt2aaa+iONWPEQjXfQN/blgAyh0Cbggjbk1Bp+fUBrjTBG5rucWUs0a48MIWgIo/vW4VGm9RFP2iEbDE2aFclyUAYcKI8MbHFeghUJiKl2vwr4ZYj200FI2M6XqSqnxrU2UZ5f05z/vR/MwzjYrRWlc+5196JAQt4vy0ADLuyf4GlNj/Tx0hcbhCkDJHOoKGGedyUepfgRq2Z6rqUJmgB6NfP0zGuX7RDZDL0FoHqZqfd5rJ8K4LJyXdsOlV5H2im0/NMuyXldfNP3YatFRNubX+RysXGvuD+N/xGKYSiVWRb5XQ22eo1AsFIOt6XmU9VSlqOFoME0TWj7y3W8WscBll36NbM22GWg1L9IH0MoDH/djU8SNs9Cm+BE8sVuTjnSzMEEzWk7Us1ck1Q5ojiuhK1mpFv6COcBKM9UFfMeAbsacEu9c119SqTpc57/kDhMxGZRGjbmsjsy7kArM6i7s5JNjOhAUb7pgDrMBbMctj7C+3Eh5IBb5lczdSMcBJmvkTlmpsIrmmrqw7meBhbe0FpwUl2UsAx4aAQJUpe45+sXpxc6tc6n4fdD9rfSYGRkeEB2nME0P2luXZZKCLh5cf8AtczDSdkCMGsQAlGlqlCBr2HiZM8spFrXGkZtHnXF8cNC2av4Mex8dkKmRYRc97zsVZfis7KfK6UNETtrRLAoGgatu7TxfmmOPvI4agn1cmT/fXUA/fPlvHdH7 q4dRwGbA RNqbQ1gt7VVUM9/ZWS7irP3H6Yc3YwXyuHJmigOvhz/5u/HzQoFVteHLthZ1ZtRJjlupB0qse3LmAo1H38/Sgc0spQk55v/1yw61TckjHmHZqeTKktB8NxkDAwQW5Nt54wNFWeyX/BmUMjNTPv28GEMP/MKECNSwrlnQd9NyNr8JrnInf2xPjVqbMHWJ2tfz8hDARUFFg1vzVYHhEH9/SMo/ELD9YjcVwew9b7Fx/16G1eRCNh2v0OHD0Cr0lKAjfBbQbDU+yC+NBE+zCPfOapOQFU6VRlG6Y7GlDKkhJkr+Iz0+qbUFtIHAhjUNfxkKPdD87 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: If an anon folio reclaimed by shrink_inactive_list is mapped by an exiting task, this anon folio will be firstly swaped-out into swapspace in shrink flow and then this swap folio is freed in task exit flow. But if this folio mapped by an exiting task can skip shrink and be freed directly in task exiting flow, which will save swap-out time and alleviate the load of the tasks exiting process. The file folio is also similar. And when system is low memory, it more likely to occur, because more backend applidatuions will be killed. This patch can alleviate the cpu load of the tasks exiting process. Signed-off-by: Qianfeng Rong --- Change log: v3->v4: 1.Modify that the unshared folios mapped only in exiting task are skip. v2->v3: Nothing. v1->v2: 1.The VM_EXITING added in v1 patch is removed, because it will fail to compile in 32-bit system. Signed-off-by: Zhiguo Jiang --- mm/rmap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) mode change 100644 => 100755 mm/rmap.c diff --git a/mm/rmap.c b/mm/rmap.c index 26806b49a86f..16b7ed04bcbe --- a/mm/rmap.c +++ b/mm/rmap.c @@ -843,6 +843,16 @@ static bool folio_referenced_one(struct folio *folio, int referenced = 0; unsigned long start = address, ptes = 0; + /* Skip the unshared folios mapped only by the single + * exiting process. + */ + if ((!atomic_read(&vma->vm_mm->mm_users) || + test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags)) && + !test_bit(VM_SHARED, &vma->vm_flags)) { + pra->referenced = -1; + return false; + } + while (page_vma_mapped_walk(&pvmw)) { address = pvmw.address;