From patchwork Tue Aug 6 07:23:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13754502 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 E16CBC52D70 for ; Tue, 6 Aug 2024 07:23:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5AD4C6B0083; Tue, 6 Aug 2024 03:23:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 535636B0085; Tue, 6 Aug 2024 03:23:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 387596B0088; Tue, 6 Aug 2024 03:23:46 -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 129B46B0083 for ; Tue, 6 Aug 2024 03:23:46 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 75151808B2 for ; Tue, 6 Aug 2024 07:23:45 +0000 (UTC) X-FDA: 82420980810.12.1CAF621 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2048.outbound.protection.outlook.com [40.107.215.48]) by imf17.hostedemail.com (Postfix) with ESMTP id C81C540013 for ; Tue, 6 Aug 2024 07:23:41 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=JWUJtmZo; spf=pass (imf17.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.215.48 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector10001: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=1722929014; h=from:from:sender:reply-to: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=XPAtVh+87FEkBZsyHwMX7y23Ie8ZMoolgjqjI6LsJyg=; b=yTBVXe8QY1vMYcN/jRfokyNu0EKjIbwVhUNyTX1D7ppErsXE4ASIFvI+VudphTGifnFWOH Nq/dxtq24UrQzicw8TC+vEdBy+eUk+MJvg+sNIq/mTQGToYka5k86xdqwV88k+e00k/7mN G7wMc0kJSFJAWkbN5Xq+PZp9FYazt+0= ARC-Authentication-Results: i=2; imf17.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=JWUJtmZo; spf=pass (imf17.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.215.48 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722929015; a=rsa-sha256; cv=pass; b=L7kleIi46C7XFuRC8qpfz72c8qJzXgzr4mBOian97p7UrCjqXPyjniGWNW4BerEiUKfKgq Md3Br/6MfqrdRxTIke69nkWnuh6eWlgWRr+IuBp+f8coaE2Fi+DxJnWy68kwo2Yy+21mto HVBdER3X3axuHuY0gFeMT12f3wRlFuc= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iOq4QHE5ntCKHl7hPydoZUnxYY4t6qdPRI6jg4aL4wRsH3c7xSxFWT7Wa2mbtKj3GcHpJlPPZBzOLJcQun02ujLNC9yyo/gJqypLzRIaZDrZXLfQ5Ge2BapYIPB4MAUg+ZUgLuIjvp/yqxopRI3+j6F9VWMlEKlIIGeFU8+QMQd7zmor6GqajV4nuzbKZqh4UQXm7DQVnow56bdCQSo7XMUrGUdHg/RzXqnGDJw9ZwMVMWAijQ2/uWpNyWebmo/ALMq1bC2+uVllSceUxsmwPAcbal89ghv20OkR8Zb20XIQTyimbLoCAHnYmUliKhvXtHfY3gRZMP5CB/XyOydzaw== 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=XPAtVh+87FEkBZsyHwMX7y23Ie8ZMoolgjqjI6LsJyg=; b=MBeRowo/OpBYyG8yx4yJUs6BzpoAKWn9hJm3AQ1m4UJZ968NXXE/tz0kexXUhj9Psu5yFE0fmJBE1msfqUd8KrnX8PV+tpK9xKishp9jKULi492vZYZbKZ4oiqO+djlT4e9fUzfROoyvn4m/X+Y+waC8r3EgQAr01PBphpqedtwSW/ZV5Qws1u7OkVD+CfYwhtDASKxUXP+rW08KGHg5/JQ2BcWAq5BVbLKnHHSQLtbQm9h3Xfo5BE+39XC4tXBl8SbkdAWDGIw4sbbGMdvg54iDtKAcV9WrBUtjbABNOU0p7I9bFkDthm3liHlOFEor9exz7J3W77LIpSzw5bQqCw== 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=XPAtVh+87FEkBZsyHwMX7y23Ie8ZMoolgjqjI6LsJyg=; b=JWUJtmZoaJO6wxsN0YwzfaSdQ4YWb5scvf9okVNlAfCfFXlfaaX2UoiodMRqZpDGNDgBQcZTAgDlFH7viq/LIqdvZpEVNLZNvBxjcrSq48JOaoG/3tdQU47xLpOvyn37ggZb+aWD8NhUHwk8k/XccTK3qt00dECO36p/geUWJlsbbzwH5ZAzMyzM32/Vj18JPIavKIvrg55N9D03Ui5L3f5wRI+KdXQx1gVbpB/MSsKMmWs7tc+C9oXxu76ZS6YVSVecoCuU8jYehajq5tCT7dA+EO7aaRLUfrgoH9D028MBsP1X4dBc5f8yPRM8/6N0CBCmffejuwGzdVhvZEHWgQ== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by SI6PR06MB7113.apcprd06.prod.outlook.com (2603:1096:4:247::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.25; Tue, 6 Aug 2024 07:23:33 +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.7828.023; Tue, 6 Aug 2024 07:23:32 +0000 Message-ID: Date: Tue, 6 Aug 2024 15:23:26 +0800 User-Agent: Mozilla Thunderbird To: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Barry Song , Kairui Song , Chris Li , "Huang, Ying" , Hugh Dickins , Kalesh Singh , Ryan Roberts , David Hildenbrand Reply-To: 20240806012409.61962-1-21cnbao@gmail.com From: zhiguojiang Subject: [PATCH] mm: attempt to batch free swap entries for zap_pte_range() X-ClientProxiedBy: TYAPR01CA0222.jpnprd01.prod.outlook.com (2603:1096:404:11e::18) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|SI6PR06MB7113:EE_ X-MS-Office365-Filtering-Correlation-Id: 5501ad13-1e20-4868-2c26-08dcb5e8ad76 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|43062017; X-Microsoft-Antispam-Message-Info: =?utf-8?q?pUk8kp2ZGaMTKt+K93HS5Y9WnKLcBrw?= =?utf-8?q?OvAGm0C/ZP+uR3ZjI+zkJT7pDZpg057q8O40+Mg3aJwdilJgyyWM8D6miAvlsznT1?= =?utf-8?q?CNpWG+CbXea6ro1ahEs3szOE04AcFSCij2liv0PhaFt2HdCgSGGc5cSPcTncNzry9?= =?utf-8?q?SYY2trMlo6XkXtih9P6c30q3Tmv30hvxOZeFfV6czRrtSZYXrqTXHZ1Dr1g1Nl027?= =?utf-8?q?zjo4y04ZNTnRhxkoRugqP+JGI3RvoMlvspM6R+Y9FCqCGjslJfkDGFSRluqhNdLgn?= =?utf-8?q?qf3N5LIJphn/sauqvhbGbEaLl/HL0UMNjc31wePjeYL3rS9s8IMRZco/YiqwJtifD?= =?utf-8?q?mInLDv7dHBkaDxwe1hUMpWZSsk/GjbSYQfYHVVUKMaSsVYgw+hHRSle32BG50EvFD?= =?utf-8?q?3tmmi2WkQJuPcDToSIKfCSnCYSZxBsMajt0DQxQF846n0ojvSXS4oPqdPILbq6iDV?= =?utf-8?q?/9yXRkbMAaFVVMOZ0nmA6oRzwZG+V0uxbNjWqLCoLD8tZL5Ages8FMg8CgIfYRU9L?= =?utf-8?q?tMuzoeGaqfC7H9lTzsRu3sksnxQrJVVM/tqX1cdGvWmLeq69qD4sdhw5EZ7OyKhVb?= =?utf-8?q?0f2VTA/ieFTpheOrhI+rF5DdCIMJ/x7mrGF6nl7mR0249g0zyoZ5lC52EgCd01cKE?= =?utf-8?q?B2fu7xV7yovqEkuVsxi2nmZ7xF6PLUSM5zJnGVH8zmFx5RjOC7gFRF637278Jy2zl?= =?utf-8?q?D86qJt8dk8SyUhXhifJ95bku9p1VBDA0o8cd33Xt1M4meDCQ9XpKKYt6omZ4QW6h7?= =?utf-8?q?ROtlJpyPPP56llHd6b3WLFY8gDkBoj/T0k/5HXjUwhhVyNr4bWE6Tl9rl/5Bo57+r?= =?utf-8?q?0dgglHbMH/1XMeF99PHcXt8PZuZqkfPDlnL50kduGk2FPQ4yao0GDqTRSm+IDyXM+?= =?utf-8?q?E++ZQO/J+z07FlMUmrafZBb8MWFsDdjM/jjHK2kBv4nJm3LGTTvQlo41DVrrq83mO?= =?utf-8?q?yU79Fsg9N8SB3sDCCYLKaOXHPICv14q11qHwKgzWj2rW1gKXz+dVUArFuEwk9UK75?= =?utf-8?q?U/RFjbCb82Pyq849nEbv8nwRXRfbhQMSQSEz+tmYPPFkVk8WhAgEQ1e4D5VON+s4z?= =?utf-8?q?hmGMZWa/pgm/TvYyLJ9LIevegx6nxXJ0pHrtWImiKiUkGA3haDcS4gbu2fTknmxv6?= =?utf-8?q?Ac5OvvTotpMpAbPHE/S5WuFEEAasrh/yBgNXLuH822hZCwCLUqBa25mv0kg1r3ETe?= =?utf-8?q?I37oUoQh5Kv6oBrrhgKo9vxwzTLxPgW+RAiXmpJTb/t5KLqGKeb/hOz9q2OwbI7+J?= =?utf-8?q?xy4eRVcX05dv2ltsc4sjXg/UlHVl7eIry2Q=3D=3D?= 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)(7416014)(43062017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?4R3TzIKm1SWd4bCKc/Ve0dzsSfkS?= =?utf-8?q?yGuNoH5AlhZdAmPnl7C9WJcHrVTCNH2PBjcPOhABHS4hXkI96O4XjS6AzikVSIa1x?= =?utf-8?q?WDReZCQuDqBFELeoFCICRDFk9195/fgg6D8oOcRvJF3dxqMRF5in2HpoFAeS5pZ3q?= =?utf-8?q?XipbpyYDRZz5uVcG1VPNkkzf8kPnwo+P886dtMuQT6NB2qf/+nkO9lTpfHJtbLQg6?= =?utf-8?q?MEjNCkKiHl5ZPF7hFdxKchQ4f+14mdfFFQgdvwS4dHqmKSRpw/96dlbmURVyZId4m?= =?utf-8?q?ZUiVDEVSuRidhey0xlfyYuE4ljDiUBwZFco23ZJdTlaYRCSojsquSjXQZdhDHCxLM?= =?utf-8?q?1PVLceeV00LVg3J91Tof4mJWRYlkMFI04iZfhBCZ+EakkUFsAUPSSAksTpHWX7HtT?= =?utf-8?q?6a5gqseW7DDSJ86+iDU42H6sdpFEYv4jvYlpwiGTpo8kJY+I0NmXPjFWP/arECawq?= =?utf-8?q?G3sAlEHq0Eq5lHBpQA7KVT2PRNHbeRHo6V1mgoA8TbFCPgp0Yyc+HM6zgMVriuH/G?= =?utf-8?q?fwQfq8B670YkuclusKH6oRIb72O9Ltkx9lfAucu4G8ZBOUN05xoUrjIj/GCHPB+a/?= =?utf-8?q?sbOsrxRqJvE4piZgPzZUIjp8MfYA89XmImrS8Yr7WsYpq6LzjplZ9REtJ9ahJk3iM?= =?utf-8?q?BvB/WqZZOASEWpW8Pvn8UPWaST4xDyw+9KVYY2+lcuELKUlCkUe/YvI3rX7+BSVis?= =?utf-8?q?0PyOKUphfMzED6HY+f+y7Cekn9CB087PK2pEwqAgsZ5ri5Wg7kk9zTIUyLqaZNDfn?= =?utf-8?q?xO8VrRbysE8IqwzsJgG6+5R3wpawFw6fnM379IlxsIB9Ni46Tjw0u0oLl5SHAsoc+?= =?utf-8?q?k55aq3jabS3Yp0fDIdYU8uJ7y2r+Rbth/dy9PzeCmOEjrm/zFjeZW0YVKXfFeao6k?= =?utf-8?q?xFZ4es9tDq0azGhd/aJ9nM/N/DPTpt6wsiNBtD2UrTZTULWMpsx1e4W5+wDyvjfON?= =?utf-8?q?HbrpMOoNItXoG6dZxEN7OJMTBoY8SZbuJO9yzxh08E6dQoTEyOCLRN6hl2NfgmEl7?= =?utf-8?q?pPzR6dAmDDAm1lAGTOPv9xJ+KUkVnuYCEE77iXqsxgc2Zyl3DNgy6sNUrVTYK+UlR?= =?utf-8?q?yViWslKCmQT4jqUfdKez8aVAz7VilUC/6eXjAqNeVIXxE+nd546avlT3W55XKjcI+?= =?utf-8?q?Ox2GPs47q8T9OvfRex8TqF3vXcQBC83F4WdltLtLc3ZMYW2NICe0uT2WEqy82mx3D?= =?utf-8?q?Y32qoB1SoAyvoWDiN2ap8Ofh4UcXsFaJY3/688rChaaW1hc6kivV6xrbKgNXAXjFi?= =?utf-8?q?/ZjQX97i8fS+Rbe9d6ySF8/N9jl8vFjT3DaPUj5zPGmoNRFQnme1wqrVLDT4a+zdM?= =?utf-8?q?06KnWsGeGfvGFWR2ZQ7T+KkhkEU7sWYhTPJryFOrIzv6+peno06JzYKTViSGKfz3L?= =?utf-8?q?4SLRmOnpBjozTsiZZb7saIy5uKU6U48ce7R3AQqWc5ul8+mEwrjRy/7hWgcJNxO1T?= =?utf-8?q?kRkphaBx5lOeIcF+jCAcfI4ud+ftkcmHwuNIvK35xPqxd8DPxx8WgO8zUtGj7lAR1?= =?utf-8?q?qUe3KjbT/EVl?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5501ad13-1e20-4868-2c26-08dcb5e8ad76 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Aug 2024 07:23:32.8799 (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: pR6m0YMxtJH4xXYF3RlWI9s5Bl+HQyy5lpFYALq+kGd0ZUCGqOpqNd8iv0+VIK34tA1HhMd6m6TVmEJ96INANA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI6PR06MB7113 X-Rspam-User: X-Stat-Signature: 9fbjk4z6nguyp65bafzf9ozae6fswgxs X-Rspamd-Queue-Id: C81C540013 X-Rspamd-Server: rspam11 X-HE-Tag: 1722929021-972170 X-HE-Meta: U2FsdGVkX19hrK+j69SLDcnwraUoPagshl7j/ZYxeRvfqHRsXYESghnGOjAT5Koj9kZMu7x6Cpv+e/BX4SBdghy6wFCGSbyzkSVZ19AYkCDdU2oSXWviBuAeJNIIB5KO3NIHpWBONu3JBjE7ujntlj4G9R9VVdWo91ehZ4JrLrTobZ5W9hoVXFTBcQYTrUm1PsUVoE9CKBffwdpkjyBAW01xvEGHD+D/0HcaFduzqKmNkdPfMJ7eBezSpBnzNDvzkC3nvD9B1ey0T59sgQzPwfhQn4mHJnrImvu6GMq/nmTW8ELAclQHe1nwUjQfH/24+++/xFKwr7WbqSXAt24BEvg+kIZZwk+Tsss7vWah1HIMREUeFCPTdKnYjXhLCv4n0islSRDMdvftiC4Hlla6iVdM391HfNeJwFPTlLNnNCYQMeMclHJD45vIXIoapf5iQmPIQ1agwqgzrnchayZ9tTBd5kvLp3b3JE9EObH2ZhYm0xzirW3krL4saqAhiLAl8SLouZ1VzAFqNPMW62E9Oaj6qe8PiRe4wKrwc4HEtfW2RrU51mq/FjjOXM5ifxyprGzfCghIbLjtD/W0wQyY55HUTxCFwpOhwaLhOEinkY6JiIb/gKUWC/VkMktWkT4GfT4MJf7U9ISY0bd2UCSM3P/m4Z/DYiap0vNGy0FZONB+kbMZGKPhJsJ8oWhRrPp+z4Ip5aufeyH+5G9q+ZuLx8RWNS08Nr8mn834bjoddCQlN9Acl3Zu69hfBeUM4ucukrKYTTTzsjQtc6hPLzY49ID9U5vkQt9moazEdjyViizdjLiVX/+wNYcFRufzJN6EydBgvIW4XUaGEknSeyvhIJVGQHjLZPmdF+DGbpYLdjE1iEdC4yKZJUC+2Inpu0gc2+la1F8BVrRH4t+4xBnP8CSwxBzdmcJ6Kw6Izpj+NVp/Gy1C9frPGfF8YlhGBGFGmdkIidBMDLibi+ONmVI gmTMFahf 8ejSWMKBUwHFAmOu7WOQ8AptPORdnCxdbSktwA+vUyEQ0hZkD2JUFdr+B8p82/sBwIdigbz4ge22zW3TmKjzJVDgvFHz0KyxKv1is6XoyuU5cIGEX6ApSft2nd/DdHvrFKAD7nv3K+vLu3uf2q2v5Q8T4LTWww/J12NPT3G4h9P1rmEf+ZsGdo3EgL/xyjevbU7UcJ5l6/S8qqdW7JIzFhzsORK3LmRsLH8RQcYf9kaH/T1Beh2WPZZLWGMjtwVr4adpeejTnWE7z9ePXQZTegEMgGZvsAiBNyaFLEOc+bTent/CRmlqpQnQdP72phxE6kmYkTgFJlwPlQl0SYA5bkcGUbcmNXxPj9t2Gp0wKP1+wYqcZbrD23xlLCN6ev8MxcGP1QPx5k20JRYnaPBtG/qLHXnFLvaWs6frkm1+xI7yMAO30h3EF+6TxaGq8XqcjQPClFn3nAQlZ0/IDDjucGZK9wMg63QGHXSKUxOIxdSKfQoxBRQwmP5rG5ZDmz4MXlavddnMXBBMNY694VWx7XQpX5nbztJxMovfRfFCJHJ0E54/3A0+VbD2oAjGIiNKkaDBVMJW36P08x8pCQFAF+ScvjtIQs+r65UCbBnfpsLMdMfbsTZET/D8nK0W/msnSQVxBxy+Pk/M11nS9PntQmlWJ0o0oPZUI/P2l7TELtOc0sX6kdg24euFpEhOfnCACPBq3Oo8yr0ADHJTAnPfdNFuoOrIkOECwW/zBofUrat99anN+us8Tcj+7cUcM65A68fE5tZjbQcnfLouEPN8FqKgiCP9MoInl043gECQTv0s5oP7bGFLJuT6z7Ixu0jjDkoQjnrJpIN8TlwWW0u04eL3qk+8cGtrzM2LTjnW0L9w7bNtotlV1cKoGKGT2pXLLi7Ai4S/bjO5Alo/GGjJ3twiKbLDx6WuRysXciHcI1ruWU90= 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: From: Barry Song Zhiguo reported that swap release could be a serious bottleneck during process exits[1]. With mTHP, we have the opportunity to batch free swaps. Thanks to the work of Chris and Kairui[2], I was able to achieve this optimization with minimal code changes by building on their efforts. If swap_count is 1, which is likely true as most anon memory are private, we can free all contiguous swap slots all together. Ran the below test program for measuring the bandwidth of munmap using zRAM and 64KiB mTHP: #include #include #include unsigned long long tv_to_ms(struct timeval tv) { return tv.tv_sec * 1000 + tv.tv_usec / 1000; } main() { struct timeval tv_b, tv_e; int i; #define SIZE 1024*1024*1024 void *p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (!p) { perror("fail to get memory"); exit(-1); } madvise(p, SIZE, MADV_HUGEPAGE); memset(p, 0x11, SIZE); /* write to get mem */ madvise(p, SIZE, MADV_PAGEOUT); gettimeofday(&tv_b, NULL); munmap(p, SIZE); gettimeofday(&tv_e, NULL); printf("munmap in bandwidth: %ld bytes/ms\n", SIZE/(tv_to_ms(tv_e) - tv_to_ms(tv_b))); } The result is as below (munmap bandwidth): mm-unstable mm-unstable-with-patch round1 21053761 63161283 round2 21053761 63161283 round3 21053761 63161283 round4 20648881 67108864 round5 20648881 67108864 munmap bandwidth becomes 3X faster. [1] https://lore.kernel.org/linux-mm/20240731133318.527-1-justinjiang@vivo.com/ [2] https://lore.kernel.org/linux-mm/20240730-swap-allocator-v5-0-cb9c148b9297@kernel.org/ Cc: Kairui Song Cc: Chris Li Cc: "Huang, Ying" Cc: Hugh Dickins Cc: Kalesh Singh Cc: Ryan Roberts Cc: David Hildenbrand Signed-off-by: Barry Song --- mm/swapfile.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) + return can_batch; +} + /* * Drop the last HAS_CACHE flag of swap entries, caller have to * ensure all entries belong to the same cgroup. @@ -1797,6 +1849,7 @@ void free_swap_and_cache_nr(swp_entry_t entry, int nr) bool any_only_cache = false; unsigned long offset; unsigned char count; + bool batched; if (non_swap_entry(entry)) return; @@ -1808,6 +1861,13 @@ void free_swap_and_cache_nr(swp_entry_t entry, int nr) if (WARN_ON(end_offset > si->max)) goto out; + if (nr > 1 && swap_count(data_race(si->swap_map[start_offset]) == 1)) { + batched = try_batch_swap_entries_free(si, entry, nr, + &any_only_cache); + if (batched) + goto reclaim; + } The mTHP swap entries are batch freed as a whole directly by skipping percpu swp_slots caches, instead of freeing every swap entry separately, which can accelerate the mTHP swap entries release. I think it is valuable. + /* * First free all entries in the range. */ @@ -1821,6 +1881,7 @@ void free_swap_and_cache_nr(swp_entry_t entry, int nr) } } +reclaim: /* * Short-circuit the below loop if none of the entries had their * reference drop to zero. diff --git a/mm/swapfile.c b/mm/swapfile.c index ea023fc25d08..ed872a186e81 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -156,6 +156,25 @@ static bool swap_is_has_cache(struct swap_info_struct *si, return true; } +static bool swap_is_last_map(struct swap_info_struct *si, + unsigned long offset, int nr_pages, + bool *has_cache) +{ + unsigned char *map = si->swap_map + offset; + unsigned char *map_end = map + nr_pages; + bool cached = false; + + do { + if ((*map & ~SWAP_HAS_CACHE) != 1) + return false; + if (*map & SWAP_HAS_CACHE) + cached = true; + } while (++map < map_end); + + *has_cache = cached; + return true; +} + /* * returns number of pages in the folio that backs the swap entry. If positive, * the folio was reclaimed. If negative, the folio was not reclaimed. If 0, no @@ -1469,6 +1488,39 @@ static unsigned char __swap_entry_free(struct swap_info_struct *p, return usage; } +static bool try_batch_swap_entries_free(struct swap_info_struct *p, + swp_entry_t entry, int nr, bool *any_only_cache) +{ + unsigned long offset = swp_offset(entry); + struct swap_cluster_info *ci; + bool has_cache = false; + bool can_batch; + int i; + + /* cross into another cluster */ + if (nr > SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER) + return false; My understand of mTHP swap entries alloced by by cluster_alloc_swap() is that they belong to the same cluster in the same swapinfo , so theoretically it will not appear for (nr > SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER)? Can you help confirm? + ci = lock_cluster_or_swap_info(p, offset); + can_batch = swap_is_last_map(p, offset, nr, &has_cache); + if (can_batch) { + for (i = 0; i < nr; i++) + WRITE_ONCE(p->swap_map[offset + i], SWAP_HAS_CACHE); + } + unlock_cluster_or_swap_info(p, ci); + + /* all swap_maps have count==1 and have no swapcache */ + if (!can_batch) + goto out; + if (!has_cache) { + spin_lock(&p->lock); + swap_entry_range_free(p, entry, nr); + spin_unlock(&p->lock); + } + *any_only_cache = has_cache; +out: