From patchwork Fri Aug 23 14:01:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13775265 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 310B2C52D7C for ; Fri, 23 Aug 2024 14:02:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 849EB80084; Fri, 23 Aug 2024 10:02:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F98D6B0321; Fri, 23 Aug 2024 10:02:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64C5180084; Fri, 23 Aug 2024 10:02:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 428446B031E for ; Fri, 23 Aug 2024 10:02:00 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BC3D0C1D72 for ; Fri, 23 Aug 2024 14:01:59 +0000 (UTC) X-FDA: 82483673958.03.B892CF2 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2064.outbound.protection.outlook.com [40.107.117.64]) by imf10.hostedemail.com (Postfix) with ESMTP id 887C5C004D for ; Fri, 23 Aug 2024 14:01:54 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=JsKSWHrm; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf10.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.64 as permitted sender) smtp.mailfrom=justinjiang@vivo.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724421648; a=rsa-sha256; cv=pass; b=EL9clLb699rxg8KotY8nWy1Q+KWvFqX76c9qFSdkXZomwX2uoecYOJpb/85aFtNapMQeXO aEtNRl0K5hhOM4gqZC7ZkxiTp2dZUMsoh8SQ+hj1q+Sr89z/wQalBjD7RdfB4sN5p5onrB +wERfmDKUTq27BwqR9ClYQ97/6Aw+4U= ARC-Authentication-Results: i=2; imf10.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=JsKSWHrm; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=quarantine) header.from=vivo.com; spf=pass (imf10.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.117.64 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=1724421648; 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=QXYoMV2Du+s+82HmC1q3+f3kEqfji82ljdp88SSmQ0g=; b=DBuvuT0oy5PxuSOnyp3oqpmOqd4Wtsl60MaAiMLIHhK8LlT9ZAczCAIs4uVK+VZB/ohHwF r4XGCz2D+iWdyLU2dwF/NdHcD4GhcuuTiOkc+FVPbfVM674ymIwvoht1REBnFPoR8Wr0tR Yx7p7Yr6JCymCqdHCZWofhw5Uh+woDo= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uPLBN9uOIsvRgKUQdtxZPbr/f7jyta+kq/n/G0I7FXYxdU1BsduEKj4+XQL4GIQJ/MHijMQa3rOX3AnEA2lMU3amWSAHuQ+qVKAH80gDDYYpNrcw7o8hzf6vGm4yJHd1tDcZUPLcMFcxC7Kz/K/fRp+k1ijyYmkr6PbQMlfoq6qTSY2HYs/0UMWTpEBY5ULM48uq8WMTGR9jxS6CVFpghF7JYC0hVSboQyD+ySNCSSrcfB7XIxPutzOy7fP7itYkgvWlB3oG63tmr43FWE+vA2/ogrPQPQ/NCm6ko2RQJPh5rakSWeE7VOqYfukDoatuz2H89Xub6QkRqCqIBwkhPA== 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=QXYoMV2Du+s+82HmC1q3+f3kEqfji82ljdp88SSmQ0g=; b=IFlRXg7Kzi/4QQl4JnX7Ib51PhCcqwr01IoS84xUa9dYtAQ0HxTh6FKoniVj4mqW4W17+MUAU/QPFIzjOaIMtO5u5osY26WSIubbHYVb6A6VVvwshDxd/FI/4U6w8xmDniA2R+tP8KhInfewHO4/l6cttxn/me7ZCWTFLjjVFXCMLwzAljNgfHqD9i0QuD2Q3bZfOz4H4RnhB8UhYCcw2GY3c9L7OYYONZV22MOHDgzekAR78HJblELOQHNoAN3UXJYA5zPnHRg8tZW/WhYqavx//sd5RQ4dQg7UHzZ4vu42hF52W+mf4YWMiGcui6nMh5dplf6uiMGrITCpcGN0ng== 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=QXYoMV2Du+s+82HmC1q3+f3kEqfji82ljdp88SSmQ0g=; b=JsKSWHrmMitjGj1bswyqimpNZ79yKoXJ8dse1v0NDz206/wNYCOQRfWAvLPZ7/AbA0IFhRZcTMPh8qTG+mREULU4fOFxQuagEUu5bIpnWH2aQeONgpeRvsalE6+Ke3mlZzwg+nlfSeO465qq61ZN2wH/yZfVNUuQzIrBhWbRM7mJpaOJfCCCB4xQk4FpP87j41PYIGqTxQjZE3uKjYO3hrGfH1Zpr1jU7YlpofQYh5+o43AkxL2lg3FF/oZcSSo2pK1MnNrOENr3IbAA2R2y878PttkTJyQIYTBoZFb/W0DTiK5Uht6U2c5cg5tiBDBp08cuf4C5N7TrFjUFG+jS5A== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by TY0PR06MB5458.apcprd06.prod.outlook.com (2603:1096:400:329::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Fri, 23 Aug 2024 14:01:47 +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; Fri, 23 Aug 2024 14:01:47 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, oe-lkp@lists.linux.dev, oliver.sang@intel.com Cc: opensource.kernel@vivo.com, Zhiguo Jiang Subject: [PATCH v2] vma remove the unneeded avc bound with non-CoWed folio Date: Fri, 23 Aug 2024 22:01:39 +0800 Message-ID: <20240823140139.263-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SI1PR02CA0033.apcprd02.prod.outlook.com (2603:1096:4:1f6::14) To JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: JH0PR06MB6849:EE_|TY0PR06MB5458:EE_ X-MS-Office365-Filtering-Correlation-Id: 06d981a2-47e0-4b6e-4b31-08dcc37c20f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: pGJzcnQk/WyzBpgOeAsJ+HizYvditsQV0CWQY799cPxR7RJXrpRDkLORNiPdKw2v48biug1/dXpJMJcLsWivSXd81+YWQY/N51e/taqixgHuFuKxtv6CUEGMlKANAzDS79z/d2Vau0HbdjFQwYE+dH8+9TGjbVsynQfB+uDCRTxvpHfnec8XrKBNhZyj2/RaWRey830+MsEnK2OzDQmMngf1h60PNQmfJ9QWs/4Lzs6aoCfOooHsqm0AgmZRA+q47gMEw80bZv0NOJVawRyzjez4StAHS7ZrjJj0ES2YU0YSYzYgECW1+qdKeMscHrnFNxMIfi2TJzRfsaolQUJBtPLQUI0V620CEMldmhxqGlbCPN4YK3xkrXilIXVhT2u9P29pJ941tgA4/AuWn7lqLfsLrDiDm1sUoXPlxdLPdyk1kmKLuB7YARCZc+1rNWuzl1d2o/4GN2VF9OFkrmRhkzh8CMk2c1GByDwrah62K4reHdqqrfe4P+gGZMj2+V2dtze+QEPNwXbQV0XhMycLB/eCck/r6Y8uiVRKFBYHHxFw116/nnLviJe6PX/0XIIUak9mBeO1JPtsGugB6sUmyt1cRJj6EnQNC/1NYzDrvSZFF8hkhjtGA9cgOe4AJWkABG9k8jSFataTQlHOY69w8J0GNFEN7+hrkyqn4McuY2+3QnWC8mOFYZr2KtBOWMD3ZKsndYpXE3UN2X+cY/1uzupFTYA1NcYYe72zy88vxD4pQ700O/0l/lQExpmO1sFnWH6Li/cfn9k5/OatD1Zc45swnURB5V1MhZvv2s7JsSkQvN4FFcUwOYTt9WVrCLxF+S1NKQjqi++9eOsiXmAfVAbn8Sj47XPoONfiUwEqH0X1QMOJPrAFeXmTz+g7YPOC5+dV+CnCet9ON62j1P7hxkljJS7OPkca+tA+f5XGI6vESBHH4IyiXtinY+JyD37ZnXJtpBoelolBk3UtmKeqEnWm927IBlLzC1/2rvVkm7pEO6kXgTPWtla1mGnMwTDRY9CIhE7cNnMOlXZkTvX3Hb01/cmvwal5L4fsdAvJYdsyzzDoaGbqNkwk040CgJt3mPdhcSVsJmhiNLPfx6VZ0x89RSp1CQiOk0OBJqIuOsOd3hxKOvo9PjXcKYc5+2yYoPVCYuy7qqZy2T8MGjDaFJvMset8wHAtP4Pt6GdELaixmNeyJLfL5dLetBMsG4H2ux2LmQav8B8ykj0OVtjWteNOICFAHUsSiG5XqEje0FoyZFXi2F46TP5qPerBrUNFbocNe+bcamcbprt+Ib3tq/HF4oibv8xJlH5WtstDnrK7Pid/Ea8NOF7EW6u02FUsdq/rguHF1kbFGDE610tkGaAIbYzhT+fSTxfJ+anWMtc= 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: Nf1OKzOQDbttDWAyNybyY7L1f9R6MmvzAwxDALq6AxtNa7iqC5AVaFGgHcZeCOS45G2wNrf9tCQ0Ty4VcYFEdSror0ghg4r9UCjyvqbIHhLVGpc74O3W/RsbPrkS3ERmBaDpZFqS/2Y9jsRrhFzJsBPln1COOxPB37svTPwmbeVeOqLWdVET2qlUc8hXYvvovv12lLBUDCK0akrAS7X9/bZLPSimNoil8K7OJrtm6XlKg8vLDImz9+ynye7L002LKYtJ251wK6QEEPwM40h/K9VLzJCx7QgI5KGa75ITkXvUJ5xEgFJyvjrJbICR/lRaKgPSA9afg9vaK9sALKrc1UbhYFF9WmllmJnHM2fqBPqxSpfVNtMv7ofjRQYvy98UevwG22lQgUxlRlAuFqXrzxe2n10TB5iws8+7xZdKKgKyhHMiEHVMKJiIChRFs0kzLFswEmcHpIGVrbz+5VxM+B0Ym5cxyaQrDNlxxVQR1DABs6dTZ5e0lFmeD/Ycdbpyx4nolqYznpJTPbPbzz0QoYnO0S0yRtJoeXVIcUSdRiRSm1R0KkGIbdNN5TSDu8UFc8iJvic7okcvJ7kbT5cr8qR16VVM5zqeLXmsB3No/KZBlbAYk47k1wm+RxnWPBQC0M51FXmBAKhQ/Cn1ePQn1DwgHnRKBGeG/7ZoiumepMS2d/8T/KWU23/erFTkimmsZ94eQojiBxT6FvsnrMJILRrXorltrDU/lyr44F0ckpp4aBzouPwTytRklmsonqPwmNsCwGGTgHULqmM4jfPHcXi0Qd0s56UeR8apZ1vM1xIXL6CDDMk7MVmOKcOd1A88hOk6Q5M2anu17GfwgItJ+eJZkN5SpcAl7BqxKC3OxkSnbULCMDGPw1WLSQcEAAi0CLv6nssYN96i8jLw7lkOMdHX+5fkXKvE6e8Su9YEqgypgPVFl47kQJ9HgZifdVRUuF/2e6xkM1a5hXJY0sfqTd1oOgFziXCogQ1ZUeAbuMqu6MeT+Qez0UnkI26Hq5Dr/HqNx52AHJIUjuadIeymVpmoNsrbZ905Z/Wps8gPCJ8tPVJvGjoWokMDI5PpSJ1pcc78XlUILcTLC3l+zpxJpiS+Jp/4gZRcCCi7q4udjz73ysI54nSjbEKfdZXkz5t9PVbggE18qcAaI3UH5YOw+HbqgWI8MNMEQAmmMab2l8FkZRsUrMVO8iWz6Bpj7cOqBfgB3y+8AeCNB5lkoKjvsaXCanp9Rw8faEnu/fuX4IpjiEMdQzvKRKF/JnFjRndwAXYGluPo9+StYwM4NWgWcfUsHvArGaxChGtvWxDSQRcGdiTZmDBkAIt4B7baMxTvtoznk8JVmjH9SF3Op6py3CJBidWaa2vGmYLYDvRY0y3+kKHwfBKZUTlSyU3WghXMXW6GRr3xQdJ6OyLXu2R1wfEBEZ+V0M6eAXIzRh5WfqwxFKsh31rB3himDohTCWRPYPXrvHcAnPIQY+3S5jDApN+2brtgyYeqhAgXtcCdXOimE6UHKP2vOmtw6u03XOjBL910n9bgM5nfeTchnChz64TvI5RagnPL2AKjntj5TFEOTqEwfyPmC5Zr99qIFkgh X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06d981a2-47e0-4b6e-4b31-08dcc37c20f6 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 14:01:47.7181 (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: OAwoFbyNH1+rUlHs8jHGVm+giW5LE17RP/2zNqh0GuBzkLcW/ieFJK96/GoXjemFUAZa4xZWQ3LqVVfBRz6HIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY0PR06MB5458 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 887C5C004D X-Stat-Signature: p5ekqjp1bt3rr4u6a4zwcusqejrjw1zd X-Rspam-User: X-HE-Tag: 1724421714-226472 X-HE-Meta: U2FsdGVkX1/TpcKxiYr53nLSMYjyQ2w5ggQr70Zp3zBqLGqfQLsG/eaQHXQbr8MA6m9LacBXyMQ1quYWB6PoNhhZ7nzeTl3G7a1x0Exc0ia7l8pPpb1TPROIOWE6db8SNrhspJ846gr3TIE+/Xfon5Lg/2jKGsKNxJP/hHuyVgjIKakvfuGyROLMgTgsAGl6JJPanfXP7PgRW7K8aRI2TT+JOa6q4ddF8Ld/wxrOwP5s9JL5aBL7ynM80BiyX2j+RD4q4iP7U0NrW7MJb0KVauAhpHGDaQZyVZukkAHx8ndWt8iE4y82N3AsCoLAVz/fqOA8xwQhcMOxXudNTfq2gZYVpqQ8TnD7D1Pz2Hsvix2TtQZkhdbm2SmrVHh4wZwjJzMj2lmoVDjCZbBpUwB1mlm070pwpbEIkpu4etvAXu7r6OOYRLDXZ5xWxChJWeGW1qgg00dgowwT2DFXs1hasTryEtHkd92HC+550sEkaTQ7x8UdDQ9Nbazc8a7EKWgAi3GNLryLgdTwsWbxGODm72kKqLtXTSlmnv8OziPjhwXGZ3JNOSLNpM7CKjhglPOs58OWEPgivtojQldOsbY6RTOX12DNCKj7WV7vTyH797rJDFI5eNR4/Ufa0sapXFsJ4dDnJe1MFZpREr/hLRMcNKgFF793UNxWg12wYIu8zHs7VYYOQDi+u3XPtj7G1NfEvJF9B1rcw1nyLraqnmEB8PZ321JbKdBgZDpdGjKuaEK2Hz4ukygtTNSk5iOHrHwp4PmCCsOyiu4EgRKuU+qj0NKPw4FQtrOF99x5lIKDm+dWqj+uLGSDpPTppli/bvf1vX3tFifRl9m6Ld5h6XMY2IyDl07Y8V0mWYZMyQr2+jwNK9byGtZrJ/qloEevOSZo4FsqLH6pW1s7R+Qw3dHwd9um0fzX3kjGRT2rJNsHemuNYNK4vgX9jzU3f9+XhnNSmExPL5k3Ou6C+uKz2Ff Qa6MlbLd ERbjzqmWirrUO+Xx7G8Mo/sVPccQDeq+Qi0W7TCuvgPh0jEaHMzi+xR8OlBFxDVi4/ZL5tg8sqOIovoIE666BWtippCwbSHlTSTO5wRoFz7iNDQ/1z8SHNVB/IOXUlp7hXJCH9AFiUDdIcJQcT0wm14AajyZ3QMPpL2RIasT5Pi1uGGAh6/leqnpptJKVo5TgF+fJiZcucc9kAUH6+yEcAtag6HmBd1x86e/By20kQXNSk1p9fWe5kyGX4ccYGEbkOlGLe5Z1MUrF7GjTg8KnQUrdjAkDwa0QUsQlbRihfkxqZh7JukLabRqE3LmVGmLpHkippHb3b/XpSgcpk4qvcFpJ0/2+4n05zdQmbJCZDxjrVLhlrUyr8/1dbYYAThiBcpgv X-Bogosity: Ham, tests=bogofilter, spamicity=0.000052, 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 CoWed by do_wp_page, the vma established a new mapping relationship with the CoWed folio instead of the non-CoWed folio. However, regarding the situation where vma->anon_vma and the non-CoWed folio's anon_vma are not same, the avc binding relationship between them will no longer be needed, so it is issue for the avc binding relationship still existing between them. This patch will remove the avc binding relationship between vma and the non-CoWed folio's anon_vma, which each has their own independent anon_vma. It can also alleviates rmap overhead simultaneously. Signed-off-by: Zhiguo Jiang Signed-off-by: Lorenzo Stoakes --- -v2: * Solve the kernel test robot noticed "WARNING" Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202408230938.43f55b4-lkp@intel.com * Update comments to more accurately describe this patch. -v1: https://lore.kernel.org/linux-mm/20240820143359.199-1-justinjiang@vivo.com/ include/linux/rmap.h | 1 + mm/memory.c | 8 +++++++ mm/rmap.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 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..4c339c571ea6 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1522,6 +1522,59 @@ void folio_add_file_rmap_pmd(struct folio *folio, struct page *page, #endif } +/** + * folio_remove_anon_avc - remove the avc binding relationship between + * folio and vma with different anon_vmas. + * @folio: The folio with anon_vma to remove the binded avc from + * @vma: The vm area to remove the binded avc with folio's anon_vma + * + * The caller is currently used for CoWed scene. + */ +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 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) { + anon_vma_interval_tree_remove(avc, &anon_vma->rb_root); + /* + * When removing the avc with anon_vma that is + * different from the parent anon_vma from parent + * anon_vma->rb_root, the parent->num_children + * count value is needed to reduce one. + */ + anon_vma->parent->num_children--; + + list_del(&avc->same_vma); + 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)