From patchwork Wed Feb 28 03:41:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 13574826 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 B9C54C47DD9 for ; Wed, 28 Feb 2024 03:42:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36DCA80018; Tue, 27 Feb 2024 22:42:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 31D7480015; Tue, 27 Feb 2024 22:42:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 170B480018; Tue, 27 Feb 2024 22:42:05 -0500 (EST) 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 0084E80015 for ; Tue, 27 Feb 2024 22:42:04 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AD034140777 for ; Wed, 28 Feb 2024 03:42:04 +0000 (UTC) X-FDA: 81839814168.06.8AE5A6A Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2071.outbound.protection.outlook.com [40.107.237.71]) by imf24.hostedemail.com (Postfix) with ESMTP id E8587180002 for ; Wed, 28 Feb 2024 03:42:00 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=DGtY2nwP; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf24.hostedemail.com: domain of jhubbard@nvidia.com designates 40.107.237.71 as permitted sender) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709091721; 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=f3Mybnezfu45hJMbc/5Qwp4vfmOhIfOfpvNNSbRuaY4=; b=e7LYTpV4C2OEywEZZvLm2ZfXNcoR15j8lRKqAFaiKXQrcR80P3RS+b7nOG5scw1lYLpw1b k8SdsoQ6Ws7tQ9hMeSrz20JHY+bksMk0BSYS5dXTcZL/NvGpmbyuAH07L5ueDi+Y1bWLNq +d2qdPdNf+4i/ojLgGXJI/D9Fye3Dzk= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1709091721; a=rsa-sha256; cv=pass; b=fRvYXizTbTdWnfbDNUUn3t00dfJml14RCEsEf3H1MX68lUQ/9lmXq0dmo+3rH/aIVnRPZA tTth8/YGjd3sadsAqextz7yIXBsi2ok5/Rj1UaBUJL0Ne0YMSRupvfIbnfKw/n7BjEL1ue AtqpKBqY1SOpLFCWfMc+r0jNMLeRmhg= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=DGtY2nwP; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf24.hostedemail.com: domain of jhubbard@nvidia.com designates 40.107.237.71 as permitted sender) smtp.mailfrom=jhubbard@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KW6uI+Gq03NNLl/T0fckbHRsupj6mEl6juC4726LJ2W/A2uBwsNCnys3pT9GlYUZidiHmDK+lvS+MLpIFsGmwUb4ppwmLRoYBuJnjd8eipVZISyZ/AGEO/hlboqgdGtK9k5dpt6ZL1BQdBpLWLZQe/Rr1Ni8lMVNVc/ZTkTsP9P7TF7tfAecj7WpAHdp5bY2cWctxzvcAP0nC03q7G24PdCzfEW/1B5XqbqvY5Nw0KdoX3Njd6Luc3UNjo0pDD/TsUqkQpquNAryKP8OH7idC1dU4oD5Ezuds1awaaJkdiI4gtivS24xmjDp7LT9azSnNPUim+MOEpxvk/4pV/rViw== 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=f3Mybnezfu45hJMbc/5Qwp4vfmOhIfOfpvNNSbRuaY4=; b=cIHm+j2LGeCRwdXDjgI2UXDNh5M2bB8e16S3jxwZ8n1iiLXOldLAbfBuhy5HaWXAzhBfQXTx2lTZZjM3618zZEwK0FBBxBhSZqWjL5mKgC27CwuE9w1c7wUrg8DF1/Ht6W50yydSUy8g09nUnw6yw8mVg/+r3NzpL+8U7Cj/sHAd3WQ/2e3eyhPVzM3Icg0wiHvEm/9a6OPlT4SHlwpuN4ymZNry8hjRgMPGybkueDUXnFDU4/hNda0CBNKvtuvd3XhrlRnbcgK7LS4urevbvIILfNXYrkUmctjz1/cmhd/uxTJKhsHZ99WfukxtyEigGM7Emc1uIH7m84Uj4QQJOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=linux-foundation.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=f3Mybnezfu45hJMbc/5Qwp4vfmOhIfOfpvNNSbRuaY4=; b=DGtY2nwP0PP1XjDZVTVYh+XpHqM3DnfPpj1BL6iqIPjNPgahnYXJwoVars7h+gwdmIfYLA+p3jxtdGLnx+G4r+kKPZt2etdJhxoh/KlfF5TChMr25Fd/Likk/RMHGnSsYF2J+vJVEfFvdWLR7tg0ssBtHRNaIGsWKWkew3Q6NA6IZSe4T6GKKp0waYAnmgfzJ1EAuULHsOGLxFzjLdSpOqqgy5UlaWD+/H+CpYCH+BD9HzR/uRLPr8eTiq0XPOj3g62/VwdLoklxNXhHikF5PeHmBAsgBHMLRcqFwKBMINO6qkegm3es4h88bBz0iQnotMOl2U3oWv1KDrZ1PZxSwA== Received: from DS7PR03CA0234.namprd03.prod.outlook.com (2603:10b6:5:3ba::29) by SN7PR12MB7345.namprd12.prod.outlook.com (2603:10b6:806:298::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 03:41:57 +0000 Received: from DS1PEPF0001709A.namprd05.prod.outlook.com (2603:10b6:5:3ba:cafe::53) by DS7PR03CA0234.outlook.office365.com (2603:10b6:5:3ba::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.27 via Frontend Transport; Wed, 28 Feb 2024 03:41:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by DS1PEPF0001709A.mail.protection.outlook.com (10.167.18.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Wed, 28 Feb 2024 03:41:57 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 27 Feb 2024 19:41:56 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Tue, 27 Feb 2024 19:41:56 -0800 Received: from blueforge.nvidia.com (10.127.8.13) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1258.12 via Frontend Transport; Tue, 27 Feb 2024 19:41:56 -0800 From: John Hubbard To: Andrew Morton CC: LKML , , John Hubbard , Ryan Roberts , David Hildenbrand Subject: [PATCH] mm/memory.c: do_numa_page(): remove a redundant page table read Date: Tue, 27 Feb 2024 19:41:51 -0800 Message-ID: <20240228034151.459370-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-NVConfidentiality: public X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0001709A:EE_|SN7PR12MB7345:EE_ X-MS-Office365-Filtering-Correlation-Id: ffe908cd-3503-4e90-289e-08dc380f36be X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sY+ThXaeeqFuGPEl4TfslpkVOHuNbaoYs+lwiShg8kAXBEIbg/vIU4AfmuKCJHLgcwUbUlpGow+PdUCjUv0gqKw2S/uF+vJt0L0zJctURgKQyxNg0latzQK078PMLzdHeqMaxPM50zcAIbvUqgo4jAM4aHDDsKPBJrMe2KuaGfOItRugxZNq0WXts7B4ED8eDrCAA9s2GgAIfEg6tMdDQAEg/Kj6Kiybrwnh6IpevEfa12Rv8fw8ZVpG5+D/j6Aq3jAWd3r59foEHCCQaGJ0O0H/4WWjI3Y2Whrcxw29QflKEc/GoYbwOAxjXoLx/80aad8Th5v4w2Uh9aDmkohvxUoFyHW/6j937M58PPXLqFFqRfxqMQlwnRs5uTWeSPbalZm5yK+lAOHpe/D80O0eZXDrFZl9vae9dKiVvijZfnhqNRcQMobss4ZKKgE7ZmDKSL2L/5Rzeg4dz4gxv9JpMt1MihbdpIXp16XS12ijlM7FMXxmszoSJh939MCGqiYa9LrYkUzAd1j9xiNvb+nCtjrWPgxISFGhtaGnRc4bgQWpb19Arl1+b9op4qEOTJ0HKhkupJeGUdKM66R4ZIqUgQ1snYB9lEA5tYLhc12s/2xyC06UHQCCvOr0kRbV24DO1MosIStycR3a9PC9w6ybEGiJzSVny95MT9O2zcpQaql0huF6uYxu18CMAOnT767ufnFsxeTDUvossOT7aHUI9IiQsFtU5IZooKn+y+UN9eMHNzE2f6MxVL0J+wCCeflj X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 03:41:57.2458 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ffe908cd-3503-4e90-289e-08dc380f36be X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0001709A.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7345 X-Stat-Signature: dt3gyrfi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z7xhtPgR bMFTcQMnwGoaD+JI= 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: do_numa_page() is reading from the same page table entry, twice, while holding the page table lock: once while checking that the pte hasn't changed, and again in order to modify the pte. Instead, just read the pte once, and save it in the same old_pte variable that already exists. This has no effect on behavior, other than to provide a tiny potential improvement to performance, by avoiding the redundant memory read (which the compiler cannot elide, due to READ_ONCE()). Also improve the associated comments nearby. Cc: Ryan Roberts Cc: David Hildenbrand Signed-off-by: John Hubbard Reviewed-by: David Hildenbrand Reviewed-by: Ryan Roberts --- mm/memory.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 0bfc8b007c01..df0711982901 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4928,18 +4928,18 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) int flags = 0; /* - * The "pte" at this point cannot be used safely without - * validation through pte_unmap_same(). It's of NUMA type but - * the pfn may be screwed if the read is non atomic. + * The pte cannot be used safely until we verify, while holding the page + * table lock, that its contents have not changed during fault handling. */ spin_lock(vmf->ptl); - if (unlikely(!pte_same(ptep_get(vmf->pte), vmf->orig_pte))) { + /* Read the live PTE from the page tables: */ + old_pte = ptep_get(vmf->pte); + + if (unlikely(!pte_same(old_pte, vmf->orig_pte))) { pte_unmap_unlock(vmf->pte, vmf->ptl); goto out; } - /* Get the normal PTE */ - old_pte = ptep_get(vmf->pte); pte = pte_modify(old_pte, vma->vm_page_prot); /*