From patchwork Thu Apr 11 00:57:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13625222 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 14E0ECD11C2 for ; Thu, 11 Apr 2024 00:57:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88F2C6B0083; Wed, 10 Apr 2024 20:57:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 841676B0085; Wed, 10 Apr 2024 20:57:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DFD86B0087; Wed, 10 Apr 2024 20:57:48 -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 512DC6B0083 for ; Wed, 10 Apr 2024 20:57:48 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0B1E11409BE for ; Thu, 11 Apr 2024 00:57:48 +0000 (UTC) X-FDA: 81995438616.11.B68AA14 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2135.outbound.protection.outlook.com [40.107.223.135]) by imf12.hostedemail.com (Postfix) with ESMTP id 4F50440008 for ; Thu, 11 Apr 2024 00:57:45 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=OdkJBitK; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf12.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.135 as permitted sender) smtp.mailfrom=apopple@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1712797065; a=rsa-sha256; cv=pass; b=kzmU9A0Mn+0Br3F96+L3LEJnLg8MBwqL/iHzkH8/9qTHpb92GnBoWZlBG1Fxv8gf3e7nEw Td2Wvr7lyMkoI/Peg7oUSgYU0l20S8kQT6W2nauAAXs6Ay1qAVYjXCPGyihXZ3gw1upT6b OL5BLzibB5+vzg8jtZ3ZrqxzvFdadcI= ARC-Authentication-Results: i=2; imf12.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=OdkJBitK; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf12.hostedemail.com: domain of apopple@nvidia.com designates 40.107.223.135 as permitted sender) smtp.mailfrom=apopple@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712797065; 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=pwz3G4pVEJdlpyhp4ZtpEgx+/B+YnG1g293zldnpPzg=; b=xOsfooz6uK7IMK7YEFF7AONl90+yBjiqiyQqsC07EovXvt6VEpMzzvPVZ4NioitM+f7uMR jnfuEHazApkupiMomV64sKAcmXnuqSg+4r0iZV/qnxneH7sz0xibhRa5dl2jI/sR+Kaotu qrXQfqN/9eS9c6sg0/IPwE6mE65O5q4= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DVy1aMEu8XAS1WCZan8oRc26UzTmWi1j0T8fYKS9M4srauIMTddD/UZSedCcf1I3LysVRKe2vSaXlc/zBOScZCK6FGKZ9QEoZfhlgSzZbCbG+X58P0W/0ermwCFzrMdxd3Y5j8hn/vMe9Cc2FJofM4MfA888yxXpXwPBMFa28uO7wZzaWo8K6fzy3so0Cc95gBpGZeMTTw8xtvXTIH/w+quRau4B0Efuyjs/vYJpwmvOaOT27M8XH/w/7mRLrnKkyTDFUWRJvPsu4VubnBfX1zzwaVxAuCoRdvnvUGlIVB4EXldis9tT/bby5oZIjQxBtFgBmC1Po+BGdOQCfWSuMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=pwz3G4pVEJdlpyhp4ZtpEgx+/B+YnG1g293zldnpPzg=; b=MyQEpd16nwzltDMGj4wYf/4P3KD3HjTrHsMA9a9q4uwQ+XHYF6KPl50hTptaU4ANu5OlgiNDib5dwtlh5+NhOLU7z7u+HsMSszoeG1DwunhJpGZ5ebTcIGpNUDVR05wC8YU8TTpYhsk21X8vwEMk6sCeM92GQBrI2nIlBGMvepgNDq2VQzuf4V2OJxE9Y7LXecyJkcDBbT+IJ0V8dbG56F3jjnUiDyv4KvgyQhOzEy/jXcOKmtpY9qe8RJnwU5oQQBuTppAVcQmL+jx7fYRkfd9g3bTTq5JSKyk1Friv0LAN3P7oupyt54C/iLPso9IeWIDDiErdg95KOYAKXWshmw== 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=pwz3G4pVEJdlpyhp4ZtpEgx+/B+YnG1g293zldnpPzg=; b=OdkJBitKYplSQAfJL6ZSjLvY5jvc0GrxEZ+7Hw0UyMfyaBtghRaHWPOjpYY2edOxKqTNYCC5TGDLJLpHkoOPlbEBlaLbox7FHevuRD0hrR96crWNp0Id68q+PLXfJrvO/HZ75fx2XBxACKtZpMWxJI/i14tHJimWdmzYR4xqQutM49mRL6s8Z8PDBHZZJAjWvNzQSyWCMPxRwMNC7G701d7da2JbN39p8mbsTCpvH89ZC8g5EFEG2gWeZ4oA87tjKJp+5pxwaOoVlz9/o8N+JH2it0D1QR7KzHh38kBZda3ZuvEA7dIilJXYotAIojILzcW/h4l+lFML8b7K23ejlg== Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by SN7PR12MB7854.namprd12.prod.outlook.com (2603:10b6:806:32b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Thu, 11 Apr 2024 00:57:41 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::c5de:1187:4532:de80]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::c5de:1187:4532:de80%7]) with mapi id 15.20.7409.042; Thu, 11 Apr 2024 00:57:40 +0000 From: Alistair Popple To: linux-mm@kvack.org Cc: david@fromorbit.com, dan.j.williams@intel.com, jhubbard@nvidia.com, rcampbell@nvidia.com, willy@infradead.org, jgg@nvidia.com, linux-fsdevel@vger.kernel.org, jack@suse.cz, djwong@kernel.org, hch@lst.de, david@redhat.com, ruansy.fnst@fujitsu.com, nvdimm@lists.linux.dev, linux-xfs@vger.kernel.org, linux-ext4@vger.kernel.org, jglisse@redhat.com, Alistair Popple Subject: [RFC 00/10] fs/dax: Fix FS DAX page reference counts Date: Thu, 11 Apr 2024 10:57:21 +1000 Message-ID: X-Mailer: git-send-email 2.43.0 X-ClientProxiedBy: SYAPR01CA0003.ausprd01.prod.outlook.com (2603:10c6:1::15) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|SN7PR12MB7854:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: stltYl4F6zWa/yARgh08etfvcq+xoDV9XmPuqv6xp7z2hhHz1b2s2t8fl/cOMmpeV0Ms2RBIMvSrTG4WI6QUMOto7TbqEvWt2BdHZdG0DsD2taJKj3pTAcABsQXZWCPOpfsOMtlNNBPQPMHpCs85wllyQ18s0A0OgvnLYCGENQOZjEyk7cprsXMrZ++mWmwMNhcR8CGpHyatwRUleeuGQdOf1JGTM/c8UsQ/apaEYFhT8/B31PO5g/yCML8CUkFx5F66bT9L9gOXimV6mHHcWpEFKvBhC0nJrfG/phHRU8/yuOAndAGg6i8SenZKizJNYavz7z2/9XdmH4u9idYxDfhlGD47v4DecGwfyqQzFv0b0aG1nqZHdz+E7aM/QJ72jDyHSqDv5mupyO3NX//NFNymSZ26qbuAjdWDK0D9lIfkTU6WlaVQ4msSYVzRSOkrcWkgP2q69eVHGW8TvQ+chgRYFdaTqOeWakA6FzkDu+ThuN5u4ow7oGE+FnS+2x0hh1SNVNsTTFZprXcGJ3pwUn6BNbigF/RR4bVdq4A8N3v5kkt70AHbZAUSI8t/ErRebtogKye4Kyecsuy4x8lfzg2qZwkrp2ys4ctlGufjTRtMg9ptiO6DEk8ZVbYXZ3i7OSL1T3Q1BMKuI/vruXDxw5m4cqvFh0KBvEuVwcMQiNQ= 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:(13230031)(376005)(1800799015)(366007)(7416005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zuR4fKit5gB0Do5otoOLKhaAcoB9jNhaE93cDWtEWXLjDrmN2M5Jr27p7sHKD2tcV/LDUOu4iAjM6nJWSuq4bHgXCHkTFu7bOLSrCnks+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NWRNIA0Cz4CepeA3OGYoHGXbW0PuBgb7T5GZlnpRVf/AgOg2T6dw72h6bGj8azz+/43Zfq8+S3bRHPKgzHOmIQ+nAQdWXMbUs8Uaix6POlJjVWgMWoAFvX1KYfs7UPiBrGyP86Eojd6s33BimuU2setDqKD9t9Um/sm7T3AlKypwdlhntjVMZuN50XV9ZfnGjYYVXvNGu6W13P2vZu4jK58GE14K+yFnZrdpVydtTJxvZPv8OQQG/Dcrnt6VVBLLBdQZ9rCj+dywJlA3D+HUPlGZkq010wJfW74ToRfLgokqeu2lweAq9CyXOPKdWoZIPo3wxuVPQIg6CgnI5FAuZ4uKYMR28byBaHORbn+vZPpKhMNRbiWtawJhJMPm3Wk+wqNtk2bI8S4+WfHgjft5DRFNcXVB03+z7AYVLyY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e00421e9-8ab1-471b-4428-08dc59c262f8 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2024 00:57:40.0373 (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: BARh95wurK+T2RmCYquye4qi/IUriTQZtZ4UiFDgiiXJJFTgiTAgNt677Ji/+e0cx10ISNjoEiZWHSCHjnkPoA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7854 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4F50440008 X-Stat-Signature: ze1ue3x44jmz4q47gysku4gasba1qh57 X-HE-Tag: 1712797065-710264 X-HE-Meta: U2FsdGVkX1/O7oy86TQKQB/Kbvd9u85hQSO24mdC2uGJWZ/CG6lVYdpdyl4+g1O6Q5g17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j8lJL1XObZbkGpDmvwUDr7EjelOpV7aW91y+uMakN3mTK9Duvp2DOSBKkpSq9TQgjL8i X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: FS DAX pages have always maintained their own page reference counts without following the normal rules for page reference counting. In particular pages are considered free when the refcount hits one rather than zero and refcounts are not added when mapping the page. Tracking this requires special PTE bits (PTE_DEVMAP) and a secondary mechanism for allowing GUP to hold references on the page (see get_dev_pagemap). However there doesn't seem to be any reason why FS DAX pages need their own reference counting scheme. This RFC is an initial attempt at removing the special reference counting and instead refcount FS DAX pages the same as normal pages. There are still a couple of rough edges - in particular I haven't completely removed the devmap PTE bit references from arch specific code and there is probably some more cleanup of dev_pagemap reference counting that could be done, particular in mm/gup.c. I also haven't yet compiled on anything other than x86_64. Before continuing further with this clean-up though I would appreciate some feedback on the viability of this approach and any issues I may have overlooked, as I am not intimately familiar with FS DAX code (or for that matter the FS layer in general). I have of course run some basic testing which didn't reveal any problems. Signed-off-by: Alistair Popple Alistair Popple (10): mm/gup.c: Remove redundant check for PCI P2PDMA page mm/hmm: Remove dead check for HugeTLB and FS DAX pci/p2pdma: Don't initialise page refcount to one fs/dax: Don't track page mapping/index fs/dax: Refactor wait for dax idle page fs/dax: Add dax_page_free callback mm: Allow compound zone device pages fs/dax: Properly refcount fs dax pages mm/khugepage.c: Warn if trying to scan devmap pmd mm: Remove pXX_devmap Documentation/mm/arch_pgtable_helpers.rst | 6 +- arch/arm64/include/asm/pgtable.h | 24 +--- arch/powerpc/include/asm/book3s/64/pgtable.h | 42 +----- arch/powerpc/mm/book3s64/hash_pgtable.c | 3 +- arch/powerpc/mm/book3s64/pgtable.c | 8 +- arch/powerpc/mm/book3s64/radix_pgtable.c | 5 +- arch/powerpc/mm/pgtable.c | 2 +- arch/x86/include/asm/pgtable.h | 31 +--- drivers/dax/super.c | 2 +- drivers/gpu/drm/nouveau/nouveau_dmem.c | 2 +- drivers/nvdimm/pmem.c | 10 +- drivers/pci/p2pdma.c | 4 +- fs/dax.c | 158 +++++++----------- fs/ext4/inode.c | 5 +- fs/fuse/dax.c | 4 +- fs/fuse/virtio_fs.c | 8 +- fs/userfaultfd.c | 2 +- fs/xfs/xfs_file.c | 4 +- include/linux/dax.h | 16 ++- include/linux/huge_mm.h | 11 +- include/linux/memremap.h | 12 +- include/linux/migrate.h | 2 +- include/linux/mm.h | 41 +----- include/linux/page-flags.h | 6 +- include/linux/pgtable.h | 17 +-- lib/test_hmm.c | 2 +- mm/debug_vm_pgtable.c | 51 +------ mm/gup.c | 165 +------------------ mm/hmm.c | 40 +---- mm/huge_memory.c | 180 +++++++++----------- mm/internal.h | 2 +- mm/khugepaged.c | 2 +- mm/mapping_dirty_helpers.c | 4 +- mm/memory-failure.c | 6 +- mm/memory.c | 109 ++++++++---- mm/memremap.c | 36 +--- mm/migrate_device.c | 6 +- mm/mm_init.c | 5 +- mm/mprotect.c | 2 +- mm/mremap.c | 5 +- mm/page_vma_mapped.c | 5 +- mm/pgtable-generic.c | 7 +- mm/swap.c | 2 +- mm/vmscan.c | 5 +- 44 files changed, 338 insertions(+), 721 deletions(-) base-commit: ffc253263a1375a65fa6c9f62a893e9767fbebfa