From patchwork Fri Aug 23 15:02:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhiguojiang X-Patchwork-Id: 13775349 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 67297C52D7C for ; Fri, 23 Aug 2024 15:02:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9FA61800A0; Fri, 23 Aug 2024 11:02:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AA198009A; Fri, 23 Aug 2024 11:02:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8236B800A0; Fri, 23 Aug 2024 11:02:25 -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 62EC28009A for ; Fri, 23 Aug 2024 11:02:25 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1FCD181D79 for ; Fri, 23 Aug 2024 15:02:25 +0000 (UTC) X-FDA: 82483826250.19.49B1E10 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2046.outbound.protection.outlook.com [40.107.255.46]) by imf02.hostedemail.com (Postfix) with ESMTP id 3B3D280024 for ; Fri, 23 Aug 2024 15:02:19 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=BnHfmEsl; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf02.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.46 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; 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=1724425260; 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=RNEg2GC57LLqhzMbirfeDKLwUKK/mTP5oA0snNrE9N8=; b=CbGI63z7sROStKvtRiUYOvKnX6ctAThU9h3boVBqn+6P2FpHPtKSVWjZv0BLqZHa/cRrTz XkmncIFhN6If8XpekucYY0kD6uEguH6WlzU/d/7ljEJRyCPGQv0auauIvfmItTSBEhQ3Bs L2qp2LLceRZVv1mihD9b+6rPNQmZQnc= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724425260; a=rsa-sha256; cv=pass; b=SBLIW199jOJ0xzJcO7qzgZUQ0zx0lh7iMrhVP4mtkWCHK6qY9YyZmLLCOHTy7g655I2jSt VryunWVBF+mXDKYAt/RppIhrdSlyvRSa9JihE0AGUumiJbhWjNrzEFLMjYysfF1j6j5ajW TRcF0IiUkDZZ7zJ9evEO1moa//+r0l4= ARC-Authentication-Results: i=2; imf02.hostedemail.com; dkim=pass header.d=vivo.com header.s=selector2 header.b=BnHfmEsl; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf02.hostedemail.com: domain of justinjiang@vivo.com designates 40.107.255.46 as permitted sender) smtp.mailfrom=justinjiang@vivo.com; dmarc=pass (policy=quarantine) header.from=vivo.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mqs5ovMAK44EK2tbepQhHrOM0G91iSHIQWyvuSh8UQxBB65JMqiGTAHVGgWgrbn3H/uEkwRV+8hc6YUTiJKtzwgBXl80PazaFzOAHL1iuXu2EVZ2t0bF59VdgYNPfHncq+Xm6MH1eagItwOfEoCzoUla2S2q0NDeoWoBUfXT+WBujEe6chY758g+cD1dS6l9hgzp1j6g+9VJ1bVrNqiFNFIFFvvYQPCdUh0wJrPC+3gbk/iJ3XzbAfNiS8J57yxZoP4mCNlCldbYf8vBdDJ6rOQxw7EHnwCxrmYt1h8CGdI1Sb7pMcmdd0v2eSJkI0NGKfauiTAqBbtUaZHMeMrWTg== 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=RNEg2GC57LLqhzMbirfeDKLwUKK/mTP5oA0snNrE9N8=; b=u7cQYH3XiVKEGGAjWGXCWN7fZjSJwXSV2NkwLld9FQZCq6jKkIP093BxuiPz3DS+A43NzXqMsXWhyXI504WhdpNpk09IxAaYun4e2lRlew6PrSX7Sx68hlelFfyDQTnNM5JglaGWrqWyj1wdDrBURZkmecFs+san8hwFZIOMDsNZaGRe/A2rPcJgZM9yRCwlyKSuBLoAIndKNCAqyscppYRfhdrk/MaXk91eg5mhJ8QWRauNZ1IUtssNvvV/HP3sbC30D52triEmdKZnLi6FXQUx4QwEFyRRH9dJ3gw4y6kcClGaJPXqG/nVKcL4GeK/C/lXgFlO2BLPOuLeeVmFYw== 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=RNEg2GC57LLqhzMbirfeDKLwUKK/mTP5oA0snNrE9N8=; b=BnHfmEslLYHhPDxim93VaUuqZxxIjBiGPo5VXhF16PQY7Pbk1iQQH0wZM0T4meknL4k7x+Gtyu4uYPizLwHCVIVD3TsalgC9Co/zJiuppiRI7+XIYk3OOhIgaelReg2GU/p8kuJkXTxzsDqrzwzv2S/lvk1NS4J4TYpE/u9JBkt3DXnj57dOZa8n5PSmf/zaT7TA3/+i4lWZkkTXfyE14N9308RGStysSaL1ljoB/kMw9JsWTybsSnEL/9OYlNHhu0K9uwcefFUsctcVR531eJcf4CXGlQurptsKyHH3waQctKLDqkzkCDGkhxdQYLQN+m5z1TRvhVCgfZKNhNoKaQ== Received: from JH0PR06MB6849.apcprd06.prod.outlook.com (2603:1096:990:47::12) by OSQPR06MB7249.apcprd06.prod.outlook.com (2603:1096:604:291::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.25; Fri, 23 Aug 2024 15:02:15 +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 15:02:15 +0000 From: Zhiguo Jiang To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, oe-lkp@lists.linux.dev, lkp@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 23:02:06 +0800 Message-ID: <20240823150206.565-1-justinjiang@vivo.com> X-Mailer: git-send-email 2.41.0.windows.3 X-ClientProxiedBy: SG2PR02CA0101.apcprd02.prod.outlook.com (2603:1096:4:92::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_|OSQPR06MB7249:EE_ X-MS-Office365-Filtering-Correlation-Id: 01f642d9-2836-4aaa-c341-08dcc3849303 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52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XOoJlIGHVNmvfpv85Czecgw2/zWAlk/gxyt9SPU/yes6pmn6hqRc85rCvkUdsF2VrVKUP0XXt28guYvy5ZDxu4wnNae3TtnX8d7NsB1zh2gkrfWP20x6iNAMJrqgDsKBcL9DhebM8fA4szOlfe1j19yKjObb7uISwrNkHPsWx0pHa6N2hJf9UXdSgYiXMyIvKDCJT+2CP+RRKYa8KU+wyfcxvouNLuaVWe154xjPthcpScMkfdD8uQrRC1ar9KDJo0f+8dsb9bTGbxWfQNVZ/JbNDBZWyxTto/r/M7ivEAAmG/YSx3PZ/F8LRQdoCr0DsaW4CNLO1ObOarwxLAYyZzXId5QbE= 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)(52116014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cQRhXZet/gNRoVAGyRJBl7zS5xOH9NpSDgyZHk+Tr/ZSpkSLHcF7FRuITg1vVPS81Ypu42MS3IPil/R0SbQjktb4mdAGzGMC8xAkR4KdVJZJDLBkvPtYptZ3T7vX6AQJNyiGJ96GxWp7XoUVcH01O79pkkffW3uCF9KVelbHzQv1OuoYkTXcAipZ1uL9SIxPiwAmzpCWg1GQA8Szb82s9iQMfQG6G/nCbpCUouQapY/iPq9TfuT8PSMpP7d6o8GHjBXYZF5ofqXTZGpKzJ82aa4p3O/zIjIOquQcuVHJ8jhN7hPhRAsXDj2pXlZixaHR+w/k3V/o/6izf8BuBEy+U2A42rkaWDqjcNAOqF3h8xIa4TZPezj9n4aq5oQ0Be5XbKxp6U9aN+mFRCbVYTAqK2474oDT5a7H1kjC0tAb/TKSf+r3vL9OBstSIbCI/utRv8IM+mY8gPl4pJYna/fGz+H3sJmXmkWJgh/msBaylhayUbfQsNivi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of4M5nyez399tmD8bPwpldL/+JjdYTW8YOP6dFvZkQuo X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01f642d9-2836-4aaa-c341-08dcc3849303 X-MS-Exchange-CrossTenant-AuthSource: JH0PR06MB6849.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 15:02:15.0644 (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: b0zpP2yOZ9gcVRCufYVLBqq1HIKJpydzwWxWXISiNUaE4uht0EiW64wn9BJ8boP8GCNR/oZV2/VI5wZFvabkiw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSQPR06MB7249 X-Rspamd-Queue-Id: 3B3D280024 X-Stat-Signature: a76myrhs4zr56gb51wu69zrhy9u4j4mo X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724425339-163216 X-HE-Meta: U2FsdGVkX18q44Ox1DM8k+v1nbMASrdBmNrGT11IRjMFceD5exJ+Rf5A1Rt+H8zirx03ytTq7dWKAkH648pzaYuCeSmkMaPEEErTPpcKBQ4TdDs7wiTwkJ39vQofKdrJoBraHW/kP/6wyppUnX3UOLMNVpsODP3d5KO+dlIEO2ub8c/wxbQKpQ+fRwNy1rG7nB4wqdSkEuxc3hkEIqNOshH9KwdOCxWDKxfDwuwTsTOYc3gpl3+1aHJ+z0jy0vHo0DVwdIQufrMSVcnov3uuqblNxRyLkinVEI060vVjY6DtXz1MxKqVkewq9EMXL/OlmK3dfB4ErAE6vQVUhzb9rra0CWeLw2wfVcxwc1GlP7HfOuv4hrhZdsUqpvXqISN1Dpn7ht5MGJiM2sSH6Qw0OKIjZDnIbfFes2Lqsw8n4RU4qYbBrdzSepabnNl4R+W816eMb94E6xROeV3ISQqf+BEfzEcQH/YZSiMIdQmlytXwRBCgl4GK3gVOv1pXRTecGBFDikFdpPpUDlc64wjPluOA71Fqy3bmzikh6sUyR2ImEap5yjf+7xkS/xTQQ4yvKwkYB1BCF3/9BTmpjCSSlgFbUWptAfYKn2LJisbIKb7JXNvPxgQj5tMGtQ8bZ7ZOWqotN8t4MGQd6NZE/OACiAM51mNIaIpCqJ0hHZuMCPbHV5xWBAzOJg08+RIcq3J/GOnSZpvnPxERRQly+N+SdoB0t1JAB3qNbM+mn7yg+PSDUaFtIgtUFyOrehlNuSMzOHeXqVEuRY7iEtglAsb9PN90qDx4KWZ71fyCMgPcTHi8EcEvoIQK+A4VqKRcOxw4FA+6OfLEMh75NBonvVmLn4QwDbzoZx+EGPCRfVOXMe9R9YY8zkMoYqOr7Dnp87PQEnPnGf19PBTgaJ77DS3uP+dHwvAvhvWn8vcKPl2v79ikx08dEDzGZRrRXlRHkmS5OLD+/xEBHSbV4tx8MeP JZsx9vep j0TrVhPGjziNn9ysLKZEujkKzLeNysUeQH2gWlcKWlSA0pcd2kggtJrtLc9ozZtofIuNRu7YJBav0rOhQPDHezd8dtm8RTuWRGQXG8i+CwvMNR7e8iC1jQREzfvQfuyM/sZnW0vpfHJ+jAVpefIJhjgcQZK5UEIYZKLDf98HYstLbCQT7YOupSIJpRuoY2jGvGNDOpQmKNhaMDN7G8dnXFs4PgoU4ZKsMVlc2RfQlcrR7SOj2WEwOt5C5/nNmjvFhs3ci0U8BQOcbjE3Ub6u3lB0E5M60WmR/l4fri/8vFMUgxJJ0XEkvIJcwAN9OlK3JV32dERbyKYfBdzykkU7abUjn8BCtWOj1gGtaUsuYwlbsCBM1jBy3XNlQsu9NPTzy9nC1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000030, 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..56fc16fcf2a9 --- 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->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)