From patchwork Tue Aug 20 14:33:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13770192 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 93E25C531DC for ; Tue, 20 Aug 2024 14:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 925706B007B; Tue, 20 Aug 2024 10:34:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AD8F6B0082; Tue, 20 Aug 2024 10:34:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 700A86B0083; Tue, 20 Aug 2024 10:34:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4EC986B007B for ; Tue, 20 Aug 2024 10:34:17 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D73F41202AB for ; Tue, 20 Aug 2024 14:34:16 +0000 (UTC) X-FDA: 82472868912.08.9D85104 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2073.outbound.protection.outlook.com [40.107.117.73]) by imf20.hostedemail.com (Postfix) with ESMTP id CE81A1C000F for ; Tue, 20 Aug 2024 14:34:12 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=nYSyuu8Z; dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf20.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.73 as permitted sender) smtp.mailfrom=justinjiang@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=1724164365; 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=V8amlR0ISfgjw9nTTh8sFWiFDiBnEjI49OgX7OSyz9A=; b=jddgRLimUftO3X9mOHJZJvzELMr0leb68DoLI9LzS8mGb29+iyrbUSHSGwtDUxcc6U5QfP YhU5If1jwDBRHRIdxdPIRlhAkSi/yypGKt9g0OO96L51qlkn6G0M7DzS1VQKBp/zFvEWLm Wu/G15t/QSE986E0zb9A2sfzHIQQ+S0= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724164365; a=rsa-sha256; cv=pass; b=XkHH4DtJw1GFM/57RNR2YAgRPVWRNF+KNRpQKdE2H8YZNlD0gh5sPepkZC2IZN6uO6X3DM FcPgVFWrZlyvQ8vwBPvH886/ahk3MJ+dZ1HIt5eYG7HZ9/h+s2JdP/eKedDtLScxDOF60C 1qGXUUDVo/8hjtp5BnJWdSsX4B4gqeA= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=nYSyuu8Z; dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf20.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.73 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=beSC8osAGkuUs5npTHJyC+ugSne7Oc3WL3JSaqYiRYV6jZ8miLWO3mbUzk4DNjZA8e8Io/gGSts3NqaBbaICQCMwNMOOw1/bjl/+q3GVixH5EEEqrV7EE4Ym32yBtwTJbL6L0DGCLOFommg+vE+Jooq8jknj2ng9h5pU0c4DJKkGqz0yEwyDGjFG8Xfo9CWzv3UV0pbnHnNZ7jnKiex/lH5qAvQwQuJtH0kRKyinyKsf+WJvvpWmwAgaTc2l8sL20E9it6QZC3O2yELc9JJgj6YhMEZZgVXbmouPR5gmTp4HwtPGMeh34jnvOebPNygV0Ika9VBlni6nYbgMcBTwrQ== 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=V8amlR0ISfgjw9nTTh8sFWiFDiBnEjI49OgX7OSyz9A=; b=MFueHqg6lLYTvbEtXiQ4TbMZr3tWoV/OUvVXNNIyCxrbnLasxnHm+iSEQDToe92oFPmo11vwEF7c758wawAg/Epx6KEMVWrFf6avmD5cOyevHFTZdboiivJU7KWSSXAFqALNy0bmaCyjzOzmMDfwY6ExVv4PyoH5ZnK9LTzT+QsN3mi3ovK5nGuN0RlggFNo3vtIK6AmPH90VtA0tXeWcsIibAfBHoB57jTR7x8RRodvSq6CmyJbzJF1ZBgxcqh73jnagMMcLr90aypJe/CtvBET72/XEc9Hi+Pru3qOUHMa3JhFaCmTRjk/Qjq95NIja1n6kELePzeOdXcTHuSGag== 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=V8amlR0ISfgjw9nTTh8sFWiFDiBnEjI49OgX7OSyz9A=; b=nYSyuu8ZXOEbYS2j+r+EjS2JHeG+H4tbK9bx6Z4fEY3EPZ+kKtUKRZCH20FsbfGnheOJ+NDYS/rMVR3N/2NKT1tx0552AXTUgfQx2i/Z77KGouh8d7XWn3J9jaF90LPAgxf7oUOnpT0MQa+C8p0B220RRjclNCxPpnoia8l8uiwCEpmbgH1db8m/94b14rXCVeL4shx+9BdDT2sqC6yHc+Fb8ZUl9giFj2a3ReelAMk55ceKnYi2vbM7i/S1h80kr8oKxz+SynA9k0K8aAQYhJyDtPlbu/GU2D2JkKj6xtp8BUDSQbaJlYlix/tZ9iztqFK1mCizz5EGvp8mBTNOFA== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by TYZPR06MB5346.apcprd06.prod.outlook.com (2603:1096:400:1f1::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Tue, 20 Aug 2024 14:34:07 +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.7875.019; Tue, 20 Aug 2024 14:34:07 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: opensource.kernel@vivo.com, Zhiguo Jiang Subject: [PATCH] mm: vma remove the redundant avc binded with old folio Date: Tue, 20 Aug 2024 22:33:59 +0800 Message-ID: <20240820143359.199-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SG2P153CA0048.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c6::17) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|TYZPR06MB5346:EE_ X-MS-Office365-Filtering-Correlation-Id: 51ef7233-33be-4130-968a-08dcc1252614 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|52116014|1800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8TUqL0dlES3lK+e6+iOuvZlDqpisOTKYrNWgo5012aP7AZQfAjRGBp+8EDhJa8fbLje4+/dphgCj8n9V9WjvFYqplvFZzNc7btcDjB0F3SiuI8AmnB4lQbGtQuw3a/3YXdwM3E3aVWCzH+rDbhECSnSyiS3eLqBoH94BNC/QxD2tDpZrRQJxsXsqTTaB5wcZNJ+9T7QHAj8lR8TefyEoSjJH2brZ6JfPDZ8dd2hBxjWeQ8azvTZpMyprrLHOP606QJrZXybTAW9KkwbLh1o1LV3JekvEEQqtUCEfAJCoRhKhmgGGsvke2mGFla3jBKLTudkG2464ae0F8OOk4niVCc3CGmaur948G7OCN3JVe6A+P7F4rbU/pyYAqekUikMXgLovewbpw== 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)(376014)(366016)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LqLkEDjz4SMXeDZVVqSHfMNVb5P4s42LK+28t2jHOPzTQg7tgo9u+MGN9w5iaUbDOBsFxtvRiz1oejLZy4JfY6hq2FCnTvUtLadMft5ad0smAMcDmmN09zPvY5YFMNLvOpFAhDMs6xCZXmf1kcY6MwbvP9p0H1ZmRpsW9drBF0HZ3G3J4Cm/GoAuV89gR6reRmXQbwxvIZyGRidv1lIZ1TUcAsq+GNdQ/nqrvtJW5ubtOETrQNCeuGmseeAznv59Z/ciYp62/MLvRYiYuvcFQGQh+y5u1G52/n4rQnwsyBsFoqn/mwJqMyolfuMS8JeYT90aQXNmqqb+PITNlqFcvyiPh2R4J6usXO9XtNKAtwmrHg/oGjTC9sOz8cNhmioqr7RYwAxB3HTqak96Cy44dnV7+Lw2nOfjrAqvNA0wYs+p0OMT4BE8jsUH8RHCav5qxCgr5J3Xhcil53T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TkRpFxiHcr7SNJZUSm5JA9Zh/mRuIaT9lh64qTCZOBOBIb30USPSdX X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51ef7233-33be-4130-968a-08dcc1252614 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Aug 2024 14:34:07.7876 (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: /jsc2EdNc9Qi7LuN4trXnw2BZhThY551HzKENrHdd1z3QgYev8WozI3/ppimpyOa1DAkdaFu4IAWwLD85HDmXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB5346 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CE81A1C000F X-Stat-Signature: z4zk9a1bpdfikkpe1ey4r8uxfaf7ajx8 X-Rspam-User: X-HE-Tag: 1724164452-56530 X-HE-Meta: U2FsdGVkX1+YRafcTgSJDnZnml/nkNarUtyXVCde5WSJkGRuk0jpLjbyrvTSCMh2+lp/DYPvTRnXcWBFyAqf5tQdzgppiV3JeftwrGG123ba+qS7UpfliSytJ0jsLbg72009LVwJklOGta8qoh5acTPl9MgJtMUc7HPBjN1wVkuY52xLiUQuMeaTpsmj1r+UcoLkXlIff7pF6+goqZcrewK4r79FDwBG1WSoCem9j2wt3sh0MWPFeYfIDh6+sJHYRWq5ZAq41w4wMUXa23nFyDgZAO+p/PFU54lXiNxLYNrwxecabV6hc1XNa6PICGbEm/ninykLS51EUqGsM8szuA9J/OzGIp9IZnIKLh995xbdnbfrjlY8zf9A9MbawWCIdCtmdnO1yoPGqVvyFEl4VODItPQPbO8Zm2BJKvkIOEfv/aDc46fYntkfXYOXObyhGY3smbCZiE3uS58CuRc1UinNDijodanvQH1jYS53RstsjrpZCawea/vmfUPG5aRrXCm9pvgAI8LViWcXR3xeC7MQcKmN3mNVIYP46pJfSoly2GWh7Syh9RLeymi2iktaMYM/bvcF7yPB0YFnWXp65nO22vXqXCAYrdYgkAVKkWrzAhDdkKFun2SM5eo+/Hs1NW6fK11Dnc5RE0KfsEqQbJXdZiYq9/QJFOUaxHa3j+DOTKDlSA51qYQTg9OY9GkLiSxyRQgrH+aOepkLapqO0UbvopdCLwSVFDhqdMB4PDefgaKln10GYcqFeDY5F0/0OZkCCCrvWwQRzAxfSfjJkVqFrD/y3rlYRSt0KrhGOC320f+6b9UbxpQUPE1ltBF5M4GyG5aVhLrcHIdnqv+BcsFer2qjdc/jJULxegScbIcO1VNhtG+JxR1B9rsmmxDUSjFTV/fJZ7OzRXrjN0wEjHPczmWDgTekNZGNXlgjK9dA9p7ARtuCaWE6Qijagj7W0lS393XQHcO+Qlnmbmt 1qiM54Ba PGnf27UkkRb/j/ScDgUq2C4CIW1qyVxP4Ebj2T5Q7x1P14762gQDFuV6EZQAxA1kAqMCSb+yh90bYS5OuBK+B8RjUtVNM3EpyX8A2mvRzQMcx3eiCz0x71WB4cO7Vz105UKrjuiL9GMFzWhW7M+ySE8ImTXXWBH+u5kD8eG0aGHzNtnSWKjWz89UFDKRi6lQyitDdTaRQULhDBY8g11zlrOa2bsxVEsgyu0fJnLFx8gV9kIJH7QBvTDucFrRBNw+Ogksxw20Lqq3wit3+al8UK5jgg7r9GCryWDhbgHY/IHMFAJg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: After do_wp_page, the vma established a new mapping relationship with the new folio, and released the mapping relationship with the old folio. However, the avc binding relationship between the vma and the anon_vma in old folio still exists, and old folio can still traverse the unrelated vma during rmap. This is incorrent and will increase the rmap redundant overhead. This patch will remove the avc binding relationship between vma and anon_vma in old folio, alleviating rmap overhead. Signed-off-by: Zhiguo Jiang --- include/linux/rmap.h | 1 + mm/memory.c | 8 ++++++++ mm/rmap.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 91b5935e8485..8607d28a3146 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -257,6 +257,7 @@ void folio_remove_rmap_ptes(struct folio *, struct page *, int nr_pages, folio_remove_rmap_ptes(folio, page, 1, vma) void folio_remove_rmap_pmd(struct folio *, struct page *, struct vm_area_struct *); +void folio_remove_anon_avc(struct folio *, struct vm_area_struct *); void hugetlb_add_anon_rmap(struct folio *, struct vm_area_struct *, unsigned long address, rmap_t flags); diff --git a/mm/memory.c b/mm/memory.c index 93c0c25433d0..4c89cb1cb73e --- a/mm/memory.c +++ b/mm/memory.c @@ -3428,6 +3428,14 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * old page will be flushed before it can be reused. */ folio_remove_rmap_pte(old_folio, vmf->page, vma); + + /* + * If the new_folio's anon_vma is different from the + * old_folio's anon_vma, the avc binding relationship + * between vma and the old_folio's anon_vma is removed, + * avoiding rmap redundant overhead. + */ + folio_remove_anon_avc(old_folio, vma); } /* Free the old page.. */ diff --git a/mm/rmap.c b/mm/rmap.c index 1103a536e474..0b9111c59dc2 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1522,6 +1522,46 @@ void folio_add_file_rmap_pmd(struct folio *folio, struct page *page, #endif } +void folio_remove_anon_avc(struct folio *folio, + struct vm_area_struct *vma) +{ + struct anon_vma *anon_vma = folio_anon_vma(folio); + pgoff_t pgoff_start, pgoff_end; + struct anon_vma_chain *avc; + + /* + * Ensure that the vma's anon_vma and the folio's + * anon_vma exist and are not the same. + */ + if (!folio_test_anon(folio) || unlikely(!anon_vma) || + anon_vma == vma->anon_vma) + return; + + pgoff_start = folio_pgoff(folio); + pgoff_end = pgoff_start + folio_nr_pages(folio) - 1; + + if (!anon_vma_trylock_write(anon_vma)) + return; + + anon_vma_interval_tree_foreach(avc, &anon_vma->rb_root, + pgoff_start, pgoff_end) { + /* + * Find the avc associated with vma from the folio's + * anon_vma and remove it. + */ + if (avc->vma == vma) { + list_del(&avc->same_vma); + anon_vma_interval_tree_remove(avc, &anon_vma->rb_root); + + if (RB_EMPTY_ROOT(&anon_vma->rb_root.rb_root)) + anon_vma->parent->num_children--; + anon_vma_chain_free(avc); + break; + } + } + anon_vma_unlock_write(anon_vma); +} + static __always_inline void __folio_remove_rmap(struct folio *folio, struct page *page, int nr_pages, struct vm_area_struct *vma, enum rmap_level level)