From patchwork Wed Jul 10 03:10:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13728816 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 F37C6C3DA41 for ; Wed, 10 Jul 2024 03:10:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4458F6B00A0; Tue, 9 Jul 2024 23:10:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F4B36B00A1; Tue, 9 Jul 2024 23:10:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26E246B00A2; Tue, 9 Jul 2024 23:10:39 -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 F34B46B00A0 for ; Tue, 9 Jul 2024 23:10:38 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9AFD31212A9 for ; Wed, 10 Jul 2024 03:10:38 +0000 (UTC) X-FDA: 82322365356.24.4EF4764 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2085.outbound.protection.outlook.com [40.107.215.85]) by imf28.hostedemail.com (Postfix) with ESMTP id 835C7C0005 for ; Wed, 10 Jul 2024 03:10:34 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=SKxlfXqY; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf28.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.215.85 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=1720581003; 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=Z3PL+S5X7q8r2qnDC/7FUZ7Gmw/iWimRo5Vyc54plj4=; b=KoEb8nKx0ktcZ3+mYkTEG+k6Ejk/09JvXbVTPy8bUf7B2HKtrfe+vR8+ted3nThot7KS/u CP97/p15PXkEkzkKGnf9pMW/Wz4JLv61dgsaK88kt+KskNbp2AIY2q0vQ+LlHP/nh/zGzE TbyIoEDdXsiJb+Dz3pvLVYBcWq8yNrA= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1720581003; a=rsa-sha256; cv=pass; b=gBcynRhH/oAD67VUj+B38AcZ7uaxZwv9olNcuM3wdgXQazrCYlFSBaEGG2brl0NZ/+HSAy nPYz3wGRsXvrzKsUaD5mQnQc/njtIRbSTSrmVc5BGGmzXrdHUM1HnLOVMT1fABxk4u5vEe VIZFGv7NtKhMraoCu/JYfm1wLb3yIKU= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=SKxlfXqY; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf28.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.215.85 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=cOQ1D79OyZaxUkRSwLpAmeL9K2jPP2O/ekYO7IgOkzR4Zk7I2SXDvhtazoIDnxeEW4XjKoSXBfxrZ0ocYszwJ3qwe5gdwvDNRvd3jCHx1JKXCv4cemnayo3atZVy8B44sYUl4WcbTrxeUXN1PBz0r8BY5oBd94bRiH7HmvtwiMSaZk8DU4v5qzEbgsLGOdbVwKm3tJPy4nBkJRJJ/rR3pGIOxRrmXcuGcwXi5NNlT2HJ2f2Dcd3trGw9rDnTPOGISuxLV+QPfmAsEuJUCspYqzQocM9LkLucPnheSZoRAJYE4YTAPgUaUy3QCp5OM6I84pFENBXF9uv1/nsXQMUpQA== 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=Z3PL+S5X7q8r2qnDC/7FUZ7Gmw/iWimRo5Vyc54plj4=; b=jMp652Ck58Tv8Ahwg/3NcLb4NdlelbVPgK47Vm2dfdbjxTHLpiwsd0spZXPWHl94M4QY39dg/IZYIqKu1EAJANr02mbdn+SjSwvKqwLXsOMYp/qAuvFda9yvr9346b7aLGIXMkoVM5iDE4fBep8h+GQCrJZ5iHrD5zNOGLGGgmY+AP7coprb0+/uDFjKEMj8VmUe0WxXME4c8FPmlAzOEciiCim6yAmxaw/I5KZzpRFMiuzNlrZArGkMcpTQrQMtTs1TxPaoa5dpIX+aeQCe0L0Nd13pUYxPheeLCz7h2NUAnl6qLFyUnWOI8y5bXmvlMMh/06l/4cgY+CIOsuPiAA== 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=Z3PL+S5X7q8r2qnDC/7FUZ7Gmw/iWimRo5Vyc54plj4=; b=SKxlfXqYRhUMF//gPmzTfba/NNJLQhjHRXQ8FkFy3bki8+ITDKcAxMptvgKBd9Wzrxh9kqX29USlY8leIge9Xfv6XaqVkKqqh/m3oXdAO5om+Y0/7bdRVuYwcYgYqpLyoLQb0OATB6p7m3V3y5rwRjNA+4/dFmGEbwxPuSuibPHnIV2lmeXCj7aWjmBGbE/uI6cBBLIz3vOunY6D0x9xXkwBZUz5+mi86uyXjjqOpPVJ8xjYLKlsv1zMrmf/zyzuaXfk+sbzNofIf8bRBek1s1Dc9dfK2rag1XUfH7kFvVbWd+C7Sya1RvMiQf6LD6/Rm+fQYbhcdVrCLDA0FAQh2Q== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by SI6PR06MB7146.apcprd06.prod.outlook.com (2603:1096:4:251::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.34; Wed, 10 Jul 2024 03:10:29 +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; Wed, 10 Jul 2024 03:10:29 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , David Hildenbrand , Matthew Wilcox Cc: opensource.kernel@vivo.com, Zhiguo Jiang Subject: [PATCH v9] mm: shrink skip folio mapped by an exiting process Date: Wed, 10 Jul 2024 11:10:20 +0800 Message-ID: <20240710031020.1681-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SG2P153CA0043.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c6::12) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|SI6PR06MB7146:EE_ X-MS-Office365-Filtering-Correlation-Id: 24b4e277-a227-43fc-b125-08dca08dda51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: OWad14J4apFlyZeDILaTQ+NU3F/E2YUFj8mpYKlSxlDDh/F7byIQ42i7KW9wMtg71RBw61op6jhNpE+lOXCVnDqgzbj+Klth1mMgybnO8INhzjL56Qgv+wMzyMc+u6q6qKWMLqGBDJTxLOrZQAbUAu2hTT8yH1+/Su8akded5TDn37UGS999f58Rl8RPw5MFlAA2SJrqtHyfgv3JDLf6FvCT6Qf12knSnLvQmx4FSQKd6t9BXeJ4v7tRjxoWsaLKUwztcssHMSJUar7DU5KMMhT6hijrEpWpGoTmrYURfe+2lU+DS8ZEok10BamEU1sGUVesiHPvTtk4qcNG1IStrGXaVW+ifHA3hphyvKGU/Og8F6pjwr+iu8FtmdC/vQslmORF9nIIovxJm4M6wMeTgcjIe5WFU0XcNwU/zHt0nwJ2K4r/b3lYHhx70LY0uqKd7S5+mQiCvw/O3hC01R8zA9dnBB9qR3ZErKVXlQ0l0xA1ANkkUEsels/qQSzIVTy8cOXwa20l/MJp8+XD7NB3nXGvsB3lRnIQO6dbm1dTWqfCPl0LS6Hch7ExPmnItmXJGaZWB8ZovrXexcX5bJJRARk6bdgduxAA99gHRqW0sEjukuDKM6dQf9TWs1Lb+bZgcaxbmjthZcSRzSzZptYYiqUNaM0Q65/vYfCjCfXE0Zf32LlfbRAHbcgbDU6lkFdn7X9pOXhSWF08YyVhBjUgxDzfQeldTbnZc7hxgcF26R5SG1NtBqdE5tOpTdZFVYZ8si/GQ+KCUZz3Gni2b5ZjlrFBwxPMV6c2csMRMkq5UaKju3GvV1oVOsPEnwD4TMNZFE+IJAGont/zSAtYFkzsV0jHOprMMRPjysJVa88UZMeJeV6Rvak9xmNJvk1NDvwuVn4QlFln3hid7Rsjjs1FJwG7HYIxnREG04aF/q44JszzHT5+APbBghkejHutG+6EWLu+O9h0HjJCQhnRutkEmS8B199i0cQrPzFe2VDOf5qCZmzSZDtvDCTuuek13JuisTr49UfayEs5BGZPKoHm1ZG+zw7dN5pD/a2uXJWfTDA1UEHXFQ+F35GYOMIQuozakBnCOPIl6XSsznjvQd6A/XnJtiiNmKe5jiwuaiYOM0lNgcJ6kZoxE+T22HZ+fFrz64EkRkNk7Z1GcytWehwtquhDeNX0VguHWz46oCUq/0LpdPel5JDXNkXHgS6YIdcQZbbcV8S7UXCf05gnwcCkR9r0EDGNCzBBKXaqGTxqNV4dEwROCRjrKkfThN0g+Cyx8+Ja3jpve0YNU3uF2bzJrUQZKizRWK+JokUhnQSlKDvYbQ/aehEkUtF0UiFoDJycVNbm+TSY6KewUFn3TBRclOXzl0eErYLp4Iz/ACMYFr4= 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)(1800799024)(52116014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BiYYEledBTB4NZh72PlArONYTM9oK5TDc9/qgemhGZbXB3KUb8rkN/Q5tL5NgYYi5letucimUNoCyyxsGrOipk5sxIZQfeqApk1RvdHKVEmWg/b8XFRVRAKUYhUyNrD2YckBUI3f53ITK+ZEfgc8w8xmgFGH5YEACdRFPLigMAqX6yOVw33+8hskWINv5fVFmvWySKIjAAWotGr8LFjjrAAksJKfQ+yxkYNgV+UWNoimb6u0p1XRLWVBIUoLHRVWwF01WqSLNGfBBhJww9VNR9I5BHpil7bMmc/LwZhzwLDPXORpvFBQMWXbljQcZNvaBBzH+NUv2QqekKWGA06Ybxi+d5Vj7/LA8bkzx7etu0AReCs5OpZyOE4HT8Uz0GYvb508wQeofPA3WY8g1EJDD12LTLsYG/+guyH6TKV7jb57PNgWbZ1DGSLzXd0pQrf0PfIQgtusKZOzmF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+tYK2aMYSuifkHErvg81Hh+1Bl1T/+wnv+yLHKC3DQ/ X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24b4e277-a227-43fc-b125-08dca08dda51 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2024 03:10:29.4712 (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: IyIJn0lK571+Xrb+YMV/zHTwTgDd6U9zbVPj11TTGhXGr+VNiUSbislQV74mzc4O3bdyZb8Yp/LhBhKrjLwkjA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI6PR06MB7146 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 835C7C0005 X-Stat-Signature: k98dmi1bbz9uwpnmymxb37tsr83uw3um X-HE-Tag: 1720581034-831703 X-HE-Meta: U2FsdGVkX1+JDRzZnv6HGTA7M00ATXBqhcqnQGTVJZo6CuzbrsOqM60oTD72+phnidbRIIUJb5yMN6fXO7MDegTy5nlW9Tl7woGoPRmovzXMptxV4BuU7h5WlOszdGL/Eic2wt/hDEu1sEp70YRxG+ryIMsUrhsuErlHCCqnBsTQUZhj+Euuw1+76I76w+WY+B3GE83tLk5Vht+xLh/1iHJbEOO02wSQIor95z+A6sA9ZuUpVW5040kIhbY1TwLOgalgABLTbQ2zc4lcuq8jDqecf2AugHR1Ig4Mi11mkRpjtcH/54a9ZQTNb2Mrsw5uXWPBIZM5mjVDNZx3UBEB5RDkH/kX714VG2JgE73JJ72m5ijw5qjOWlUZzv5X0QJbcAUOfSlu1PZhA3R+qJDoy8O7rEOmlmaFY+fRpwZ+EKNOEwnwZ/ioUFtw6c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m@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The releasing process of the non-shared anonymous folio mapped solely by an exiting process may go through two flows: 1) the anonymous folio is firstly is swaped-out into swapspace and transformed into a swp_entry in shrink_folio_list; 2) then the swp_entry is released in the process exiting flow. This will result in the high cpu load of releasing a non-shared anonymous folio mapped solely by an exiting process. When the low system memory and the exiting process exist at the same time, it will be likely to happen, because the non-shared anonymous folio mapped solely by an exiting process may be reclaimed by shrink_folio_list. This patch is that shrink skips the non-shared anonymous folio solely mapped by an exting process and this folio is only released directly in the process exiting flow, which will save swap-out time and alleviate the load of the process exiting. Acked-by: Barry Song Signed-off-by: Zhiguo Jiang --- Change log: v8->v9: 1.Update Reviewed-by tag information. v7->v8: 1.Add tags of Reviewed-by and Acked-by. 2.Add #include to solve compilation issue. v6->v7: 1.Modify tab indentation to space indentation of the continuation lines of the condition. v5->v6: 1.Move folio_likely_mapped_shared() under the PTL. 2.Add check_stable_address_space() to replace MMF_OOM_SKIP. 3.Remove folio_test_anon(folio). v4->v5: 1.Further modify to skip non-shared anonymous folio only. 2.Update comments for pra->referenced = -1. v3->v4: 1.Modify to skip only the non-shared anonymous folio mapped solely by an exiting process. 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. Comments from participants and my responses: [v8->v9]: 1.Barry Song No, this is a disaster. Please ask someone for help before you send it. Neither Willy nor David has ever posted any Reviewed-by tags. Please do get someone to help you. Stop posting like this! --> Update Reviewed-by tag information in v9. [v7->v8]: 1.Barry Song You should have collected tags such as reviewed-by, acked-by you got in v6 while sending v7. --> Added in patch v8. You didn't even pass the compilation stage because you're missing 'linux/oom.h'. It's quite disappointing because I believe in your idea, but you didn't even build it before sending. --> Sorry, I overlooked the compilation of folio_likely_mapped_shared() added in patch v5. Compiled and Updated have been compeleted in patch v8. [v6->v7]: 1.Matthew Wilcox You told me you'd fix the indentation. You cannot indent both the continuation lines of the condition and the body of the if by one tab each! --> Modify tab indentation to space indentation of the continuation lines of the condition. [v5->v6]: 1.David Hildenbrand I'm currently working on moving all folio_likely_mapped_shared() under the PTL, where we are then sure that the folio is actually mapped by this process (e.g., no concurrent unmapping poisslbe). Can we do the same here directly? --> You are right. we might use page_vma_mapped_walk_done() to bail out. (Barry Song) 2.Barry Song By the way, I am not convinced that using test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags) is correct (I think it is wrong). And exit_mmap() automatically has MMF_OOM_SKIP. What is the purpose of this check? Is there a better way to determine if a process is an OOM target? What about check_stable_address_space() ? --> Sorry, I overlook the situation with if (is_global_init(p)), MMF_OOM_SKIP is indeed not suitable. It seems feasible for check_stable_address_space() replacing MMF_OOM_SKIP. check_stable_address_space() can indicate oom kill, and !atomic_read(&vma->vm_mm->mm_users) can indicate the normal process exiting. I also think we actually can remove "folio_test_anon(folio)". --> Yes, update in patch v6. [v4->v5]: 1.Barry Song I don't think this is correct. folio_likely_mapped_shared() is almost "correct" but not always. Please explain why you set pra->referenced = -1. Please address all comments before you send a new version. --> Update in patch v5. 2.Matthew Wilcox How is the file folio similar? File folios are never written to swap, and they'll be written back from the page cache whenever the filesystem decides it's a good time to do so. --> What do you mean is that the file folio will not have any relevant identifier left in memory after it is reclamed in the shrink flow, and it will not be released again during an exiting process? If that's the case, I think we only need the anon folio is skipped here. [v3->v4]: 1.Barry Song This is clearly version 3, as you previously sent version 2, correct? --> Yes. Could you please describe the specific impact on users, including user experience and power consumption? How serious is this problem? --> At present, I do not have a suitable method to accurately measure the optimization benefit datas of this modifications, but I believe it theoretically has some benefits. Launching large memory app (for example, starting the camera) in multiple backend scenes may result in the high cpu load of the exiting processes. Applications? --> Yes, when system is low memory, it more likely to occur. I'm not completely convinced this patch is correct, but it appears to be heading in the right direction. Therefore, I expect to see new versions rather than it being dead. You changed the file mode to 755, which is incorrect. --> Solved. Why use -1? Is this meant to simulate lock contention to keep the folio without activating it? Please do have some comments to explain why. I'm not convinced this change is appropriate for shared folios. It seems more suitable for exclusive folios used solely by the exiting process. --> The skiped folios are FOLIOREF_KEEP and added into inactive lru, beacase the folios will be freed soon in the exiting process flow. Yes, the shared folios can not be simply skipped. I have made relevant modifications in patch v4 and please help to further review. https://lore.kernel.org/linux-mm/20240708031517.856-1-justinjiang@vivo.com/ 2.David Hildenbrand but what if it is shared among multiple processes and only one of them is exiting? --> Modify to skip only the non-shared anonymous folio mapped solely by an exiting process in next version v4. [v2->v3:] Nothing. [v1->v2]: 1.Matthew Wilcox What testing have you done of this patch? How often does it happen? Are there particular workloads that benefit from this? (I'm not sure what "mutil backed-applications" are?) And I do mean specifically of this patch, because to my eyes it shouldn't even compile. Except on 32-bit where it'll say "warning: integer constant out of range". --> Yes, I have tested. When the low system memory and the exiting process exist at the same time, it will happen. This modification can alleviate the load of the exiting process. "mutil backed-applications" means that there are a large number of the backend applications in the system. The VM_EXITING added in v1 patch is removed, because it will fail to compile in 32-bit system. mm/rmap.c | 15 +++++++++++++++ mm/vmscan.c | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index 26806b49a86f..5b92c3dadcc2 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -75,6 +75,7 @@ #include #include #include +#include #include @@ -870,6 +871,20 @@ static bool folio_referenced_one(struct folio *folio, continue; } + /* + * Skip the non-shared swapbacked folio mapped solely by + * the exiting or OOM-reaped process. This avoids redundant + * swap-out followed by an immediate unmap. + */ + if ((!atomic_read(&vma->vm_mm->mm_users) || + check_stable_address_space(vma->vm_mm)) && + folio_test_swapbacked(folio) && + !folio_likely_mapped_shared(folio)) { + pra->referenced = -1; + page_vma_mapped_walk_done(&pvmw); + return false; + } + if (pvmw.pte) { if (lru_gen_enabled() && pte_young(ptep_get(pvmw.pte))) { diff --git a/mm/vmscan.c b/mm/vmscan.c index 80f9a486cf27..1d5f78a3dbeb 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -863,7 +863,12 @@ static enum folio_references folio_check_references(struct folio *folio, if (vm_flags & VM_LOCKED) return FOLIOREF_ACTIVATE; - /* rmap lock contention: rotate */ + /* + * There are two cases to consider. + * 1) Rmap lock contention: rotate. + * 2) Skip the non-shared swapbacked folio mapped solely by + * the exiting or OOM-reaped process. + */ if (referenced_ptes == -1) return FOLIOREF_KEEP;