From patchwork Fri Jan 10 06:00:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13933824 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 420BDE7719C for ; Fri, 10 Jan 2025 06:16:20 +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=YPkvu0HOcKU50op5xWevlI320b4g9MRTTEsTmpTzyxY=; b=0D0V+TbFtyoEhNvllSln68U3+s 1wi6X1kyxc0+Q91QGcRMZvn5MWi64HpDaU3cWPOqyxXmjf6BNNEizpre+G/TuaAjylzY8A6MXZ6/G unW2Rod0K/bBEhkLz2hVDZqCbwITw5gfu3WZ/l2RtOel9gqBf5c5FwOzcTYNtGPJt8dx+sa8UddcX HBgbdwpfH3aU7UcxzLqtINGEt+X/aXpw015YsXdr7Q52xcazT/giGS9+5/uA3i+FVeWT1lfhmb3WG mq0v3Utl+AXVyw1CU5pvKk57LaNWRjlyh6xUxS8lYN0bcwJG+wX0amSZGpw148fpDY/M7pdeCAZBb Syeiuzsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tW8JQ-0000000EE3U-0CY0; Fri, 10 Jan 2025 06:16:04 +0000 Received: from mail-dm6nam11on20623.outbound.protection.outlook.com ([2a01:111:f403:2415::623] helo=NAM11-DM6-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tW85u-0000000E8jG-0L1B for linux-arm-kernel@lists.infradead.org; Fri, 10 Jan 2025 06:02:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dpgpcDtj9NIJ4NKcih59h4fIsYxKsBW7Un1o66uxjW4nSR72vHpN4t+NIS1bO9tEr2611rbNHkVLV1UL7hdwSOUbWrhXvxZe9TOVx3PUsGL04Ru7HQG4iEz9d+RmsZxNMvEHeM86FIMXxFJUqXmopQ0w6Ou8uMevhQUgtBSRlsllX5X6uMSh+58brTDdqa6t+p4S61CQSJXSo9iFKHyjDM0JLWo5zNXiW+BSrGAoiEPtcROJ9H8m+kCnwCL9zfTucfOz+1gYvPynWeCs0r4Ng6LlxG169mZRBAWc4t1hVvluxLCbZlAk1EzH9Dm9vJDQh5gCQfEpjWBzCyWNzKYDOw== 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=YPkvu0HOcKU50op5xWevlI320b4g9MRTTEsTmpTzyxY=; b=Iig8ID6vJT0cs8GBKuzdA7EKXQSt5ysTYvQNF2kMOVuc5UrM3DzfJy6oV0FKBS0bdRLrk5O7T5ZJiuJls75Ad6vqRFScti826zzrMk1A9d6PJ45NHmlwWn0Ou+TxNhyLJ+5Jxx9AKEzI060L+pWTvw+Hdx2o2fdwGQlkddxXjNhamc95T60dvsGRyyxFikECdlYy72cJTy44YPBTRgohLDkY9gP0Z+Orwn3aUk0XaHeD1G2Wl+rN3EvFum0R8yqG83WrS5IA6W62EbieuWXN/+DFouGjyNUqhpWqK47a23/t4bLbM6l6H/u5ZejLrqb3jGGEAj/+alzVcrnxmtA2uQ== 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=YPkvu0HOcKU50op5xWevlI320b4g9MRTTEsTmpTzyxY=; b=YYBoUbdSwK49JmV1OZyEzZLXA5CbTgYJQWkmhB/lEWZcjEq02UrDWDJr2ebkq5x8DAuHchch/pDYTxzb0pq/ulpkvznf1Wpr9DOJix4CzDGbc7twWiu/mX+SvBVgodJE/B9qfunK/poEmGRokLYolLpos6kJNgBkpcPxC52mCE9ap4962PGg0joLB7csq09cHmHTr00kIVL0GtJjEwxwbtHDr0imgzeQtBV+f0IjOaa9vrE6fIY4IolXzFBOIPNiGIzl8veKjBYyqmTC4zyHpRQDdkDZstCZgM91nFkfYrvqx/SJtZ6FLUa8Pc+GxRBc/cUpfDK+3CDw9+yHvRdXpw== 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 BY5PR12MB4132.namprd12.prod.outlook.com (2603:10b6:a03:209::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.10; Fri, 10 Jan 2025 06:02:02 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%7]) with mapi id 15.20.8335.011; Fri, 10 Jan 2025 06:02:02 +0000 From: Alistair Popple To: akpm@linux-foundation.org, dan.j.williams@intel.com, linux-mm@kvack.org Cc: alison.schofield@intel.com, 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, chenhuacai@kernel.org, kernel@xen0n.name, loongarch@lists.linux.dev Subject: [PATCH v6 08/26] fs/dax: Remove PAGE_MAPPING_DAX_SHARED mapping flag Date: Fri, 10 Jan 2025 17:00:36 +1100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY5PR01CA0062.ausprd01.prod.outlook.com (2603:10c6:10:1f4::6) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4132:EE_ X-MS-Office365-Filtering-Correlation-Id: 7115f0ac-8193-4a3f-3824-08dd313c4d49 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: EBk6dRc/jy3c6e46fEn47r2oLMWOFsk3GkgheYwIJ6hQ3YZgw2Si+/oJe818HcxlejU9V+V4jOilo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KRHSNYA1HHOWWOx/exKF7lYBUEsTW73HEPlRv67SwqFG75pb9icLf9/3cK80hYpDaqFx2BYyOcRoMf98+0plxjR4KyFp4TgRMB7KPI6eiRvSFqJNNUga+42YYIx3MGawBL0kTykDTsIjGX/fCb8l+wQ7uq+i8+pY+z4Ym/X3IFd1sUuPAuWhdIVWNWKmoCivCbfyjDbbAZPNacndp4nGesw/xFnR8ctPNo7jdjYO3tgj39MASxI3yXA/HOn 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)(1800799024)(376014)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ogCdlVMVtd8OQJVX669PMlHqobJNKo8lLb60ZvzUNEf8V/T7vqZmwFHIP2T0cUb85oNL0y7HnVKSIdDy9qu/L1EBwN9re+Occ13Cy/Yqod6egKDCO/8q8IFilCIfMO80Q0E7FutRns83UK2iLLiyOJxZS9+to9u1h1CPzLznFNC/+LW1GBYflZuI0/vUdXUytzWGMKNqvN+7AqFcxoHdRz3F6rrn8+uIoY4vcaf6p3egzanLhfmTprweyag8Ddu6f8md6iOkFY0HxC3HRi7IYWOyYhM4HyJBUtL5hVLuj9wgEOr+yLSmppXz+MFU6zjIMmHy3OMGQgpq6L6d5f5euw5X2jE401UHiEDIleMMdz+JpwXVV3v6VlK8biJfNy3xbKpWK1uTkxNcXJn4ZPcawrxYeKp95hmRLzcOjXIjznG4UZrPRb+vk0muC4XLdft/X1qXMdQw6EXM+xPkRCGXaPp1OCyNyvPCpHmJ19rlKU5gSUg5rnpKaCv80fI0SSmJHXWLCJHsyKL68Al9bTMDm5uhQwvWuwDf4X2eaCC+T1N/av5qPYVKEihUQv9WZvzlYuvg4wBVbQ0rElBpGmscno3oasy5W5uAKhTBfqQbS4JYgiUffC/Nf65LI7gFrA2ODKNM8838vTQH/fj1erYY0SCgURB5ywGoQyeEfVWJxKzDZZ6nf/EjnOmdhfpMDD6Upi2v123Kk/hdqWi+M346wMYzSn8cM1AXhL0gM8zZtB+Q4hDBDr/RqfznxbD6s9RgtMcogW/9TeIXHSt763Nss2O6DJo4OLbt0dyjSbqQNkHeRj7oN06Jd05+1syThWcPb9a/tGlYPV/2aHxoPPV8zXCujpQHcAp6AGbNu6x6GLMU+IZwNeI9zBtgwXUkF/h9tvTiUjuOHciBYAQp590JuvFDn6C4oT7/CnVzSU+SuSyawpBMzqIhtMN79Nf/91rz9gD4v0d+E6UP4lNY9RK6sxp+SAKix/JlyJt/xWnOScJZg1USwz81+DO61ole4JUptWkhTkjyIrcV2FCvzOCp1rLfln3++wyHaRMknIGH6aZnL1tijEr3fNUUV3qSg5SNmzgTz7H7XwUeHzefrkEjw8JVOPHPSuq9YS7FLMS6t8M/SqZ0zru97ZY6uNQXPA506y5E8oOpedILkJJqBP3iehWF6uEsfLWb5WiOM6ke+JAlaW3ZxG+t8iQLD+qQyCwgeUJSilmyC6730ndAROZsw7Yz/nAVeRLb8j5tN8w8K0QUFBg1855bquELKQYgxqdeGwxeunbWI8GHXdvMBCYN1xWPO5q4EtmP4be6RrgKX+h9dXnKtxXeTSDs8Tzi8TvhXb4ayL/mR7zhMG8NwEAAz3hmUtW4FKeFV131C06zcSOzO9rBNLMyThFQ803YLh4Sf0pg0Try9O+zjq9Mu7XQt7SXdqbqFnG6Vc7eU/DeDqpxDCPniBHpPzyYZCMC1VhbA0lIdZRSRma9dZyE80UpxcIl7ApFj6ScI5sQj3iO1zkVQgbDa0Dl2/sU5ptYhupRM8vthYzy0RDSGJCePZHABSZn4dYRH9UouG7x3Otw9faFJmkIVWAvxGc+7ps2cI8k X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7115f0ac-8193-4a3f-3824-08dd313c4d49 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2025 06:02:02.4099 (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: NmYHwA4/8tKbsJZvmJkGZSxL0RoJY8PPNBgFSyQjKAa5kZLq3dzMrymXZvhbzMlkhXAyswrueL6kOFkQlErEXQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4132 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250109_220206_124165_D4F29E5E X-CRM114-Status: GOOD ( 23.84 ) 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 4e49cc4..d35dbe1 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 is 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 to 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;