From patchwork Tue Jul 9 12:31:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13727783 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 606FAC2BD09 for ; Tue, 9 Jul 2024 12:31:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4F0E6B0085; Tue, 9 Jul 2024 08:31:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFE116B008C; Tue, 9 Jul 2024 08:31:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9505A6B0096; Tue, 9 Jul 2024 08:31:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6F02F6B0085 for ; Tue, 9 Jul 2024 08:31:35 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 24E3D14183C for ; Tue, 9 Jul 2024 12:31:35 +0000 (UTC) X-FDA: 82320150150.17.F2A1338 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2061.outbound.protection.outlook.com [40.107.255.61]) by imf26.hostedemail.com (Postfix) with ESMTP id 9441B140027 for ; Tue, 9 Jul 2024 12:31:30 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b="Bd/KdBK4"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf26.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.61 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=1720528262; 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=KBQYeZ+KKcOh0ASnvZAPiI6X7kMet71fI0cF5lRBkBg=; b=aF24unacRESMlzBPUsp+oTAejJvckAn95qc6SW1qkzG+DWSxNqzXsAk57bZsq31hlrYKWE wXOsiQ4D/ev97OyryC7q0dkebQbleUA1I9imv/Pi61rZmSmCSWhhSq0ZJRoldo26GhxA40 AJivAnNUoKDpJJzLJykDE0zfYGwMHq4= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1720528262; a=rsa-sha256; cv=pass; b=RypmVfs2UPUjmmY79lzVYlk+DJJga/D6B+wO/HaZRJsI2O8iroXWJE6TUfvRyjfx8Ud9R+ zfjh3s6Bc+Q7vzO4MBDFg3VyfOWdDgQNMwewgw997/FULM2EcmZ9FPo4QGqw1oHyy9Vv1r p9UPa0nEOGc+SHU2IjqWSOe2cn0awO8= ARC-Authentication-Results: i=2; imf26.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b="Bd/KdBK4"; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf26.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.61 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=BhFyGPyfzR8DuLrEMqqABVGh643+saDziSbEWhxUWl+ocEq+EBsH0xI42/TCi8a1+RiUulU+pgiBrQNRkrMof28ANKMh44iQzrsMSti4tg7pNGqHrnN68jtV3C3zChANAH3N0lnpDNWGUOEz3c6cMLEefCswr/blTnR8mdGLPct5rmz51/tqRk9L6fi+U6CBnC7gdqnUKRlUMroLAruZtYnSI5v1oH9zcxO8lXbu1NKf4gqtCZO38w5bBdr6FgKrnA/Dx6KV+9k+Ae6kxbOxN+zqshIlLHk5N3gnQHc3V2yWJ1rC+twCp9dlMoDMu99MVzdaXCgAiYkOkvOn/iGq9g== 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=KBQYeZ+KKcOh0ASnvZAPiI6X7kMet71fI0cF5lRBkBg=; b=dHxRgo4S1lktSMlIDUmcN+/WKV5y67qg6LYOo1Dl6nj1O5rmspyJHEDH3D6d3Bb5uVVuYH4Evjaak9c58KiZLrqPSAH3qkxsDH141QulYvDRgPM2DCXnd8fEMXG9S5tnsTuBPGmOVXyq8ZlGnK7huoLd9+nDG/3nkmcEeEW7NUIwO74M5gEL0nG5Tm+V0TVinG2uurcUDzLxHZq3QvoZIAyzgz01AVjoIRSSfBR5YfejhwtnP18zcvi4RgjZw75eSfCPg4RvkUv8s0FlcHDdtIqh22KDToVO/3PAnCCYCxLQc+Vr/WLTIkb49Yhifqwj7+kgFc5K/3jJzU5dZD9/3w== 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=KBQYeZ+KKcOh0ASnvZAPiI6X7kMet71fI0cF5lRBkBg=; b=Bd/KdBK4DMx5Afbp+4lFxaljop832DOmnVd0ChYJYLcxEzblsXxLDVZJBDgwV2jTo5Dlhr9VpUGXOoqZ3QnE6Mkh+r2+jOKMAQdB+CqRYDUWZXYRghwJmN1J40v851nR0qZe7vlQPQxg/SCOIi2VR3xMJfFbrvJSz9JA/0QAei6CAILmP3cn4FUPpg9VWuzkCYejZ029I+n8lKfDyqysdpnLK0QgaZABIx5pX0icDVYcGxOkDYmDRqjhOW7gU5cWPgkm9PfhvYmP4hXMT102e3EBe/OWRmJwu6HQBAq2/8eHIbzbg+kTEFVszevXVehQWoeVAbkiUfY2BzgEwTtaKg== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by TYZPR06MB6546.apcprd06.prod.outlook.com (2603:1096:400:458::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.20; Tue, 9 Jul 2024 12:31:23 +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; Tue, 9 Jul 2024 12:31:23 +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 v7] mm: shrink skip folio mapped by an exiting process Date: Tue, 9 Jul 2024 20:31:15 +0800 Message-ID: <20240709123115.117-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SI2PR04CA0005.apcprd04.prod.outlook.com (2603:1096:4:197::16) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|TYZPR06MB6546:EE_ X-MS-Office365-Filtering-Correlation-Id: 8172bbfd-dbed-42f3-a89e-08dca0130b45 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-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E0NEVmTSSV74Lwvk3M3rJ+vpVmJw0/sHhGTsICtvf7Pscin5R1e9yle+Ph+7HxKgUqq9VIoFYw7ilf3BrFvqc5Zq7l2opvFDloruyaSu/EqK9OzbAmchpXQ/yL+3ciG7tjaYMCXxh776WAg+UjA+MQ7Fgs6floL18e1R0srpdCjsh4fNElfMd4RA3hcqtTEBrETeWv+mlKUGGPzo1ePbJvCCEN+WZ3TPskoNrgXmTJZXZkF7Kh1lozq3nPkFXe/cK/l5PtmYkkWU50LQwBiF8PNMIcklpHjTcQJdFLmktCTMhiWGFW2g4To0RqaywIubLpFzawpA1ODK18Duu83MFeXgj78Ey6FG52+IUadc+CspEnUT65PI= 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)(376014)(52116014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YLhT8HpZBrXzNC2KsMRIVz3GaF5oa3rfRQI01o6BG3wNZNry3qkpAD/hcB+Ph4lcGHCWNk7iRTc95+OWqQScZt/mFjj/CFAJUaN1WuxoeWcPd+7xCgs7A7qglISidRWD6ifkocLzERq+qTTr3L3fw3hGBhWdlS3FOsReNX+Jdr9oPNtIZLcpzhZ2yEi2ViKxTdokgh+o37SSzmo6MXFPkqzo1mixEsdVu+niMH6p5K0cnNv1q18zE1UHglLPf1MD7extBtxBXwvRzou++LEy1ge2uqkPdvJhndgAZ87GuOeORfZcMAZzCZa4LfIUY9f9SKfuH2y2MQGhPQbzMusAmXe8Kczv9AikZPYoK2P48SEty4tX/Fz/3WpaKFoh8yE/nXdRjMQQuoCsMlZI9TfvV7pnZvCOTAZGlkDtw7M+U4LKuub8dxZ8GHCW412h1wNKCqLN87A3UO8vAdOqcp3FbhJ3rT9Ta44CY3A21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wmCyF/zCKVowQbvLtqw66VeIqP9A1Min X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8172bbfd-dbed-42f3-a89e-08dca0130b45 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2024 12:31:23.4948 (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: 03u1lh/EEbKaDaXaPzMreotVb2ag6rcuUgbg3Xez4eW9cE/Q6rfvnc2hRLJRrW4NVDJMQ97LWYaCEI4cYyxOJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB6546 X-Rspamd-Queue-Id: 9441B140027 X-Stat-Signature: 96c7oxsch7rfuwcsassp4q7k9987wyzn X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1720528290-532907 X-HE-Meta: U2FsdGVkX18T47exq5X1xksGngL73+/N3hb9Ncl+JcisVPSt7y9QWFpoKfJCrbuFW8hTSzv2ArN1LOyalVCReTXrVWe/zvLiA2vSBwwOiBToNITkR937r/nEdBbWwcc3zEBTLy0/pfRNQlRFPxpRFq7digatiQCMt6wvtpu4wE6R4kenfvr2L3UAoG3Mo6n+Bd5bZOEdjpdg0oOyTGbvLaVFhKtu7HwmSf2CZ3w97efAhpLtCtMGi918A1ByWGkUhoyBBgkQQZCsUjzYy7vLmbtBFOQDLhMXR13Oi6HPqQZd+RsOetATtPwn0CeLeHPkNqDt6Pm8ZVAfVoGTnqNNSoLv/p3I7DvcwaMPBS6VkG7JZnyEFwaqvUEuKoIpmpPnnE3sCboA3AyMZSMXzYdauU63y0w4nun0c0pc+Z+bDjhd8v9+PslimsZIsw+A2V1qfsKOXdoWsNctdvi0MsrtDvjm2sPvJ8MSO5QV52uxrUcJi/zFN/TgqgHNqwQZsJ0OtXUXdXWtfRJjzJBSGAgFFAbQbT/hg/jm6IJS4DZ1N5NC9KaV4HRqTLiKrJPfay1Wtkbg2BsaMoPn8aQrGoLHf43dy1oeSh2g4r56YEipDOmUzVIgeyXF2xE0BNV+qQBwC0GPdNg2nz9jUJnFNCktoerarWpljavxaO76igxjUl5VdS0nGDKM4grhzhpWsMhgYb25YYcNs99hHPBIt4/7ursId7guHXHHd9AtRuuaGyJw/mAhJEZqmWF/+2CxXIFnAZmx5Mrgng0UG4jvsLJYrRlQODfgNUqI3t88EpaGRizX0ihOKKD3Obk9CkSukMldLnDrvN71QJ6DK2QoDcMm2G/amQapg95eMPY4c+mr8M6rWUJAO3WXytfMgiIrXpUhw0tNQsotSp+P5ego4g7mEmVau6VN1iYSsDJhSrKDWAUhSAEopM5UL3rVurud0cZ0li/YeqSFoVOsJEV9MVO 5wiEQAlp AvB9z/PQiPigB3xuD4eoVuYdBPzynhsabHBdOh/PRsH4xzKE1HmLoI/9z/dBeZWUY6Feu76TlPHONLqnjyVvapVftMKt966igOEh1nGclxn36KkaH+y9bvlsX8otldkOAE5RkuEhJE7/6RAEGLPopN0qUN5YwsYmAvxSQzHrztWlPhKBAssy2vCaZdVVWx4kxvOXsHQQduZf/rYq+i//ByG6rkdUaN6xcdNOX1i+U2+bzLaunjIsSucJKWEDu0tGoy1XrxA+7yZgO/unstK22GUP+wrPM1BIsv/+J2nqr6jCkWZoRldtd+uy9MXA6gIjRv9jg4nmtqtgqaX5bvb0YsEjIE8ZKNsL7oOifjIaCfWpOGdA4kzerbVLBdpaWqMCxr6GLGAruj9QlUPeg3PPljSRYr4WDpPQZItG3KNDLaVPFbziZ33bKknldU+L+i1NGRCbUReZpJLtYXLcG9Ga+cCTG7Q== 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. Signed-off-by: Zhiguo Jiang Acked-by: Barry Song --- Change log: 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: [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 | 14 ++++++++++++++ mm/vmscan.c | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index 88156deb46a6..bb9954773cce 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -877,6 +877,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;