Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp368803lqb; Thu, 29 Feb 2024 03:35:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX+okA//7BCzEWLoW/IOa7jJ7cWkpZgbygka51MwI3Nnw9U+UBbhNGxUgNO4zCHHoZ235LBhyjcAqpTyFmGF+Ww++DuO43ofaJsCkeNLQ== X-Google-Smtp-Source: AGHT+IHtY04A6JYCtVmu1yR0tQdKOVdc5HKPWskH3sqNpmGnMFcGMjppfulJbzIzEr6Q7tA+j2Fd X-Received: by 2002:a0c:fd8b:0:b0:68f:a13d:ee26 with SMTP id p11-20020a0cfd8b000000b0068fa13dee26mr1900408qvr.21.1709206532029; Thu, 29 Feb 2024 03:35:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709206532; cv=pass; d=google.com; s=arc-20160816; b=J3V8XhfoHt+noObSP9Ap75hFJ8WDyXcGu2ElK93tmuIrzvsLBP1kL2DHCToXn2AMJB hxcHUttI7GTc5iITtEfj3xcoOgbmR7SMVqqtGtzmibrl58Va35cv7HoC1LBtDAB+a26Y 7Oz5GOR/J2uTzDQ4fhJnEdRZsvhsRWm6EikeTd3dqM7cR1fXsWdtxnoXwCauixWfWHLl jAEmTL5/eZzV2tcMWV6sq9ELtuaDjWxHqUuEoR+FZ0+TN7QM1F+lz+a0Y0QicLpOWcav /StyaSTyp/hEve5hldWCLayyHEOVsIFgml7y2BIuiJCmVf6V9BC+ULWyC8bmKVI4jpz2 dJYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=jQKeWHr3Qw0XvRWXhOVx8J0HQ9KHAG/qw0RACMREGZA=; fh=xtQKhJoL0jEUXaQ3cvHh0EM4IqKc08CwUnBafpLLpe0=; b=DFzgXYB7Wifk+katRVoktOjiAmKUkmLp/Nh5rP93z9qxYIdkn4+4eJBKy+i2YpIuZQ 20VMPE52F3bOyv1/c6Yhdfdqn219SRFuwOME2i+vYjdVAS1mKUaThUemOCpn7NEb3t9N ZTUjtFjOudrVuOJGITG6Do3AI3wmJANdWPTd90++tBL8ZRwZw4A1GCZJsKbYn5OheuV4 mXV88oXYUURMcalfkkM2hNsr1UGY0l5yQSjYmymyRJUYTaJAmXlM4KvcDW9XAADHmZSZ Oe6nFHOdqDlGwoyLH16ypQZ4RpsQ0+U0SXp+USb7Aty4L/IhRaojZ/DS2c/G7bT56XWD V9Rw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-86634-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86634-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id js5-20020a0562142aa500b0068f41bc4354si1141747qvb.148.2024.02.29.03.35.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 03:35:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86634-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-86634-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86634-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A6BC81C21240 for ; Thu, 29 Feb 2024 11:35:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 311C77C094; Thu, 29 Feb 2024 11:35:26 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 778487AE41 for ; Thu, 29 Feb 2024 11:35:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709206525; cv=none; b=gQu1/uVZplbd4rZPsscfEEJVgKo2SEMZH4wo1gVmPjKess7tlAaw2bMEwj5aV+oRBkvPVTKTH6etS4hXZuQLm/LeXsEpPOsQFJbP/Kfytu0jXPbUP9/kU3bgcxN/f/ismGJgOGZbMEMEfjSFKnDvQFdKRI9apu6mce8yppdckTc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709206525; c=relaxed/simple; bh=Tcv85mJuRG7F5HJeDHob15mnxzEcXiChVN1WZIyv8vQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=d28nRl76nfI0CGU4w4uDFzED099y1VvGRSTYheAyfdBJHHEiX+dG5AxPr6ujC3Mi9CUMkQSxDPSw8ysDoJsRCDix/34Zt4byvrM4duUngSoxXlIiAaAbQHBybYcmUSqkvckaPAa7QgHCyM23YvuJj59XPAB12BmHQVOYJZLBiNI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9159B1FB; Thu, 29 Feb 2024 03:36:01 -0800 (PST) Received: from [10.57.68.58] (unknown [10.57.68.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A3C43F762; Thu, 29 Feb 2024 03:35:21 -0800 (PST) Message-ID: Date: Thu, 29 Feb 2024 11:35:18 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/memory.c: do_numa_page(): remove a redundant page table read Content-Language: en-GB To: John Hubbard , Andrew Morton Cc: LKML , linux-mm@kvack.org, David Hildenbrand References: <20240228034151.459370-1-jhubbard@nvidia.com> From: Ryan Roberts In-Reply-To: <20240228034151.459370-1-jhubbard@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 28/02/2024 03:41, John Hubbard wrote: > 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: 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); > > /*