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: 13911086 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2072.outbound.protection.outlook.com [40.107.223.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1860159209; Tue, 17 Dec 2024 05:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734412462; cv=fail; b=l7WBEKBxagDKSo5iWzFi3XGdLrkWGvUm3rOKW72lIXiyjwBP2i/CIoaMtQopVvd70U5E5Cqzp/a2g30MGSCA7pprlvLp0aapQZsjzEfdUYKth7bAEVf4gdF//yhvnHZNEwiweGeR525JnTQyTmUGlNnpjHqEfJEp5SfiWO/TJDc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734412462; c=relaxed/simple; bh=gOr+LtZ2BWl97cf/723vrNY2Bc5lZNdEix/RTY98ThY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=RiE/3MUf+96RC/2KoSRCG6Xlm+Q/JTA/8VBR1KnT0WsJ5K458J5VD8axgeuTFlQio/swJKGfce432QO9cSipDF+xYSA4sdigtyYp+74cj9OByCszwhYn/K8XvMO7IOt22VdFz2Sf5rslTvhg2656MJQ2sTSGnxiKnaNKpkyMRBc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=iu6rqgx0; arc=fail smtp.client-ip=40.107.223.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="iu6rqgx0" 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) Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: 5yu4rWVKZhoBQm9DHXKG9uR4mYRWXvVeO0qKBKrbHBjUPxjWbNGB3cOM1iTeDX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4e7kKYK4YX8KyLWjxs7hn9sTuWczCob5bOK/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+IUNbwVzB0OrfmdvaaaYbHxdwHAZxFkIg5PBXkBWRhL7j8rWXidPa91UdZFy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08dd1e59a75b 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 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;