From patchwork Wed Aug 21 07:45:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuanhua Han X-Patchwork-Id: 13770971 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 1A62EC52D6F for ; Wed, 21 Aug 2024 07:46:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D0156B00B5; Wed, 21 Aug 2024 03:46:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 980116B00B6; Wed, 21 Aug 2024 03:46:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D24C6B00B7; Wed, 21 Aug 2024 03:46:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 603E16B00B5 for ; Wed, 21 Aug 2024 03:46:38 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CFD081A0A3F for ; Wed, 21 Aug 2024 07:46:37 +0000 (UTC) X-FDA: 82475470434.05.01ADF71 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2061.outbound.protection.outlook.com [40.107.255.61]) by imf04.hostedemail.com (Postfix) with ESMTP id 3CD0340003 for ; Wed, 21 Aug 2024 07:46:33 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=oppo.com header.s=selector1 header.b=akldg0gw; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf04.hostedemail.com: domain of hanchuanhua@oppo.com designates 40.107.255.61 as permitted sender) smtp.mailfrom=hanchuanhua@oppo.com; dmarc=pass (policy=quarantine) header.from=oppo.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724226316; 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=tA9aZraGuDqJxramZ0QgY1FA0Nn7yW99MlzZpYtrJRQ=; b=pkXsG/IYPJH1DzlIKlkZMC27nXft/b2YMW36f499/fTVXo+6B8MWRv8K50bcqaFt8nyz3M kFEF3GhAmmQCdYwKWTwHfklOTFl2Fuq4RlHsVhAZF8kufwnpXChqCQ6rt3MDhOgyVeiujV b93o1+LO2jt50uvfCn0oFiMXKRu4kkE= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724226316; a=rsa-sha256; cv=pass; b=1YJE0HcO5ir7CnQU52cWuO0gXvsHkgtPKMv6FJOPz8vNfvBWSZjQUXnKq42qYWv3Bv6sOn oSTcQglfOt3n0lYyHbWZjDi6CVhxjZOXkehcwZxKj34tDC1ugsq2hKXGid6DLyiY+DT8sL 9ohxEkaggE4ddu1Bz8WM+S+msaNDkEQ= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=oppo.com header.s=selector1 header.b=akldg0gw; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf04.hostedemail.com: domain of hanchuanhua@oppo.com designates 40.107.255.61 as permitted sender) smtp.mailfrom=hanchuanhua@oppo.com; dmarc=pass (policy=quarantine) header.from=oppo.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IZMYjB+wZ87DzkUtGT6Gead1/0b8GkPnDsIm4SCNoC+hTQS200kNZQZNZOqsYxYvQVZ9rl+8Oi590DZcRSccsXUHZl0BZ7XxhKhqb+hdKa5oYwyNow9ZOhrSNTvz4hE/mQyzc9/0DFQUjo8rhEeW8+1LubJ7kThOCms9lsALzTqzBtVlxrutdRHW33IBeLb35OOnayuuAlKVVllknP2YcSrsD1vgOvc2CM6iBkxBHmE1fzYDDFB2EQYD3Olhr7wjIwOCkvs10xmXX3OK+dnIqZMpPc49RUKNTuliA9UcEQcL1uciR5plCVyfHynt5PCtfO5d1q6B3FV3Z0mudw2Zew== 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=tA9aZraGuDqJxramZ0QgY1FA0Nn7yW99MlzZpYtrJRQ=; b=TXjnXHWegJXZ/jj8nADnZ6jzvIYiU9PGLeiHRdQyIVGtrJcj5xnxqpEyQU+PLIOMgS4z+UY9Tfy2eUvsR1lQE/Z5/j0ewVmSMqldrnenpAkycRsAX7icuCLeAton9SmxIUTvVXufu0KPUxGBFoGLm7MJAjlBp/P43UqVebcszOAs4qx25U6y1UP9jKyommOaAgrw0LsPPs85b883l5ovxp5x4pXgEcWVaqSXsrA5JVb/M5n+4JRTNqoJEm/RjKvdUv7tnUAWkf89YpESaWYg7mjY+HEXbnbSpL8H+LdDqo7Wq6c3k26Rk6chjrKAvfCDhqTqixuGAOfNM9jsmbS2jQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 58.252.5.68) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=oppo.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=oppo.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oppo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tA9aZraGuDqJxramZ0QgY1FA0Nn7yW99MlzZpYtrJRQ=; b=akldg0gwoiBYvWfObCVZmQWK2lEU1ip1nfef5OgBYGqO2qvBBYs5PNuX285AHpP+A7LAPFavUyprq9CX+KQCLbzumnmJrB0ZbiehcG307eJIcWN/i7ytqxmzVaf6TDxtMlF4oyScdkhdtSSK9QKwZXuF+t/DvqbfQwAC97SYAxM= Received: from SI2PR02CA0045.apcprd02.prod.outlook.com (2603:1096:4:196::21) by SI2PR02MB5514.apcprd02.prod.outlook.com (2603:1096:4:1a2::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.18; Wed, 21 Aug 2024 07:46:27 +0000 Received: from HK3PEPF0000021A.apcprd03.prod.outlook.com (2603:1096:4:196:cafe::7d) by SI2PR02CA0045.outlook.office365.com (2603:1096:4:196::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.18 via Frontend Transport; Wed, 21 Aug 2024 07:46:27 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 58.252.5.68) smtp.mailfrom=oppo.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=oppo.com; Received-SPF: Pass (protection.outlook.com: domain of oppo.com designates 58.252.5.68 as permitted sender) receiver=protection.outlook.com; client-ip=58.252.5.68; helo=mail.oppo.com; pr=C Received: from mail.oppo.com (58.252.5.68) by HK3PEPF0000021A.mail.protection.outlook.com (10.167.8.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7897.11 via Frontend Transport; Wed, 21 Aug 2024 07:46:26 +0000 Received: from localhost.localdomain (172.16.40.118) by mailappw30.adc.com (172.16.56.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 21 Aug 2024 15:46:20 +0800 From: To: , CC: , , , , , , , , , , , , , , , , , , , , , , , Chuanhua Han Subject: [PATCH v7 1/2] mm: add nr argument in mem_cgroup_swapin_uncharge_swap() helper to support large folios Date: Wed, 21 Aug 2024 15:45:39 +0800 Message-ID: <20240821074541.516249-2-hanchuanhua@oppo.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240821074541.516249-1-hanchuanhua@oppo.com> References: <20240821074541.516249-1-hanchuanhua@oppo.com> MIME-Version: 1.0 X-Originating-IP: [172.16.40.118] X-ClientProxiedBy: mailappw31.adc.com (172.16.56.198) To mailappw30.adc.com (172.16.56.197) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HK3PEPF0000021A:EE_|SI2PR02MB5514:EE_ X-MS-Office365-Filtering-Correlation-Id: f50ef5e1-ea48-4af9-47cb-08dcc1b55d0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|7416014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: +lHhGpDOVJ3W/iSj+Osr28etKWP81DKD+g+cAOtlFqBUDFsSLD4Bi2J/2NjsQpiqO8Z5UlcjZB+0ilWSOufRzE+AOSG/qYrKfytVUbQ8t5zbI/SrrTCmHhM7dNdb46XAf8JVRmRNMOckoF7ozz6vNIcTnyDDgot/huSlsRp5Ce8iPIIGAfVuLqZDjqofTzZoiAiy9V+HUV0848h+IJyqn22bcvbOFYX8RIfVRQfEcsjCcePR7viwII6RlQeXThBteozHNW1zJyh/g358EU4OrHk8OneSSOKiJiEflasRFoOCeKXXlX9S7YSR96QEzj79zn1Qmk9r7+F7V+rKrf7PwCFVH0xj+wcOqst0MXCp89tAspsjtXZog4FzKozw3feE1TkVSedImitPFO+9ttvGr7jtWvqnJ3O2ch47h2PMNIpr0RRy8O9hYANNOr295pAi+EXVswc+EFz3HM5yETHGILWuOepbCDZZW7E4fNAqKyBStNcEy2vtbFjbi0rMqqcQBUZ8qxNV1RZAXQfWDgJcViQeLHLNEZ2rPdyDaUdnvrHaUHmDxd/8CNwPVKVjoXdOmkLFdVG6VrMSfb3trEgPgVlrafGicuXFf6pp69AiGuJKsW1kQ44wkoDWXqA5OYO00HSkhZP0DXAX0mLq+MOoYbz98bocSnDYT/hsriWNSFMGPZw3HMte+Ap0z+V9Ez+b5mz0sOq/jMNSUUKW9FJ6nFRgBugDCcMsT90Z/Nfwxx5HhJWGAmQ323ZF6fHotMQPGddT6YTIsggCM36kT8xQbX0YlFzfSN/o6aUxqvIf8BbGiUEgOS5ogz3TAGGdazWfmGAD2zlLAwWeuSEc0RIsMARcWsnsJMI2XajWW5jUugYpj/lJDgsX5NfszNO3gcp7tDUBHpPGYCa1wuxFIyVewr6ZcalWrUw4uUcur2zB/yqNxZlT5hnrwLyBJ42o8DWruM8mFLVbzbViGD9Zz2KkdcOKf3ChsJI0aPjqEphgAAjksHJwNORAjhP98KABzHhiAzNaPJqy0q7heHrxn82xFMX25tg52xJqq2GCwC08LGamuDzr4toZNkv4wE7gzFhMJVC4Ray1im+6iag8diX1LdChuyXELgTW0LEExJXKfWZsKQZZu2Ufv0nBnogLa6HlzN/0sYLlKNj1y08US2EzdVNDgjp2MsLXbMWiL7sBETnsatdsrbystk9dGJMZxBXZr+ItwKuKMTpeeiJXsJ534ZH6snLt6rCJiRiKskkzePsKHPaP5OzSQZBUXNKbpGnUqo36eKN8GYa8Vny+lMoa1HzEznXEIZmNMfqjBx89MS8u8eVTI1inSi4EV4SrnjS/wucGOKNCdtB3YWzck7nBbvFi1rStUONPzVnJvBJqWHP8ctjNPG9H2Y20qrB9Yow3rACxUxBTzKLX60D9fHwmGaeLZZ9hjlDjKn0qUxAMh7C2O0szO1rRm7wt10gCzeIH X-Forefront-Antispam-Report: CIP:58.252.5.68;CTRY:CN;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.oppo.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700013)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: oppo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2024 07:46:26.5123 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f50ef5e1-ea48-4af9-47cb-08dcc1b55d0b X-MS-Exchange-CrossTenant-Id: f1905eb1-c353-41c5-9516-62b4a54b5ee6 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f1905eb1-c353-41c5-9516-62b4a54b5ee6;Ip=[58.252.5.68];Helo=[mail.oppo.com] X-MS-Exchange-CrossTenant-AuthSource: HK3PEPF0000021A.apcprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR02MB5514 X-Rspamd-Queue-Id: 3CD0340003 X-Stat-Signature: s4a4hjmcob1r9qmihqxzb8brk6mgwyq7 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724226393-229528 X-HE-Meta: U2FsdGVkX1+bSZgXClK4r+aM9Jaj1KHSM+cRs8/blAwzrmm5OJxIq6sO8Y06ztkoAbdLMwuQGHUbL43uxpVjc/xMlM+OzGtAQ9sGErmm/24t31e8LFMCelKY5rl+PIGd/vxDp9oHIfCS4Cl6hRxQS1kw/RFlwSkrbyngZ+z1gQsJ3Gta0hkr81RNSPuFC+kAD8lD3+80mUn81eRukddnU2yJa5qvfUeVTup4eHMjL+ZpkSUqrsf5IIkStdf8b5ASZk/LA/KpdgNTOQg3aNPUwIESnJT1+6dWFpYopH/FQtbe2yeYwHaOV63Kog1FfAg0flXUO5KzIH7Xah44NaHlYHSzhPRuwE4oj1EuIGZ4YcoqgnZnH3h8ucb0fxHxrhF20CTI8SJocFW9+S83I7McAMZjUvutxD87jpYhRxKVuFVWxisWBUQHo1APGsHd/uJ7KvZy42mp1ybFc6yDe/Osb0iMG8IOhd0U7K+ukLnBk8+ziiG7IQ95Wh22hzg6v4e0UMkHmHKprt29VsBWfpT45HgpgE+zE4FI5+SuZ7aU6OY7jWT/6xF2ukHIDz49G4aHs4LBF8G/AZ9DlPojdPB+nEHHRRAs1dNjT8T5curXu6f8rg1TB22s/crUsro3mlIiT00yPzf3tKkHonZ4EXtinLkXZWGu5T4Z6nDRv0w7HOtdVQ9pV1+5YIpq0Fqtj/WaatcDWK1D0FcdgRXHQP0IYj9TJ+A3UVyBbyeGOP77sXizcKgNKEXPLpbEfg0cqow47Og6rY07OuSSEWCx84TGRXjd7Ch53xfvPbCl4wRqIJ66GxFu6AojyJPVymAdd98S1FoWQip1sSXAJGMNx3VEyLxazHXn2/arhKH6s9buZyVG5ivZrp0xgjtZmBmE6D9o/k4JSKmxqK5txuFwKgoEDbaHAyLXwWE8rnaz9mBbaIO5APE8uq5SaoFjnAMPLM0cX1UMncEBShseg+SDT4g YZNCdZc8 QVsOiVVBBArS4p5cvswgNoa1A5pHlK3gpVBUY+SWlrfKH+9kpJ+rguxqrIc3py29khF8hOUtnlSPiCy3K/EvVmMdw4WLztZUOyb+kwFQXqFl3j4GgtbCe2J4e1vaxXZ+um5aFcJjhWLp4dr5aNCqpAPd2RJMygTwBAC1mj0sol660KErb7VgEW5n2sc3+F3jeGUt6dh7Xg9pbY8GwoeaM7h+PbwloItbL2ej9XYFXmK+DGf9cP6XMWYWL88nSNtR/S49F0rHWbEq75KU0/HTnHSL940vNgCmsqAHUppeG7GPMLeM51Qd3ie3pLDn7Hz6QFaGjEVErApT+AaAcg/nR9WETMbqxUjdTGx7FPe5Cox6iHTq6lHrQxTp4CETXwUIU/NAUbdgqPCwawlLNpjRDfN3Ckei8wdvYk4QTPzoUr+0zinH7UN/PVJonegWU/jevofmaA8k4TVKYDrOeU4z5dUQSzENH6aO2myGOgRInQsPHYGc= 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 With large folios swap-in, we might need to uncharge multiple entries all together, add nr argument in mem_cgroup_swapin_uncharge_swap(). For the existing two users, just pass nr=1. Signed-off-by: Barry Song Signed-off-by: Chuanhua Han Acked-by: Chris Li --- include/linux/memcontrol.h | 5 +++-- mm/memcontrol.c | 7 ++++--- mm/memory.c | 2 +- mm/swap_state.c | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index fe05fdb92779..780120f7b9dd 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -699,7 +699,8 @@ int mem_cgroup_hugetlb_try_charge(struct mem_cgroup *memcg, gfp_t gfp, int mem_cgroup_swapin_charge_folio(struct folio *folio, struct mm_struct *mm, gfp_t gfp, swp_entry_t entry); -void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry); + +void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry, unsigned int nr_pages); void __mem_cgroup_uncharge(struct folio *folio); @@ -1206,7 +1207,7 @@ static inline int mem_cgroup_swapin_charge_folio(struct folio *folio, return 0; } -static inline void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry) +static inline void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry, unsigned int nr) { } diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 42c826eec124..fd74a20f23a7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4574,14 +4574,15 @@ int mem_cgroup_swapin_charge_folio(struct folio *folio, struct mm_struct *mm, /* * mem_cgroup_swapin_uncharge_swap - uncharge swap slot - * @entry: swap entry for which the page is charged + * @entry: the first swap entry for which the pages are charged + * @nr_pages: number of pages which will be uncharged * * Call this function after successfully adding the charged page to swapcache. * * Note: This function assumes the page for which swap slot is being uncharged * is order 0 page. */ -void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry) +void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry, unsigned int nr_pages) { /* * Cgroup1's unified memory+swap counter has been charged with the @@ -4601,7 +4602,7 @@ void mem_cgroup_swapin_uncharge_swap(swp_entry_t entry) * let's not wait for it. The page already received a * memory+swap charge, drop the swap entry duplicate. */ - mem_cgroup_uncharge_swap(entry, 1); + mem_cgroup_uncharge_swap(entry, nr_pages); } } diff --git a/mm/memory.c b/mm/memory.c index 93c0c25433d0..b9fe2f354878 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4101,7 +4101,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) ret = VM_FAULT_OOM; goto out_page; } - mem_cgroup_swapin_uncharge_swap(entry); + mem_cgroup_swapin_uncharge_swap(entry, 1); shadow = get_shadow_from_swap_cache(entry); if (shadow) diff --git a/mm/swap_state.c b/mm/swap_state.c index a042720554a7..4669f29cf555 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -522,7 +522,7 @@ struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, if (add_to_swap_cache(new_folio, entry, gfp_mask & GFP_RECLAIM_MASK, &shadow)) goto fail_unlock; - mem_cgroup_swapin_uncharge_swap(entry); + mem_cgroup_swapin_uncharge_swap(entry, 1); if (shadow) workingset_refault(new_folio, shadow);