From patchwork Tue Jul 30 11:44:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13747293 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 4DED0C52D1D for ; Tue, 30 Jul 2024 11:46:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE0AC6B0096; Tue, 30 Jul 2024 07:46:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D69936B0098; Tue, 30 Jul 2024 07:46:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BED926B0099; Tue, 30 Jul 2024 07:46:16 -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 97D0B6B0096 for ; Tue, 30 Jul 2024 07:46:16 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1D7A7120268 for ; Tue, 30 Jul 2024 11:46:16 +0000 (UTC) X-FDA: 82396240752.12.3B4530A Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2066.outbound.protection.outlook.com [40.107.255.66]) by imf26.hostedemail.com (Postfix) with ESMTP id 30981140004 for ; Tue, 30 Jul 2024 11:46:12 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=ZnWYkggF; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf26.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.66 as permitted sender) smtp.mailfrom=justinjiang@vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722339933; a=rsa-sha256; cv=pass; b=eBCghRtRqe13vrkt3QS+7+BQcQ3Nft8ruNejV9YC2PbvllZIjnrXn6s9ZZGtSZ3Mvkuaho IGtluBJ/UI0nqx61eckVs6SO63Fb5BUyn5BSAPqwnogu8HgpwvmqGCIzxQwREBCKV30JAG kM3F4HcA1vnVd1SH+5gMgrYXvpay8Ho= ARC-Authentication-Results: i=2; imf26.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=ZnWYkggF; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf26.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.66 as permitted sender) smtp.mailfrom=justinjiang@vivo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722339933; 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:in-reply-to:references:references:dkim-signature; bh=lyxFrc6Clfrofhrb3kvsAmejA25jBTP+9YIvp/aeLhU=; b=4Y2Jc9qybqxj1BN+IUzYfhcxWRUEJXfvfW7Bferj8YkzGISDPGn6s2Dkx31tKwzROmPvRC 4YcpOCjIsFV75HfqdrAxqeYBXiNaVKnMA5MHux54WOUbSepVPLcoKj+Jd6IcsDcbG/GmJc t6spsB5YwRKQKbqDrxh6D/PgYgCjHH8= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=edAaJWcCrABKLfIwgirbbLTusm6buQxCBJP4h4SriQ77CqJ1IAlIkoPjiWMfshvr2PzitxjOb5ywpJMHKI37Z//CV63lYR9AD6+C9d7ZN+3Wlv0gbA2cdkmp2I5JwUe5RZXQrJiBory3ekkFSUk+u57Ha2m1CxynpDKTgF2W9NHT8YeHqHBIN6D717ytLXziX3rxYF1iABngd66k+wd28QrH0JnjgaszRhT3BuFP/VDLl++vy3DYe/x0pjks7IDs9hd/iQGdaNN1Gsd2X1deZKm+FvrMMCFZXKalUIFv9PBo/3BlpnTGPGMYvFVblbA1rFdlPdppMQXj/ckEeVqvBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=lyxFrc6Clfrofhrb3kvsAmejA25jBTP+9YIvp/aeLhU=; b=BBfNWL6kmlRBx2WedY60xNqRA0BpmpXlczND526vwkxgvJbBAbWM3Qn3LmI2sYEX2w7AAWIqZ5qQm9FZRdc7k7FBUU34hxWvlSRjyTIdQ2kG2Pqp/y70QoSE8QK6Su8cjuxcL9ObfMNevWdaO6r7cNtDj9/X8Yl/aEXPrsnBpvdPety31WCXKTvHNza7DlyhIb0eIk6YNcUu7aWhbN4M8QANMYRPqEuzsbhd7/Kw9MgnoyKohVnj9gBisOIdqChjiPbzYwuEq1cQbHHazQEpz2N5E6Ov6GL2o005Ch8esQ6LJWoKkKcMFvDoF8wQMtWxO/LiNx+k9NTsufxOpQi0Vg== 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=lyxFrc6Clfrofhrb3kvsAmejA25jBTP+9YIvp/aeLhU=; b=ZnWYkggFLTJW/LWEp6yQeFM+udpDyffnSHL5+PuALL0ajyaSc7CyrspafWpaPj/96QPOfN0wsd2NK6uhwaFJ87B9/wxMvIYfcJH5AbOnFBfsoAUAGjX9a/Hf+Hff9150tH/eYDqhzfoxyoE36pmBCXxdMktzpJeulbk0/747px1ctLVbd07FDPkiZnvEbd4YhdPy8A5dij203R4ChquxPSRr1+WGmngTGVLWgH1I3OiCdKx1qHCW+GtXCvxlnmetXZwu3JfInTjz83UDlYULjPYHr7tmEuWE5nUsFGTr2wxRiUMdbQiQGlbX3VJUxphnVcv4rT4SdZ2Ci1OA032pBQ== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by KL1PR06MB6520.apcprd06.prod.outlook.com (2603:1096:820:fd::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Tue, 30 Jul 2024 11:44:37 +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.7807.026; Tue, 30 Jul 2024 11:44:37 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Arnd Bergmann , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , linux-arch@vger.kernel.org, cgroups@vger.kernel.org, Barry Song <21cnbao@gmail.com>, Zhiguo Jiang Cc: opensource.kernel@vivo.com Subject: [PATCH 1/2] mm: move task_is_dying to h headfile Date: Tue, 30 Jul 2024 19:44:25 +0800 Message-ID: <20240730114426.511-2-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 In-Reply-To: <20240730114426.511-1-justinjiang@vivo.com> References: <20240730114426.511-1-justinjiang@vivo.com> X-ClientProxiedBy: SI2PR04CA0018.apcprd04.prod.outlook.com (2603:1096:4:197::9) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|KL1PR06MB6520:EE_ X-MS-Office365-Filtering-Correlation-Id: 8596e6d6-d95f-4374-ec8b-08dcb08cfd7d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|52116014|7416014|921020|38350700014; X-Microsoft-Antispam-Message-Info: VA6BcA0maItQ5r/HS8h836amASMLoL8nK3PeRP+S5d8rl2aPbALQ0mK2rXqAi9ekRAJniyjtXTwC/n2dSeVktI9URiQraDnlUCe3urHUAXRVhpVSeTzE2gVBbzGomtqnr4JR+OSggSthAadJnaSQFa2tSr+RnmTfmKdsZnBIVIxtGYOzMuU3PhLSKM7VjbNAgbwfpIEGQUL/AK7igpCktjvAGy7d6x/2qY5jrXYNw0EAH3n2waL0mj3XRO/qiPDooFFOCsyx6GFp0Fd8XOVEwxm6SJtQaR5cK7ttEXEMyaoe6enL/hZEOOv8AmV5lOzk81g/ZfhfNExeHJchmXVIqBtcsDLW1oEJ0YnEiO/JnZb7HEVLechOloX7F+SbSMmZX4W0Vstu826mzxRiNJW4HCS9dKfV4b++31j+fj0tNW4KjTMX358Nfq1CYZJm15GCjesWivs6wtcJOKTbrLld0m08vQZlx4jvkxuERlcAQd4w3OhONRNQekp/LXlohFU8UiaTWFMjX03tEunGdmlaQ4jDhaan91DWlrQ0RVptMiYjEXuKSuJei4s6eEhgEEKBdqn9B+i5MNEmvTpKKvpBKjmDVW/pCivBuOfojnywmukMi9f6GvK8TcjQfYf71SF+HKJScQhrdzSSts3S6Mc56dZ79GRl1GGhtHRT9EXvWxQ0p66VH5asepKDt9J1gCHatMENvoXBe8vcm/D0fIi5ekK1u8iuuATR54lkC6VOmKaPwSieWgIvXumvi4ktQApgsZsETUY6q8mjCzfkK9qrbkbfaL7iGBynMkkUU7j9suqK+KdiszmAlcephq2pT9W0Lr65V8avc7LM5pGIs8IrT8ccOI2GB0zVV6CPfIxmuILwj28sI/bGdT6FEQ9vUnhpu9u2xw6etEQki01AkTDqEJLEUtW3Vpt6tPVVaPF4McQeBE8NMvOU1SO2l8MyOk2f8yZnTZx7h71X0LOMx5SxJcaRe/NDMbFRO0DFnHWncLBEoI6G2+PpZhZ+hxZ/kNFNWDnZjMLSxk4EJ5kw90k+tRGJ5HrlniEY1Qa8Ag4Q7N9srT4b+1CZuw5nAhs7HtojywiKzvJwaczK5lyESNyB/4ZYiKYi0u+RWZWys5LOLqscy2hj5HNRFcffQDedqUYc4SmHMray5IjcvdK5wVsYXpJW8OSqGcAqTlryAtpREwlh4nsacsNciGM9mlxTm7QXeK0qTn07RAVSIHMMKtwweyAwWnwMbS48NA8WGCsn/T6XXnEFIPBYaTic50NxcjsgkW7eh5TdIXJU5EKIzBQQlYgRu2EUCtcTJr/2nM3o9RQJrm9BiwKN4dlrDa+6LpB1fjhNKgqcMayWsBcxzy7f1GaQym5Z2SB380ucrUAat3vhYPXBaWHGHjhwtVfBP3cRuwl6MycKw6CB/gHbiKoy+wQrvFPZbSQhBXLd5A/abIU= 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)(366016)(1800799024)(376014)(52116014)(7416014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: USQG8Z3b9uQ0Kku77tquSSEFhY02DqTRxVSzd+ua+ST4RY8ppTwpK9q5lRays/35GnmTjHNi++xrAz3KxemgN+fBj+oZD1afmmEA5fYuBbyd708tzh1C67QDCCplqmLykr99YLVeMjNOL5H6kcw09CGRfhau7YLwhGhUfziiAGn9Di/CnBr9/dJDrdj1sjb2vD8Rpc7dx7325VM+TPewjOnSgwkcU2qZIaIsHf9K8v4CfojrR/DyAHOBq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4cI9Jk5eyzQu8hdbND5bnTAGnVagirFnd6IgrhPhqOWCuRWsTDkOxZ904Iwl2dnATqD4pLMTP1m4JWOrwRolu4V3xHRLL++xGSjmsa6rdFcreA4w42hbKIquylhX7+gF6WMoKlKriIuJdoeQtjO+XMwXAgrtsZaNLoPniF5DErQ21GwzIGczRy0NJbsgv9gYxlhKgkBHeiTHcymSPIvgTeLfGvZ2NsbAdsgmCNV8HnMpIrX2VLEvJ0tNpuJiCPvd7fTRB/ychnPEuUkCA2sYU8Hu3 X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8596e6d6-d95f-4374-ec8b-08dcb08cfd7d X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2024 11:44:37.6413 (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: t26tSBp1kOJTxpiGj6S2X62+H6qZlfzfgAG/NOg3CYWbdHXZ+pFFPkBotmii1eiaYl0KEOL+r7ZyURHaMY+dPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6520 X-Rspamd-Queue-Id: 30981140004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: xnt1pz8binegi3mmpeiuop4mgsyfx3fy X-HE-Tag: 1722339972-33820 X-HE-Meta: U2FsdGVkX19+8URx8RaRCLyIlRKXQ009VFgvjw7bYYthKQfM+y3AZlsS2gBXHYK8uoVTi+4cdAygED58zJURdJd9mXKeoCBoC6LYYGYZMl6eaUrtlaqXOQ8jefZ/I0C8VOlV9xZDW/zjgpL2boRwUsFOzGrsn9uyRzSmhFVnSMcoN+FLq4n4xwoU1VVE2U2BaKfv+Om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0mSeGOvzOY5AtmMwYgLg66DvK4WyDwNn2gN6rseiK4bHjd46NRiWtWikINV 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: Move task_is_dying() to include/linux/oom.h so that it can be referenced elsewhere. Signed-off-by: Zhiguo Jiang --- include/linux/oom.h | 6 ++++++ mm/memcontrol.c | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/oom.h b/include/linux/oom.h index 7d0c9c48a0c5..a3a58463c0d5 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -77,6 +77,12 @@ static inline bool tsk_is_oom_victim(struct task_struct * tsk) return tsk->signal->oom_mm; } +static inline bool task_is_dying(void) +{ + return tsk_is_oom_victim(current) || fatal_signal_pending(current) || + (current->flags & PF_EXITING); +} + /* * Checks whether a page fault on the given mm is still reliable. * This is no longer true if the oom reaper started to reap the diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9b3ef3a70833..c54a8aea19b0 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -98,12 +98,6 @@ static DECLARE_WAIT_QUEUE_HEAD(memcg_cgwb_frn_waitq); #define THRESHOLDS_EVENTS_TARGET 128 #define SOFTLIMIT_EVENTS_TARGET 1024 -static inline bool task_is_dying(void) -{ - return tsk_is_oom_victim(current) || fatal_signal_pending(current) || - (current->flags & PF_EXITING); -} - /* Some nice accessors for the vmpressure. */ struct vmpressure *memcg_to_vmpressure(struct mem_cgroup *memcg) { From patchwork Tue Jul 30 11:44:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13747282 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 9E0CCC3DA7E for ; Tue, 30 Jul 2024 11:45:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26D746B0088; Tue, 30 Jul 2024 07:45:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 21D776B008C; Tue, 30 Jul 2024 07:45:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 070846B0092; Tue, 30 Jul 2024 07:45:01 -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 D96936B0088 for ; Tue, 30 Jul 2024 07:45:00 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 844FD140113 for ; Tue, 30 Jul 2024 11:45:00 +0000 (UTC) X-FDA: 82396237560.24.41DA65D Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2061.outbound.protection.outlook.com [40.107.117.61]) by imf15.hostedemail.com (Postfix) with ESMTP id 773C7A0003 for ; Tue, 30 Jul 2024 11:44:57 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=aoouA7mV; spf=pass (imf15.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.61 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722339825; 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:in-reply-to:references:references:dkim-signature; bh=w+yAbJV3p5E6MldL7D068KSuk5rJf9cNrO69LjY8gc0=; b=NuQagdS4PjNDuZ9rlo/sOUu4Ub8Kr7efqx2M4p38taIQk+6pHkUnDdpggC/yb38RCxJY7s r2ixeVp9sn/u1Ce2LmZmNyCIKPnivGOwdAQdS5C4OiceHTram5KxAqaZ5IXQauLd9yAqGH WDsr+1SGlYGcbw5JJ2p/yIGN7UQCWVc= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=aoouA7mV; spf=pass (imf15.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.61 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; dmarc=pass (policy=quarantine) header.from=vivo.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722339825; a=rsa-sha256; cv=pass; b=tzzU3yvthAIuqoutw5TsUHVDE2qnmYo1GcWElRvM4p8AdLqLPN1JSzhnuIc9Scsc0SVsNC ZUqzBB86UKHGrH2ZEKKN38P5Kr4WJ8mXKResKaiVmJXudzRQzyibwPmZzxCN1gjapW3Agk 7KIe5vUyGjowfQfPItGFY2n8VNmX3+Y= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c0DObm4R5A9T0kggyotd/FnNlji/MPhzTLCwEg0V5Sd/+qQznTWeoPtqcrmiO58Y4dMFA4S2JxMRB7TbnBVWkLCyTKo8kquspK3rwqBj4JPhzPFEbkEv6WJW6c8/sCs31dq8CmHV05EcBIQcNa52gf83d84RcaMyelL7l8TSInsDKyAQktPNEWPtj7NGwHVRdmSFTKE4olfrowpAT3EVPZfeIrqhrWh0P9ui96fJ07By/bn9n3p4nUjKrRSAFaY3Yqyia6sn0FanpbKILnA5rCKEgAB/igf+mwP7VjAo5LgpXIMn7REgpKBvMZxVfxLoFbW/sL6zJUsyr2FZXP0KWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=w+yAbJV3p5E6MldL7D068KSuk5rJf9cNrO69LjY8gc0=; b=HutI9+d/ePfwdyUx3pGP7/WN9ToHMS7NKvq7OqISVcxkaOeKgsj1WDbmKt8q2LSRLM2zJX6q8H1qJkyuI8aG1rGNoo+piEOk7eQKqBmyILXCMJLRfuZsr4AWAhXRYVUwrP36gdD6Dcll5ebOjhDzJbT9FKdA+F2E2N8vKn39SmMs0vMYb6WyDVXKkS69A915+HoKYJ/bhprIDUjpsTk2pSRdaDXm/jLOkgA9qfN9He9ZzlYisoiWW61SdfCxpwpiUSKpqPjtEkjPh6lgucufnCXGnIGh8kW4i22NjrT4PbO9xaVs+6vVNaSFcp69vxDNsQy3R8GCcsY5nf7uPL3UJQ== 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=w+yAbJV3p5E6MldL7D068KSuk5rJf9cNrO69LjY8gc0=; b=aoouA7mVgQxVfWHb0fnYHIfCq12lLw2qv3q12x0QENjoGMQsqQNZxKKlYz6moyCsIJrhhGYEAeRyxx8lfuwQJ4Z8WEO3smw59ZNT6iqRuZBT7vlWTndwZ+9CgB7zxCPVuMQ6hr3pP2oP+A/DYNhX1uXRUGPNf7lAwIFeNFDTy5rPdl13hZOQTbkv22SLrlnDCZriJXxMrrail/CHY9s0gJuwX/yRNNDm+JuJ/e9Fgb2MtTiuRvAbRrl8om8RtSG80Swgb+zL0ypW6l1cCqKW0rGdvUd80jexLA0x0yCOatv2i7rnxm/t0vk6uYjodS9P003TAx3PIj9xS2LUHXKo+Q== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by KL1PR06MB6520.apcprd06.prod.outlook.com (2603:1096:820:fd::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Tue, 30 Jul 2024 11:44:39 +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.7807.026; Tue, 30 Jul 2024 11:44:39 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Peter Zijlstra , Arnd Bergmann , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , linux-arch@vger.kernel.org, cgroups@vger.kernel.org, Barry Song <21cnbao@gmail.com>, Zhiguo Jiang Cc: opensource.kernel@vivo.com Subject: [PATCH 2/2] mm: tlb: add tlb swap entries batch async release Date: Tue, 30 Jul 2024 19:44:26 +0800 Message-ID: <20240730114426.511-3-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 In-Reply-To: <20240730114426.511-1-justinjiang@vivo.com> References: <20240730114426.511-1-justinjiang@vivo.com> X-ClientProxiedBy: SI2PR04CA0018.apcprd04.prod.outlook.com (2603:1096:4:197::9) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|KL1PR06MB6520:EE_ X-MS-Office365-Filtering-Correlation-Id: a2057c46-37ce-47f4-54ae-08dcb08cfe7b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024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R8W/dL8xpwnx1a3SLG05iEBCKrToHTehQdaLtSK/KGoX6AcNaCS3mb+urYSKOOSgeTusc56hVZJ7FkHYg4VWkYneea4A8wSKWcx2IQW6oAm9ipVhdXGaBDvoqC7OGJKDqiZohholFpCPL2SnlgfTZmw1fE8kxQAiiAjrdBvXaPZIQGkO0GRVs8W8i+hBV+HLehufKosp/q5M/yxryEwLz0+K7UcbmGrMot1TAD2Nzbq2U7uSPbsVJX51hWsbEXNiseimwfpBRwVfouCpaYTGpIH9LWe9nFXj2XPp1UFCT0j0DCr7fBDNmiPxCMXz7WTNEevd9lUdO/n1rWrCb1TfGi+JXccggB62I/YUON19mLW5hek5nizwI4v9VGen+/WZwiF/Dk+iYEOf/8DXnLpdwUaJPFtxuvosTqQ8= 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)(366016)(1800799024)(376014)(52116014)(7416014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BiKiRoeCiUsVJ3IPbYOWUQ49ghGOZmnLxJCGa9P3SY6x4LsdA5qkG+EUG3n/RlfYcpvHq17+6Qcj/b1sU3U0NKQE76UeB7ITsLDDE2IC82S1oLOODUoClnWdYxtH0zZ2DOkKCRWnz+RajE866IXGDaTtRlfN4uR1AoXJRuxoEdntrHOq/pxu0JCfc2iJMJnfLpvIHkY2wq0fMpF2j7crWRJH9lmq2awJdJMWpp9mbXhPcMYM3dDxDZkvhJc5+CWzBPMd1eS3knSj4vp69Dmlc48ohhavXmHcrp+dam0R+ln9FHgZFrDhM8sK/3gwRJ7Qm1mp16BECrzqozE9JQZjRuA5laMdpBNiq8W09rYVcDSrNCjS3SbVdVNP3SdDBVJmLYG+iBFThQRbKSu891nCdtJiXBAvKZE4HcPOhD0YR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7nQ54nJm8FZOSjfrnk1hIqoTcZIxCvd97/dxPwwGk0mHT5YjvhYqO75X/VZZHl7clAGi9DuxMtemK/qp7Tg43zcp7M X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2057c46-37ce-47f4-54ae-08dcb08cfe7b X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2024 11:44:39.3257 (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: mBVIig3OINasHb3fPfDVhF4wiPCoVKUKi9T1+TdwD/VZMImEhCdqPn30KeL7OOPCKJySj+iUUGbk9uUx1Jenow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6520 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 773C7A0003 X-Stat-Signature: mpn4wnkty4amd1c9weze5ap16szgwtne X-Rspam-User: X-HE-Tag: 1722339897-651816 X-HE-Meta: U2FsdGVkX1+ArjbfQRulCgsqTxpdKyx/f/U+Sp9Srsm6crEtjJR78G0Og+8drqEP7duza6EKHD4+JHara1TXDvGAjpO4sdM8e3o3/5qASB5euK3MShftt03B5ORTMrKSUH/pz3b1ILgX9qHGgf3jLG1tkWhv/dcjoKRVnYaN8c+8hGRfK+cu48/3LQ+EWbyB92QaseG6HzoEInbO+oiosroPJEBHq3V+3miQb5fC9tfIjhrAO2fYe7uHv5yn8Q5C8OazGgpZmWKEtM80bcnigfXEl7GFNDOwCxMdYpQLN/3DzBCmaxJCYtjkXQs5X7KywBZwIYDAKsmg6PBiAFjv2E6t/zBqOfWBdLExKE4MP1hrs3qVcvPxCZlmpzAtipiusZnqJyU2z5nT3IhNjWWR5xWnDESixY4lzo6d0MiH1V+b4dC3gSSwysJwbuFXj/RQjVl9TS0ADXOoCPvsb/P1iCqdq5jUqJ3F5Jt5j9v8buv7nXJeg3mn9n6ekULwRUt9q9Vu0Suv1/TmjrNvdb45JOThIL9I9lCQIy+coLwtqJYYTZdt54FDf1d6zZKL2ghUrF/TgoRKRSEOimW3/q6zqU2vqJ/HmqtwaFPnxMhcKVoF3DLn0K7mz/0wUg5NJJylO9rK88Fuu6+4w+77fnGDuA9tgXzfM8MDA5cPiBt27cYrtMTMk6mrAqzIjHKZrTixObhRvUMviGpqHqa+B3ISiLOwvzPxUsDQIhySIucGLrphjs4wX0kjk+ub9bJizbVlAUWII7hyMfqW80scfmdQV0grSgEYKvF8ZXGhTbBoL34xK+z6vX3PM/XQtb7o3ggsKlhFhoh+lYF8sNvAyM5YDmNE6xEUH38Ga/Yj80H7mVKqzD+0sLVUGD8QoCSkvYol3e+NTFaXMDa0eGek7w40Y3TW5TsTXqQgl6lZPIpzbH7es7cwj/TnJTp8fybKRSihfD6/+Fv0mwJ9XOdcjpx i/HY4w/n xtt85KYTAFA1udVZry16ehGxNH3x13Tw1D3ZEtCMA0cvdstkfjC8YdflzrLegw8zRkPc9W5i5BRwqBg6GtyqCLng0LpjY6kY2M+WDjf8d7cSpMXBo8aZ3LU7bnL+pZjDY5qz+izXNCWU/U9Njky+b+GuH4JgEvO3DGU98AifV63oEk9ptHxJLFKtBpRQzb23rUF2YFuIFz1tTzrkh82HbkjXUDOd6vK73dXtohn1X1Tmmu13CPiR8XY6JhE2kd7CPi8c17WV+giSamXhgl8TuHSF+8ekTTnq5eRfgEp+FDaTBPes= 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 main reasons for the prolonged exit of a background process is the time-consuming release of its swap entries. The proportion of swap memory occupied by the background process increases with its duration in the background, and after a period of time, this value can reach 60% or more. Additionally, the relatively lengthy path for releasing swap entries further contributes to the longer time required for the background process to release its swap entries. In the multiple background applications scenario, when launching a large memory application such as a camera, system may enter a low memory state, which will triggers the killing of multiple background processes at the same time. Due to multiple exiting processes occupying multiple CPUs for concurrent execution, the current foreground application's CPU resources are tight and may cause issues such as lagging. To solve this problem, we have introduced the multiple exiting process asynchronous swap memory release mechanism, which isolates and caches swap entries occupied by multiple exit processes, and hands them over to an asynchronous kworker to complete the release. This allows the exiting processes to complete quickly and release CPU resources. We have validated this modification on the products and achieved the expected benefits. It offers several benefits: 1. Alleviate the high system cpu load caused by multiple exiting processes running simultaneously. 2. Reduce lock competition in swap entry free path by an asynchronous kworker instead of multiple exiting processes parallel execution. 3. Release memory occupied by exiting processes more efficiently. Signed-off-by: Zhiguo Jiang --- include/asm-generic/tlb.h | 50 +++++++ include/linux/mm_types.h | 58 ++++++++ mm/memory.c | 3 +- mm/mmu_gather.c | 297 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 407 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 709830274b75..aab43f1cf97f --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -294,6 +294,43 @@ extern void tlb_flush_rmaps(struct mmu_gather *tlb, struct vm_area_struct *vma); static inline void tlb_flush_rmaps(struct mmu_gather *tlb, struct vm_area_struct *vma) { } #endif +#ifndef CONFIG_MMU_GATHER_NO_GATHER +struct mmu_swap_batch { + struct mmu_swap_batch *next; + unsigned int nr; + unsigned int max; + encoded_swpentry_t encoded_entrys[]; +}; + +#define MAX_SWAP_GATHER_BATCH \ + ((PAGE_SIZE - sizeof(struct mmu_swap_batch)) / sizeof(void *)) + +#define MAX_SWAP_GATHER_BATCH_COUNT (10000UL / MAX_SWAP_GATHER_BATCH) + +struct mmu_swap_gather { + /* + * the asynchronous kworker to batch + * release swap entries + */ + struct work_struct free_work; + + /* batch cache swap entries */ + unsigned int batch_count; + struct mmu_swap_batch *active; + struct mmu_swap_batch local; + encoded_swpentry_t __encoded_entrys[MMU_GATHER_BUNDLE]; +}; + +extern bool __tlb_remove_swap_entries(struct mmu_gather *tlb, + swp_entry_t entry, int nr); +#else +bool __tlb_remove_swap_entries(struct mmu_gather *tlb, + swp_entry_t entry, int nr) +{ + return false; +} +#endif + /* * struct mmu_gather is an opaque type used by the mm code for passing around * any data needed by arch specific code for tlb_remove_page. @@ -343,6 +380,18 @@ struct mmu_gather { unsigned int vma_exec : 1; unsigned int vma_huge : 1; unsigned int vma_pfn : 1; +#ifndef CONFIG_MMU_GATHER_NO_GATHER + /* + * Two states of releasing swap entries + * asynchronously: + * swp_freeable - have opportunity to + * release asynchronously future + * swp_freeing - be releasing asynchronously. + */ + unsigned int swp_freeable : 1; + unsigned int swp_freeing : 1; + unsigned int swp_disable : 1; +#endif unsigned int batch_count; @@ -354,6 +403,7 @@ struct mmu_gather { #ifdef CONFIG_MMU_GATHER_PAGE_SIZE unsigned int page_size; #endif + struct mmu_swap_gather *swp; #endif }; diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 485424979254..f26fbff93ff4 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -283,6 +283,64 @@ typedef struct { unsigned long val; } swp_entry_t; +/* + * encoded_swpentry_t - a type marking the encoded swp_entry_t. + * + * An 'encoded_swpentry_t' represents a 'swp_enrty_t' with its the highest + * bit indicating extra context-dependent information. Only used in swp_entry + * asynchronous release path by mmu_swap_gather. + */ +typedef struct { + unsigned long val; +} encoded_swpentry_t; + +/* + * The next item in an encoded_swpentry_t array is the "nr" argument, specifying the + * total number of consecutive swap entries associated with the same folio. If this + * bit is not set, "nr" is implicitly 1. + * + * Refer to include\asm\pgtable.h, swp_offset bits: 0 ~ 57, swp_type bits: 58 ~ 62. + * Bit63 can be used here. + */ +#define ENCODED_SWPENTRY_BIT_NR_ENTRYS_NEXT (1UL << (BITS_PER_LONG - 1)) + +static __always_inline encoded_swpentry_t +encode_swpentry(swp_entry_t entry, unsigned long flags) +{ + encoded_swpentry_t ret; + + VM_WARN_ON_ONCE(flags & ~ENCODED_SWPENTRY_BIT_NR_ENTRYS_NEXT); + ret.val = flags | entry.val; + return ret; +} + +static inline unsigned long encoded_swpentry_flags(encoded_swpentry_t entry) +{ + return ENCODED_SWPENTRY_BIT_NR_ENTRYS_NEXT & entry.val; +} + +static inline swp_entry_t encoded_swpentry_data(encoded_swpentry_t entry) +{ + swp_entry_t ret; + + ret.val = ~ENCODED_SWPENTRY_BIT_NR_ENTRYS_NEXT & entry.val; + return ret; +} + +static __always_inline encoded_swpentry_t encode_nr_swpentrys(unsigned long nr) +{ + encoded_swpentry_t ret; + + VM_WARN_ON_ONCE(nr & ENCODED_SWPENTRY_BIT_NR_ENTRYS_NEXT); + ret.val = nr; + return ret; +} + +static __always_inline unsigned long encoded_nr_swpentrys(encoded_swpentry_t entry) +{ + return ((~ENCODED_SWPENTRY_BIT_NR_ENTRYS_NEXT) & entry.val); +} + /** * struct folio - Represents a contiguous set of bytes. * @flags: Identical to the page flags. diff --git a/mm/memory.c b/mm/memory.c index b9f5cc0db3eb..bfa1995558d2 --- a/mm/memory.c +++ b/mm/memory.c @@ -1650,7 +1650,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (!should_zap_cows(details)) continue; rss[MM_SWAPENTS] -= nr; - free_swap_and_cache_nr(entry, nr); + if (!__tlb_remove_swap_entries(tlb, entry, nr)) + free_swap_and_cache_nr(entry, nr); } else if (is_migration_entry(entry)) { folio = pfn_swap_entry_folio(entry); if (!should_zap_folio(details, folio)) diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index 99b3e9408aa0..2bb413d052bd --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -9,11 +9,304 @@ #include #include #include +#include #include #include #ifndef CONFIG_MMU_GATHER_NO_GATHER +/* + * The swp_entry asynchronous release mechanism for multiple processes exiting + * simultaneously. + * + * During the multiple exiting processes releasing their own mm simultaneously, + * the swap entries in the exiting processes are handled by isolating, caching + * and handing over to an asynchronous kworker to complete the release. + * + * The conditions for the exiting process entering the swp_entry asynchronous + * release path: + * 1. The exiting process's MM_SWAPENTS count is >= SWAP_CLUSTER_MAX, avoiding + * to alloc struct mmu_swap_gather frequently. + * 2. The number of exiting processes is >= NR_MIN_EXITING_PROCESSES. + * + * Since the time for determining the number of exiting processes is dynamic, + * the exiting process may start to enter the swp_entry asynchronous release + * at the beginning or middle stage of the exiting process's swp_entry release + * path. + * + * Once an exiting process enters the swp_entry asynchronous release, all remaining + * swap entries in this exiting process need to be fully released by asynchronous + * kworker theoretically. + * + * The function of the swp_entry asynchronous release: + * 1. Alleviate the high system cpu load caused by multiple exiting processes + * running simultaneously. + * 2. Reduce lock competition in swap entry free path by an asynchronous kworker + * instead of multiple exiting processes parallel execution. + * 3. Release memory occupied by exiting processes more efficiently. + */ + +/* + * The min number of exiting processes required for swp_entry asynchronous release + */ +#define NR_MIN_EXITING_PROCESSES 2 + +atomic_t nr_exiting_processes = ATOMIC_INIT(0); +static struct kmem_cache *swap_gather_cachep; +static struct workqueue_struct *swapfree_wq; +static DEFINE_STATIC_KEY_TRUE(tlb_swap_asyncfree_disabled); + +static int __init tlb_swap_async_free_setup(void) +{ + swapfree_wq = alloc_workqueue("smfree_wq", WQ_UNBOUND | + WQ_HIGHPRI | WQ_MEM_RECLAIM, 1); + if (!swapfree_wq) + goto fail; + + swap_gather_cachep = kmem_cache_create("swap_gather", + sizeof(struct mmu_swap_gather), + 0, SLAB_TYPESAFE_BY_RCU | SLAB_PANIC | SLAB_ACCOUNT, + NULL); + if (!swap_gather_cachep) + goto kcache_fail; + + static_branch_disable(&tlb_swap_asyncfree_disabled); + return 0; + +kcache_fail: + destroy_workqueue(swapfree_wq); +fail: + return -ENOMEM; +} +postcore_initcall(tlb_swap_async_free_setup); + +static void __tlb_swap_gather_free(struct mmu_swap_gather *swap_gather) +{ + struct mmu_swap_batch *swap_batch, *next; + + for (swap_batch = swap_gather->local.next; swap_batch; swap_batch = next) { + next = swap_batch->next; + free_page((unsigned long)swap_batch); + } + swap_gather->local.next = NULL; + kmem_cache_free(swap_gather_cachep, swap_gather); +} + +static void tlb_swap_async_free_work(struct work_struct *w) +{ + int i, nr_multi, nr_free; + swp_entry_t start_entry; + struct mmu_swap_batch *swap_batch; + struct mmu_swap_gather *swap_gather = container_of(w, + struct mmu_swap_gather, free_work); + + /* Release swap entries cached in mmu_swap_batch. */ + for (swap_batch = &swap_gather->local; swap_batch && swap_batch->nr; + swap_batch = swap_batch->next) { + nr_free = 0; + for (i = 0; i < swap_batch->nr; i++) { + if (unlikely(encoded_swpentry_flags(swap_batch->encoded_entrys[i]) & + ENCODED_SWPENTRY_BIT_NR_ENTRYS_NEXT)) { + start_entry = encoded_swpentry_data(swap_batch->encoded_entrys[i]); + nr_multi = encoded_nr_swpentrys(swap_batch->encoded_entrys[++i]); + free_swap_and_cache_nr(start_entry, nr_multi); + nr_free += 2; + } else { + start_entry = encoded_swpentry_data(swap_batch->encoded_entrys[i]); + free_swap_and_cache_nr(start_entry, 1); + nr_free++; + } + } + swap_batch->nr -= nr_free; + WARN_ON_ONCE(swap_batch->nr); + } + __tlb_swap_gather_free(swap_gather); +} + +static bool __tlb_swap_gather_mmu_check(struct mmu_gather *tlb) +{ + /* + * Only the exiting processes with the MM_SWAPENTS counter >= + * SWAP_CLUSTER_MAX have the opportunity to release their swap + * entries by asynchronous kworker. + */ + if (!task_is_dying() || + get_mm_counter(tlb->mm, MM_SWAPENTS) < SWAP_CLUSTER_MAX) + return true; + + atomic_inc(&nr_exiting_processes); + if (atomic_read(&nr_exiting_processes) < NR_MIN_EXITING_PROCESSES) + tlb->swp_freeable = 1; + else + tlb->swp_freeing = 1; + + return false; +} + +/** + * __tlb_swap_gather_init - Initialize an mmu_swap_gather structure + * for swp_entry tear-down. + * @tlb: the mmu_swap_gather structure belongs to tlb + */ +static bool __tlb_swap_gather_init(struct mmu_gather *tlb) +{ + tlb->swp = kmem_cache_alloc(swap_gather_cachep, GFP_ATOMIC | GFP_NOWAIT); + if (unlikely(!tlb->swp)) + return false; + + tlb->swp->local.next = NULL; + tlb->swp->local.nr = 0; + tlb->swp->local.max = ARRAY_SIZE(tlb->swp->__encoded_entrys); + + tlb->swp->active = &tlb->swp->local; + tlb->swp->batch_count = 0; + + INIT_WORK(&tlb->swp->free_work, tlb_swap_async_free_work); + return true; +} + +static void __tlb_swap_gather_mmu(struct mmu_gather *tlb) +{ + if (static_branch_unlikely(&tlb_swap_asyncfree_disabled)) + return; + + tlb->swp = NULL; + tlb->swp_freeable = 0; + tlb->swp_freeing = 0; + tlb->swp_disable = 0; + + if (__tlb_swap_gather_mmu_check(tlb)) + return; + + /* + * If the exiting process meets the conditions of + * swp_entry asynchronous release, an mmu_swap_gather + * structure will be initialized. + */ + if (tlb->swp_freeing) + __tlb_swap_gather_init(tlb); +} + +static void __tlb_swap_gather_queuework(struct mmu_gather *tlb, bool finish) +{ + queue_work(swapfree_wq, &tlb->swp->free_work); + tlb->swp = NULL; + if (!finish) + __tlb_swap_gather_init(tlb); +} + +static bool __tlb_swap_next_batch(struct mmu_gather *tlb) +{ + struct mmu_swap_batch *swap_batch; + + if (tlb->swp->batch_count == MAX_SWAP_GATHER_BATCH_COUNT) + goto free; + + swap_batch = (void *)__get_free_page(GFP_ATOMIC | GFP_NOWAIT); + if (unlikely(!swap_batch)) + goto free; + + swap_batch->next = NULL; + swap_batch->nr = 0; + swap_batch->max = MAX_SWAP_GATHER_BATCH; + + tlb->swp->active->next = swap_batch; + tlb->swp->active = swap_batch; + tlb->swp->batch_count++; + return true; +free: + /* batch move to wq */ + __tlb_swap_gather_queuework(tlb, false); + return false; +} + +/** + * __tlb_remove_swap_entries - the swap entries in exiting process are + * isolated, batch cached in struct mmu_swap_batch. + * @tlb: the current mmu_gather + * @entry: swp_entry to be isolated and cached + * @nr: the number of consecutive entries starting from entry parameter. + */ +bool __tlb_remove_swap_entries(struct mmu_gather *tlb, + swp_entry_t entry, int nr) +{ + struct mmu_swap_batch *swap_batch; + unsigned long flags = 0; + bool ret = false; + + if (tlb->swp_disable) + return ret; + + if (!tlb->swp_freeable && !tlb->swp_freeing) + return ret; + + + if (tlb->swp_freeable) { + if (atomic_read(&nr_exiting_processes) < + NR_MIN_EXITING_PROCESSES) + return ret; + /* + * If the current number of exiting processes + * is >= NR_MIN_EXITING_PROCESSES, the exiting + * process with swp_freeable state will enter + * swp_freeing state to start releasing its + * remaining swap entries by the asynchronous + * kworker. + */ + tlb->swp_freeable = 0; + tlb->swp_freeing = 1; + } + + VM_BUG_ON(tlb->swp_freeable || !tlb->swp_freeing); + if (!tlb->swp && !__tlb_swap_gather_init(tlb)) + return ret; + + swap_batch = tlb->swp->active; + if (unlikely(swap_batch->nr >= swap_batch->max - 1)) { + __tlb_swap_gather_queuework(tlb, false); + return ret; + } + + if (likely(nr == 1)) { + swap_batch->encoded_entrys[swap_batch->nr++] = encode_swpentry(entry, flags); + } else { + flags |= ENCODED_SWPENTRY_BIT_NR_ENTRYS_NEXT; + swap_batch->encoded_entrys[swap_batch->nr++] = encode_swpentry(entry, flags); + swap_batch->encoded_entrys[swap_batch->nr++] = encode_nr_swpentrys(nr); + } + ret = true; + + if (swap_batch->nr >= swap_batch->max - 1) { + if (!__tlb_swap_next_batch(tlb)) + goto exit; + swap_batch = tlb->swp->active; + } + VM_BUG_ON(swap_batch->nr > swap_batch->max - 1); +exit: + return ret; +} + +static void __tlb_batch_swap_finish(struct mmu_gather *tlb) +{ + if (tlb->swp_disable) + return; + + if (!tlb->swp_freeable && !tlb->swp_freeing) + return; + + if (tlb->swp_freeable) { + tlb->swp_freeable = 0; + VM_BUG_ON(tlb->swp_freeing); + goto exit; + } + tlb->swp_freeing = 0; + if (unlikely(!tlb->swp)) + goto exit; + + __tlb_swap_gather_queuework(tlb, true); +exit: + atomic_dec(&nr_exiting_processes); +} static bool tlb_next_batch(struct mmu_gather *tlb) { @@ -386,6 +679,9 @@ static void __tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, tlb->local.max = ARRAY_SIZE(tlb->__pages); tlb->active = &tlb->local; tlb->batch_count = 0; + + tlb->swp_disable = 1; + __tlb_swap_gather_mmu(tlb); #endif tlb->delayed_rmap = 0; @@ -466,6 +762,7 @@ void tlb_finish_mmu(struct mmu_gather *tlb) #ifndef CONFIG_MMU_GATHER_NO_GATHER tlb_batch_list_free(tlb); + __tlb_batch_swap_finish(tlb); #endif dec_tlb_flush_pending(tlb->mm); }