From patchwork Tue Dec 17 05:12:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13911112 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88439E7717F for ; Tue, 17 Dec 2024 05:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iOElRdwa5q60T2DYAegK6z/BML32Imghect7PnnZP/4=; b=nQoLE0KTYVYZiM2yAV5P/AR0gm ZSQ/4ezZJI7L52NV5VnGG2C0DC3bvE6VGRP9mlVcWJuNCVyjWgrJKsr77z7rMJIvhxmDNksNXgmiy 3kZHgiJUFoGBO4LT8nLj2x1mVIUlEv+ymDZNdOlG6Ch32l7XcWVDy4wX0xtZaA75ReEyS102YsRto PzL9ZQNRyxt2eUD/UvJt2gv9npZrQWEFdlq+wR6SGCA4ZpOztoQwMEmsAPTt/qUIZkomTGORfqkWA 4wkdiAOQb9d4YRvIHeLzySMdMhtUEnCYiv1JisjbZTLAcGWqmXd3510CO3t9pgGS1pCbVJWJdK91Z zgMLbmAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tNQ3L-0000000CGTL-3Ly2; Tue, 17 Dec 2024 05:23:27 +0000 Received: from mail-dm6nam11on2062f.outbound.protection.outlook.com ([2a01:111:f403:2415::62f] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tNPuW-0000000CDGJ-0stP for linux-arm-kernel@lists.infradead.org; Tue, 17 Dec 2024 05:14:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xvQ75chR9Rs6DnDcP5+YmUI+aoYwZCgFXUYdjL+2iNV8F8vjUchkjwia1nmFWKkYbCAgHEkqvnS1uTl4aOtD2C9qIW1TkMYP6Y8mioyhxvWajNq/ErjlvG99/okH1t4pTFEYx9xd5OzH2HOtqiCV0VkE1nLPY1uJYSOi5GTLTIDdG9vFqDo3orIi3B7/R1WzLYUnm3YxDJiPisQyiq95kdGs9wla6wq48mXbSiLGhBOWkSmLCaagcq29FoQXfzjC7jeR5MMm55ZtK0CG9Bo3i7UQdJbJ51C60Yk3/M5179maVlQu4TR0HRCKuQm1P8gSQveRkmjeCWOtTmtQaEFkyQ== 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=iOElRdwa5q60T2DYAegK6z/BML32Imghect7PnnZP/4=; b=j5xqqOHgG6FHt6yLElfPrqJ5w8s7ZeUEF82FIMHYVoDKVSeFo8NfQaetENkjkYqydLJ+d6Y7WOKNZkbcnCm8rsKrx0Ac9/KZsdR0DCzGAYlLFVtiWlho+eI+uS0k576POO+3jTM//cR5LJjpyBPgGR3pQNIxV8vkp8hNXPtQfNXg22uzLQP1aiWvhXZRttqlRtAz4ktcoSFtCtalwLik3Njbjx8f5qqhX1XbkNmK+EZE8093R0xxFLBp5RNUZzmxeg0s8E5pY0XBrUCNznnDgCrbWTwjndf58Sde7VIevyTL0+4Laj97chmw9FdFZnsz88y79cVhOteVZoNHx5tLwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iOElRdwa5q60T2DYAegK6z/BML32Imghect7PnnZP/4=; b=iu6rqgx0gtCMuSehxVPgZmkYXrwM9N8WPsGAKU2zfe90nxAvzvTFyUtYqhvZKIuSMJ9i9+lRcHzWtMJeQin8y9FKzMQ61jMay/FPCdum0yd0xQqc/Pe59z9VU71mAwbKJnYJSEzBDjcXBskeNVcIuJaGYNePP+TSfyokTm8BUdRGF82IA91Dmh1Tu68mCTE8nsY15Kx0YlgWM+GVsJbDJ19kBhjJeqbScW1ccm/3RJEhhUzMJh803pkEwD1Mer1S4h1eytoPaHvptu4tmr19nGY6LhY5AQ5kBEJR1AvoRs0xUrppYOVk6EGxU//r8Htox74RXJCeazAGMpCQWuWCJA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by CH3PR12MB8936.namprd12.prod.outlook.com (2603:10b6:610:179::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Tue, 17 Dec 2024 05:14:16 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%4]) with mapi id 15.20.8251.015; Tue, 17 Dec 2024 05:14:16 +0000 From: Alistair Popple To: akpm@linux-foundation.org, dan.j.williams@intel.com, linux-mm@kvack.org Cc: Alistair Popple , lina@asahilina.net, zhang.lyra@gmail.com, gerald.schaefer@linux.ibm.com, vishal.l.verma@intel.com, dave.jiang@intel.com, logang@deltatee.com, bhelgaas@google.com, jack@suse.cz, jgg@ziepe.ca, catalin.marinas@arm.com, will@kernel.org, mpe@ellerman.id.au, npiggin@gmail.com, dave.hansen@linux.intel.com, ira.weiny@intel.com, willy@infradead.org, djwong@kernel.org, tytso@mit.edu, linmiaohe@huawei.com, david@redhat.com, peterx@redhat.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, jhubbard@nvidia.com, hch@lst.de, david@fromorbit.com Subject: [PATCH v4 08/25] fs/dax: Remove PAGE_MAPPING_DAX_SHARED mapping flag Date: Tue, 17 Dec 2024 16:12:51 +1100 Message-ID: <0aabbc2d9fe4d136d5a7458c4fa55e4b139a0b5e.1734407924.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY5P300CA0019.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:1ff::11) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|CH3PR12MB8936:EE_ X-MS-Office365-Filtering-Correlation-Id: 04de6dc2-e910-4119-7f7f-08dd1e59a75b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|366016; X-Microsoft-Antispam-Message-Info: 5yu4rWVKZhoBQm9DHXKG9uR4mYRWXvVeO0qKBKrbHBjUPxjWbNGB3cOM1iTeDXs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e7kKYK4YX8KyLWjxs7hn9sTuWczCob5bOK/YFg0sLbgGkbZtaWb0dRoiNIYEfPqkTAX/uzJpGWuMUrOjurrkDUFP0oHyGuyhec6u1dN6RDkAx/Rv02rWPqXCkwOyByQZ8zttldatFmsH5n3uC1NSy/yYIZ5JXvHMLDUU5dH00cowgqEvj1WR2dEUW8eCydVRQ5A8oYNKajWVnpLizH/EHOO00nucEr3M8wSNQh95WGvo1ygJy7YNoLZJrMPgTygtKwIktyGGZ5TogX2DrI0RT X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB7726.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ovB069yZ1yX7XZxqJLwWSAKK7KqjDf5q61p56robh59VKk1U3mULgyU0eUivyZ3LieZ2IOIXIi1D511r2t5PLJCkOH4RsjmpkkMiVoPrQPYc3tCtyzU3LIcQhzpKPYkmhnHWnUDhAgFaoAfMfJqwc2zfn15C1k4h1gcVmqDa1O4ZUnugKVDP8OJvDjebCoDmiM/Nzi9u4bETWR845hdYLfbri9zpL4lrt4VAqJD438zqMj/T+MxQKvUPbXGhbgK4haYPseuq9reeT6fO8c5mhAjigVl4Fo6x6lds4u/b+IQzfGrNtVkVTaPeokB9xs/x1Le8o+3aVB+dI/7RMW1lMiokwYVCpGsan0PGDOR1sMeEgMkzbtmDkNjpXaL/NiSNrMkTO880cIFopcbMdL1jbfTvy8I7/FHoIfig9273/AFAOCsPCQuGZopjJMDIYniql61uSUSUJLrit5LOPc/5OMkVybH1PjLYRVJZrdNHgK30WNWOq57LEtuj9z2ECSCEyy/849WFFYv1zUkkTzbZR8WF+IUNbwVzB0OrfmdvaaaYbHxdwHAZxFkIg5PBXkBWRhL7j8rWXidPa91UdZFyI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dd1e59a75b X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 05:14:16.8238 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vMrtWozpPjwXs4Ov536S6P9hvdpxDPzlUzlm6Zg/XcCdPFIW5xCr4ShEgG0urVfMxQ9iqBG4yqx6lBR6HLWPZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8936 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241216_211420_249777_A82E4D6C X-CRM114-Status: GOOD ( 22.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org PAGE_MAPPING_DAX_SHARED is the same as PAGE_MAPPING_ANON. This isn't currently a problem because FS DAX pages are treated specially. However a future change will make FS DAX pages more like normal pages, so folio_test_anon() must not return true for a FS DAX page. We could explicitly test for a FS DAX page in folio_test_anon(), etc. however the PAGE_MAPPING_DAX_SHARED flag isn't actually needed. Instead we can use the page->mapping field to implicitly track the first mapping of a page. If page->mapping is non-NULL it implies the page is associated with a single mapping at page->index. If the page is associated with a second mapping clear page->mapping and set page->share to 1. This is possible because a shared mapping implies the file-system implements dax_holder_operations which makes the ->mapping and ->index, which is a union with ->share, unused. The page is considered shared when page->mapping == NULL and page->share > 0 or page->mapping != NULL, implying it is present in at least one address space. This also makes it easier for a future change to detect when a page is first mapped into an address space which requires special handling. Signed-off-by: Alistair Popple --- fs/dax.c | 45 +++++++++++++++++++++++++-------------- include/linux/page-flags.h | 6 +----- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 34a7690..6f2d1de 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -351,38 +351,41 @@ static unsigned long dax_end_pfn(void *entry) for (pfn = dax_to_pfn(entry); \ pfn < dax_end_pfn(entry); pfn++) +/* + * A DAX page is considered shared if it has no mapping set and ->share (which + * shares the ->index field) is non-zero. Note this may return false even if the + * page if shared between multiple files but has not yet actually been mapped + * into multiple address spaces. + */ static inline bool dax_page_is_shared(struct page *page) { - return page->mapping == PAGE_MAPPING_DAX_SHARED; + return !page->mapping && page->share; } /* - * Set the page->mapping with PAGE_MAPPING_DAX_SHARED flag, increase the - * refcount. + * Increase the page share refcount, warning if the page is not marked as shared. */ static inline void dax_page_share_get(struct page *page) { - if (page->mapping != PAGE_MAPPING_DAX_SHARED) { - /* - * Reset the index if the page was already mapped - * regularly before. - */ - if (page->mapping) - page->share = 1; - page->mapping = PAGE_MAPPING_DAX_SHARED; - } + WARN_ON_ONCE(!page->share); + WARN_ON_ONCE(page->mapping); page->share++; } static inline unsigned long dax_page_share_put(struct page *page) { + WARN_ON_ONCE(!page->share); return --page->share; } /* - * When it is called in dax_insert_entry(), the shared flag will indicate that - * whether this entry is shared by multiple files. If so, set the page->mapping - * PAGE_MAPPING_DAX_SHARED, and use page->share as refcount. + * When it is called in dax_insert_entry(), the shared flag will indicate + * whether this entry is shared by multiple files. If the page has not + * previously been associated with any mappings the ->mapping and ->index + * fields will be set. If it has already been associated with a mapping + * the mapping will be cleared and the share count set. It's then up the + * file-system to track which mappings contain which pages, ie. by implementing + * dax_holder_operations. */ static void dax_associate_entry(void *entry, struct address_space *mapping, struct vm_area_struct *vma, unsigned long address, bool shared) @@ -397,7 +400,17 @@ static void dax_associate_entry(void *entry, struct address_space *mapping, for_each_mapped_pfn(entry, pfn) { struct page *page = pfn_to_page(pfn); - if (shared) { + if (shared && page->mapping && page->share) { + if (page->mapping) { + page->mapping = NULL; + + /* + * Page has already been mapped into one address + * space so set the share count. + */ + page->share = 1; + } + dax_page_share_get(page); } else { WARN_ON_ONCE(page->mapping); diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 691506b..598334e 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -668,12 +668,6 @@ PAGEFLAG_FALSE(VmemmapSelfHosted, vmemmap_self_hosted) #define PAGE_MAPPING_KSM (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) #define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_MOVABLE) -/* - * Different with flags above, this flag is used only for fsdax mode. It - * indicates that this page->mapping is now under reflink case. - */ -#define PAGE_MAPPING_DAX_SHARED ((void *)0x1) - static __always_inline bool folio_mapping_flags(const struct folio *folio) { return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) != 0;