From patchwork Mon Jul 8 09:04:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13726304 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 B583CC3271E for ; Mon, 8 Jul 2024 09:04:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AC9A6B0092; Mon, 8 Jul 2024 05:04:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 05CAF6B0095; Mon, 8 Jul 2024 05:04:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E18086B0096; Mon, 8 Jul 2024 05:04:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C356E6B0092 for ; Mon, 8 Jul 2024 05:04:34 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4DB9DC11FC for ; Mon, 8 Jul 2024 09:04:34 +0000 (UTC) X-FDA: 82315999668.28.ED96969 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2086.outbound.protection.outlook.com [40.107.117.86]) by imf10.hostedemail.com (Postfix) with ESMTP id 417D7C001F for ; Mon, 8 Jul 2024 09:04:29 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=nw19tyyx; spf=pass (imf10.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.86 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); 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=1720429455; 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=acXqe6PTX9VcN8nUmysG90Goj+fqwohiaxiCxKistXA=; b=BORd1d6Bl8l4Ue7zzanhlnBAC1ukbQd+3hp90Wylk6OEawKZgEOkHNvKs/gy76tY70bpni RWoqhZ9nYd8AnpTj8X8TQTxmHdbN91fMwy9S/gOlmO/AiokNAH8esV2TAWPpFmoLaODf2q EjOmlpBI3fS8u6DlE+mSc14Nu7EXzos= ARC-Authentication-Results: i=2; imf10.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=nw19tyyx; spf=pass (imf10.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.86 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1720429455; a=rsa-sha256; cv=pass; b=5VyViX0d/7tcC7zFhJ0A/JZNIWyUhh+vdN8Vb0BEEuIpMDFPWK/ZvEKx1I4c0zCzbrXu2L dhA+55OKWBVZq7LCaZKjYZ9lDDshu1EVNLgF4i0tjIlnhdnYrqYFuUG4byHPV+Sj1OehQZ JYmKnGozSRPxCx1oJf6jgRpp81D3ui8= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ar0oEEDMYNSy+KzPdbCFlpmlBCAupcCGSaPI41cQxsP+bi8mBK2EZiZzx3k8MmkyQjU4rO3U36XW0zMqGi5J46am2WwDcV6BItL2kvb377tmwKHI+H2+TIOcIv0Dh+A2j8RZQljZoTGWKFfWWmVS8kvENofUYNk072h/E9euojk0xTXefhAGi9bXieBXcjzXAvju9JdKAySyvwc03+X3b7GMDrmWH/u3C5KQ1yTwbFmBoY60l/kf6VkRz4w/Ku3WAAku7eKMq/HO5/dOSJYfnOQ/JX+l4MsWn9h3I2j6b21oXPv+0mMluMyIU28zkYS0t4t2f6sj1+9x/nl+ZXsgvg== 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=acXqe6PTX9VcN8nUmysG90Goj+fqwohiaxiCxKistXA=; b=oghNqsJGx8TFD6DQyh7kQO11N5h68QPdkfEGre9eBvgRlczKaSjenyjJFS5uAIryjQkWciOWgXR/kwW2VnRmX4hFoNspaQk1pxOkUIFteV1q5RJQP3SWEeeyVWLER3gPNB1Hmrbj3G+a2LqbCjkpQTr8jEZAtNX1quYyLjgf+4JOqHOLY0dTguhd4ndLIvSpYIgnx0z5AjzWCCocw2r90vHkY6/mDRcvtyJ4qpEJ2hFdwswNVXMgLo4JzjdU3LIhbGAiFPTGMNtzmfFxF7MLJfsrdKi9Ze3WvEeqNBKfiHADA3PyvLq8AhOKJ9wbMm099BAOIBKmNA0oNoQamTeOvQ== 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=acXqe6PTX9VcN8nUmysG90Goj+fqwohiaxiCxKistXA=; b=nw19tyyxUaM5fFJj5J2RxtkS3Qv15PP1TefhY2otFUAODpQWmzu/W0HbWdO6DNjkosV6/s8Rct5s46uQIqoju3PZVTGcew7E3g5kL/cbaxP+xilamUTygsgWmzIUVaneLH3YagIlSbHZmknXIAFMOYt/IGfoRHF5nvQBend799pkznNs9jyahMpNHSaLdYeS/5GCwENFzqJWZz4d06MlZBFEzQcjzGyhs8NgxxiU+t8UIYdsfYidrae6noVUdIgxAGZnC+TDW/ma/9obbZC9hVMj4wC6xvART5r3COsdND0+Gj3imKyTnHSo58oMYH4ft5RaixZR/1c3JBDQzb61Mg== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by SEZPR06MB6351.apcprd06.prod.outlook.com (2603:1096:101:12a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.34; Mon, 8 Jul 2024 09:04:22 +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 09:04:21 +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 Subject: [PATCH v5] mm: shrink skip folio mapped by an exiting process Date: Mon, 8 Jul 2024 17:04:13 +0800 Message-ID: <20240708090413.888-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SI2P153CA0003.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::20) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|SEZPR06MB6351:EE_ X-MS-Office365-Filtering-Correlation-Id: f16cf014-3722-4499-9da9-08dc9f2cf4fa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|376014|366016|38350700014; X-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nosWnEIC7nlMQUVUbba8yCZtC6h/bXQ3M1Sxg5ug9dUPUkscU8j9BRpj2SDTA4xkBYWViJ4MVRzK8+0T/cu47wwVQD5k0Z5LLYa4GxcB02OASBZ/YkqW9EtDVA2TPlvMnV4uwj0Abo3bwsGr9Z4cyVoupZ+hsqb0jZerAXHjmlShHlQGc/z21XsnlXlClXE5yLI8Cj7Bq4V3DnCrl/OlqcqiAtkZSfsfEZQk/1JEtxfVMZ6s25DefPLDhC11BMA2hLEmRj8XOX7h/vNHRyQy4vMZqKg91gmm61K0olXfuKb4EHBwbUVNItJvX4HMTbDcXxTDdM34kp4RsCdB8lno7Z/CxwVgjWg== 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: L0PxWDqNiGVzvw6QnzSNHRSj0rC2iu157N3X/RwZmZcHYZ363szMwYT9Nr6CR6srQPj2BVYMSw9JlgYirk/WOK7aVyPYy8Nv+Zw9IY2dLGSGdbQqR9e7UgegLZp2LvEV6rKlccaJ/tnhbM1Hh5BRp0B+qN7LTmncZ3V94mAMEE6YbkFz3rltTKcSICmrWssAHwbOMEBZGa/W/0jlgs8lxrtY7PSLcDrWwmz67LzaM8pTzof70gq9pzdLYQW9SZXFwIeXzntoP/eIeuY3PaHcHlK5Qj8UfGnigZ+If0Ge32+pQgGwPVyrLUzBb6/OyfQEpk2yJx8GdFKSWRZrY+usOJ8vqCXDTrGy66Kqd+whJjGblK0QTBq5cKc2zzj2kh+0gj3+vSeW8WxqA/kC5OVOWWfrhu94ZzE813R9jqXgRnzFHZIsUDVzAoFenHHr4Zdlpi/VhGa3CtQyRFUUy6nW1w/H/HZ1egbkSK7n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LEYOcwuH38F5eOdtjvMObF0brCQH8mWfHoHWYsN8Bii708pfb X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f16cf014-3722-4499-9da9-08dc9f2cf4fa X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2024 09:04:21.8419 (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: 1XESp0ze6tts9aDg3onU/mGNVv0zN+MFmuSsjVBB24S+BTFLDHqH3OhCn8TNYKOJeTZ3JaDdbco804aRVruBWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB6351 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 417D7C001F X-Stat-Signature: efyex5gfef3ts914ci7esqucce74iwnf X-Rspam-User: X-HE-Tag: 1720429469-662434 X-HE-Meta: U2FsdGVkX19/jHcDWC0cXO1JEJN8+M+6vDTdyrE6dabu9ZHkFINbsHGHkyEBzXXXk5lxNaxUZBDMbEvE16Tl82Hz0wlCGQrnUQ/7u8eOggE9ngQigEp5JMpj1sJK4+ok5Q4KyTCMoxkHIN13+fZKqJJdZnDIs7vRPuqGMUk3aTsIf8IBWjUJNBJgZJZNV/7AzJwnOHgYFSd9AA4N/6pzS4jgAoYFn2lKrfUywG8kRYy/ztuy42IUOvo2L+ttpBToC1m0NyFNATM21pa116N4NhU0etej2Qa0eqL5pFMU8zrvxdRKgY8I5eLO0buRUzt0A7desb64d67uDv17bYpgRns/j46rVwkjjMa1ZACGUCKg9EAiH2Np8anM0RagFzaegfUNKz1o5y0vYtQ9EeRyL4aDjgd3DSCvRtu4VxzVdxvSWUum+dw/4pjv63fs13AFeMJ+8ugU6mRI0Lm2gz7btrzph7/v+Y76blDDHsGDVFM0NunEEPBzn3Lz5unOzr9x/CldRlES7KZDw54595K6lR/jfzqIs11jy4pVoOzHwEY4HJFBQGaAil56RcQVsd/7Giiai1qEorhoA5+ElT9ekSZlFKqer9e8HCklXRjRty5S9BdaYMyuviTs1T269hMaHu8lobrohff4M+KINbtg9Rf30wwiH82wp6+UV1W4bEsbzI4It/36vKqgmwocdz1kHu65xi94CB9TNszc3uVcbkPCPjWRzDR5OfkwCI51IZUYoSieuO7xfkEc1MFah+qwe2OKK7skKw+ppIdiCzqejftUyZMxglMoPbEIOqL/L2nWEfXrcxp9kWMSY5y9+5k7cqoEgjNNN8NVlEw7EhnGDfuBmw1GNdeap/gglGYUtvVBRycRG1IXRRpY/AgD2xYPbBjsm3vG3RXOi4sXLpriRa6i3riuK1SpL6UClr8uDD+EU3zLo1D1gl4BGbP39o5wTV0NzM6zOJ3htiIYRQX Yu4f/WVC 4g+UDwaGdT39GM/82WneSp2d2eRMAhANH5T+VUkwewCnkChh5EWHUQ80/gl+23ebaY35reixnGJtWnGQ6jpBnLLjMt2S2Egm/AzVAmRwLoTUoj63Qw+lIqMNfpqIfalHgdMNKEww5ueSqZ2bTq+9kiO57VHlB6H5WGW9ktEtZtftKt7Uk/WbrLx57H2kv75EQri5BM8u9YDCPipuwWjNudGPwOWweOUCNQ/+LVcqHnN7c6P0U6zzNf70j8MLX0ee9mv40/K1pfK/J2Xpzv0yPwixWzFkHe2AQesuHKZQdy+m6EyU= 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 increase the cpu load of releasing a non-shared anonymous folio mapped solely by an exiting process, because the folio go through swap-out and the releasing the swapspace and swp_entry. When system is low memory, it is more likely to occur, because more backend applidatuions will be killed. The modification is that shrink skips the non-shared anonymous folio solely mapped by an exting process and the 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 --- Change log: v4->v5: 1.Modify to skip non-shared anonymous folio only. 2.Update comments for pra->referenced = -1. 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. mm/rmap.c | 13 +++++++++++++ mm/vmscan.c | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mm/rmap.c b/mm/rmap.c index 26806b49a86f..5b5281d71dbb --- a/mm/rmap.c +++ b/mm/rmap.c @@ -843,6 +843,19 @@ static bool folio_referenced_one(struct folio *folio, int referenced = 0; unsigned long start = address, ptes = 0; + /* + * Skip the non-shared anonymous folio mapped solely by + * the single exiting process, and release it directly + * in the process exiting. + */ + if ((!atomic_read(&vma->vm_mm->mm_users) || + test_bit(MMF_OOM_SKIP, &vma->vm_mm->flags)) && + folio_test_anon(folio) && folio_test_swapbacked(folio) && + !folio_likely_mapped_shared(folio)) { + pra->referenced = -1; + return false; + } + while (page_vma_mapped_walk(&pvmw)) { address = pvmw.address; diff --git a/mm/vmscan.c b/mm/vmscan.c index 0761f91b407f..bae7a8bf6b3d --- 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 anonymous folio mapped solely by + * the single exiting process. + */ if (referenced_ptes == -1) return FOLIOREF_KEEP;