From patchwork Wed Jul 10 08:36:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13729000 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 9F037C3DA42 for ; Wed, 10 Jul 2024 08:36:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CFB96B0083; Wed, 10 Jul 2024 04:36:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 058EE6B0088; Wed, 10 Jul 2024 04:36:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DECE46B008A; Wed, 10 Jul 2024 04:36:58 -0400 (EDT) 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 B64EE6B0083 for ; Wed, 10 Jul 2024 04:36:58 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2F2691C31EC for ; Wed, 10 Jul 2024 08:36:58 +0000 (UTC) X-FDA: 82323187716.13.489510C Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2088.outbound.protection.outlook.com [40.107.117.88]) by imf29.hostedemail.com (Postfix) with ESMTP id D3404120009 for ; Wed, 10 Jul 2024 08:36:54 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=noEG4sBb; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf29.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.88 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=1720600583; 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=ErDNvj0HDvbg1Qm9rfp1tR/SZOARCOdDKlwtcRepnjQ=; b=Zv/XzJEfvTxl8w8q3dp1yj/DVspG2kl7miEOIXxWkzBdvVUyOSCjUBzjO4rTNxS/xPwDog hP40VDvGHgNdisbAUFbsfPTUVhZsu2nO9wQnqkCRW4lWyy0s93qClowuhjnGmpQro9BLGk XMbtKxMLQCiTuNLtdvJ+z7lWuXLGTq8= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1720600583; a=rsa-sha256; cv=pass; b=Y62WoZnIUMFQVlbxbREx6qteWmunp5sqLzemY2q9XHC0Zwaqmj+fGWoahnnNIOUMsYCXRE nDRtfuFfi9kN0jekj5M+OxiSak48JjEXuy9jci4jK3amqW3S6YVm5sKvdJSeq6EuX+4amo 0KVY6Qz+KyHcwsZFbLKawezy8lVo+LI= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=noEG4sBb; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf29.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.88 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=KhTCsfHdkIT91NgVkTih7c6rkmVDPGAUB9393Eb/OsXlULlFNOkOTpELQqsxIoOYfKmUMGh7cgc/DqY3plVd1dKwa/JO73OwmnVA6gQbqPlwJ8WaWjpLbzDgmx7uKfhVOZImxm1g6TolqVEaNQRzwvsxbFJfA1YrgO/s8fhxV3CTBKo/SI8xbLpzPiV8eTgYZEjPgLXq1tea4HV/E9dbqzFV8VCvFb9tr8pN39458ZiCVBsk04fO1UwKeh59WLx+b+q7naUfnMMWBSGIP690VNSad1IDNdrl+MNCiW4mD+T2WJCM3XzoIBXlLeoc13SaJbcle3Dv7VUsCBZie6tp3A== 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=ErDNvj0HDvbg1Qm9rfp1tR/SZOARCOdDKlwtcRepnjQ=; b=lMdx8EJx1VSRdFp8b0KxzDp/tEljrRjCIjDYLFugg6ESf8b/Z9AY/hmB9HcrkPpOjqvSeLfULctbE4DXD2P0K+ggf7e96n5rBN7tsNgAl3LjkgTLxb++xqoPnd6y1GeH5U5eVBBlcf6H36wJRwdi1S8g5MBaDuQCL7FaPBKtZcwtJ29cPp2NOdCAdoFHWJYVpTR6vNsV+TIwOvM+g5nY6I+AerOMmDwnnqPD5pymMPNz5N6DKB/4MQn7zUzuvfOXpEvXsQ7ueTaplRUqWZzyCZrhx9VYJ7O+GBVIqhGdmE0zOtFbLnj3v5wd7oNVYa2ePWg1lS0WFXK8TFCSwj0yUA== 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=ErDNvj0HDvbg1Qm9rfp1tR/SZOARCOdDKlwtcRepnjQ=; b=noEG4sBbmAwavGZfymW6TuNrcmb9bFTV4RUhZ37OIk+VkwCmImIh4RVX6/XZjEpZ388auTFZsZW18QUs/SSghW70WqPfAkpRWyLnwKdCGR0DYk0oMUwCST2B/44ehBmjp7tMNZaIe0yFZv6jpNFWYkDCGBxN7aR2at1rLhC0xFCzQMkTKhpE3/aQftruZEGFCEnTOLbl9n7rqTHVGnE7mvRNLAC3RA00zughZi6trFjGfmxeaT7si4KFx3K62iQzTQeNjmsFZaVH4lJizzM9RcVFFMJjZhvAiZ/B7K2JwYnGi9C6PamtFaEb6BIDoWLDwb+awRNT9JyH5DhDsy65OA== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by SEYPR06MB5792.apcprd06.prod.outlook.com (2603:1096:101:b2::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.20; Wed, 10 Jul 2024 08:36:50 +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 08:36:50 +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 v10] mm: shrink skip folio mapped by an exiting process Date: Wed, 10 Jul 2024 16:36:41 +0800 Message-ID: <20240710083641.546-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SI2P153CA0024.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::13) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|SEYPR06MB5792:EE_ X-MS-Office365-Filtering-Correlation-Id: ede492a5-59b3-4b80-7fee-08dca0bb713a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Micros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LXi31P6yXO9NxDytjUs41EfQkXKFY0RNFDnf8FFGgOnWXg6rEKSy/R5F/EDJRBp6tlBGrXqqr7eoxTqSeBGGrjYg+UxfGbyKy/DGqgQrz8Ae6OMdQ+JRHmOFxR4pQVNic8t/Lk/37S5qGaysAG69+oM7fqekI5CTGhGoV5M5XdSWMtUYq43+grJ2k4uVkQKXjPDeJXteGcwKD9RCmNKl7fl9wxdtoPwDEhprZdRT98GWaVFcpJY1FHzSa9K+AJwaidW++Lk3ZraQPBy2azDTQ+u+nE7u0rFfFfAOGFz5OpVylmx9MDCcPnxilDcR11RZDnKI7bMK7fh8TAAyvsepg3XKZlWtUbaEgl4WjbjeRihsiY34B7zXF8yFrTo= 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)(366016)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OKdvZI4AvKCGtjmkD0cqbjaevRSxqBNtcvlflfFDruKnIm1/r//LB25qgkFpon7rlK5oFPwz2XJpzFYXD9gU7C6ENTJ2lQNYceSBezucpsuHS+tJpRx958LYEJAPuVQI/RTBR1KBC3nz305q3ZMV1iPqSlx/kwz4vzYk6kHKqgWW+o+j0/k8ZrVQCXts55TlrE0lxZwBRi+uQVouxHYSCxAUJE7+9zarM0YEap9HV23Ura4GQu6UGf6IVGRZ1/EheKmQrbfyxb8oTuu9/4HtHvqjHqZveB/VgFnix2Xd0bLn6ZpKJRUto5Wn+BkSRJ6N43cKpaXSOUTNsdqUXMCqV3IiOhLeLhhThHSvu8SS/3+mwQR8bz6hPTJY8MXxKagoBsKqomC7Bu65jnO9RpQsN8VZOdaA+z3XtcBLY+pb6npdvOcDdPUSgKa2WKbTCv2RXGzu/yOPN91/73Axeh2/t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obxLMUA44LEko1onZ0UyyLotbg3pIBZ5qCR8Y X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ede492a5-59b3-4b80-7fee-08dca0bb713a X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2024 08:36:49.9994 (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: jWxg5veRD/791fSHWYwJL6qft+GLZWxg4pPQAI2yvLrD9K8+8tObJxLAnZ6nJGRC0p7LAr9dbPFsY4tcbxAubw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB5792 X-Stat-Signature: 1dpedkd686hybwbwf1e8gfswpnf7qjg6 X-Rspamd-Queue-Id: D3404120009 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1720600614-518943 X-HE-Meta: U2FsdGVkX18vOwBqL7YhMXTUlKGmVLIMQPk+W2m73+D1bDjWuabh0PnR2cUgVx+vZRvP6TIqQNAxuJ9biPcqGiW2Qgcc2c5d4tmyNoOIijM26DMZC7mvgJc8KX67AVmvPAhqXsjr3srgVhDP/hKgeWZrCkrcbddQvYei7qea6WMq/tng0KbVh7Z9U7E0XuIdM15p/CFkd2a9k0fFABVEgdEd5n6iPRUSsUB5+PjCgpY8LhxAyhiOB0evvHT3hanF1pxMDbDwOuVovbH7mQmQsguSflRu9hXgbxwzs1Xs1frpUGTkwLeAMCihzFOPrEdxbClzlk0U49wm3EPToyZoDhzkyce6oKawvqnXHg1RgdYJ4OUJ1bV0HSMlg1kUi54x+3lA6vYfEGPtET1e2+5bJmQx9Ekm2qVG8mTC6GYUwepYmqGsJdSNJ8YQ15LDQYkH/crTw6fkl3WEZtnvymmtOHw3rpbcCjHWxVkzubEvkjFaFIDPS2NsXrvoVwg2Ay3mQ49EVW09PdomRvfv8fFbSy6GrvwZqgeyJhDoXh6RWMiLBCJGgA59HVXI5kr9z+UgqiyxkKPc4D45zAnqJBzF+Jo5ipXCtnGJnHIugTaaGMLXEj5HzTbzNYrNxMAL3x37jXendVREB6XsP+cd/ZCKcOon3uiykjNf0y5tmbeOD9DZx1KOlX++r1lCJ0r74BhgmKeIev3hh6uDJ1MHOct4gOYqynDcS751O6s/rSOcJ7QZYJeWgHAnLCgoGb2GEuYMwnCcpX5KbpBJhaxn2hFnPo9nEtfeetK34I7IVpl3vxBwKY8ef+4UbFObZYB3wt2d6HHesb8TyNQtLonvx1f0bVIO6mTbfvqUMdUtEpgcAXKnfhBBl221ZMDpFpoYqCtqqRVIjkOE3T+W3/O0T6S3/BC8lNmQUsPrvw6u8Q6E4CVSDUNEbOkKtf1SdxuhJBpQFdHX9ADUvxstpmMeKR3 UWyTuo+5 EwytLHMUppXHUo7vU66RjZ1FmWyT0IrBHikiDlFZcm+GC/0cf45vCS+rSMsiHZUYiQqPXiGjmu1vD5wsDR7DRu6fuFYwrFmg6vobH/6KHymF7BgDo/YqKlmWohFHOzBA+HSa3x+ASVuLsjK9ZqsZwsDNRNpc47PDkcNImjMoOV7M/+yrWszU0oyr6NIjy+PAVlDnYidm9Vt8o295kLfn53vVcNS/SMjfEKikJ5914jDWkjr6fkY1jQQrIKwJEptc/JCyYheJQ7CC76NdiJETAUnCagjci+sR757juL4m2L7shJverXjEhjxpqmTfSnVaTlS0Jc6aiaN1BrZBKR51ELmTp4FNEHmFjsHULAzb1277ZnfW+am0mLWckG770xMo/2qaPrN8aoLFO21iEY4jhfZ5i94Ui9DA7eo2M29OVgO6I34tF0rOye8sB3XfFRedGSd0rCJGG52xXURdKIxbrf5lclA== 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: 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: v9->v10: 1.Add folio_test_anon(folio) condition. 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: [v9->v10]: 1.David Hildenbrand && Barry Song BTW, we dropped the folio_test_anon() check, but what about shmem? They also do __folio_set_swapbacked()? Even though anon_shmem behaves similarly to anonymous memory when releasing memory, it doesn't seem worth the added complexity? --> Take folio_test_anon() back. [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 86787df6e212..316a6bb9747b 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_anon(folio) && 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 0761f91b407f..9afe4bb5ba87 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;