From mboxrd@z Thu Jan 1 00:00:00 1970 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 CD146C47DD9 for ; Wed, 27 Mar 2024 10:01:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5083E6B0089; Wed, 27 Mar 2024 06:01:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B8366B008A; Wed, 27 Mar 2024 06:01:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 380F06B0092; Wed, 27 Mar 2024 06:01:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1942D6B0089 for ; Wed, 27 Mar 2024 06:01:08 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CF71A1C03B1 for ; Wed, 27 Mar 2024 10:01:07 +0000 (UTC) X-FDA: 81942375774.27.C8E566F Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf03.hostedemail.com (Postfix) with ESMTP id BA4D220024 for ; Wed, 27 Mar 2024 10:01:05 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711533665; 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:in-reply-to:references:references; bh=yq5BjuVZ3W+hGRGOcjzhn+plEAKyBhWoS6eN1/8vm9U=; b=x3ZLHoGbqqR9xtZKxhCNk8IFtUz/vlSnHpiKkHXqfCHGnGSJOGpDXdW6AVfmCat9c90dOs 9UJ4D00BcJicZuXyzl9Re2bF84uRcJTdiggVW6P1w41Kn/y/eRcr2StLgCCYQ3ZUamFgUG BkBLimijDO3WdvATbE/7BKMmPHIgE6k= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711533665; a=rsa-sha256; cv=none; b=DiDi4J4XN3B8ECurhXwzheoQeYeOWkyOOWa6bqDr9V3gtbDtk6oeWJPirN1PSPSKKaiMua FxSQ90MKCz9iumiKVxcdtbV2+Z/wdSThMfsQvOISDA/vro1OLe4Q12rK81yhJMyBEXGXcl NWHJkIL7DpvCt+UgET4KIEn/C2d/IlU= 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 E82BC2F4; Wed, 27 Mar 2024 03:01:38 -0700 (PDT) Received: from [10.57.72.121] (unknown [10.57.72.121]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ACA2E3F694; Wed, 27 Mar 2024 03:01:02 -0700 (PDT) Message-ID: Date: Wed, 27 Mar 2024 10:01:00 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 0/4] Reduce cost of ptep_get_lockless on arm64 Content-Language: en-GB To: David Hildenbrand , Mark Rutland , Catalin Marinas , Will Deacon , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Andrew Morton , Muchun Song Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240215121756.2734131-1-ryan.roberts@arm.com> <0ae22147-e1a1-4bcb-8a4c-f900f3f8c39e@redhat.com> <374d8500-4625-4bff-a934-77b5f34cf2ec@arm.com> <8bd9e136-8575-4c40-bae2-9b015d823916@redhat.com> <86680856-2532-495b-951a-ea7b2b93872f@arm.com> <35236bbf-3d9a-40e9-84b5-e10e10295c0c@redhat.com> From: Ryan Roberts In-Reply-To: <35236bbf-3d9a-40e9-84b5-e10e10295c0c@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: BA4D220024 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ypyk1gg8k86ar1zw9cgn37s85hcsgemt X-HE-Tag: 1711533665-902558 X-HE-Meta: U2FsdGVkX1/Ak3j+yZr7SCgCz+FOnTKdufC4EKSfHgVgiXPap9Xvet5bt3yJ49rkz2HS5APA42ih3awox6Yr/pdbimlv+bPDeDfakt20bkjPsjQKTrJwR6LVxMrCoxFsRe56w4HRLlFJanNjGwWeGaf8ZkLZtPQVSWUOmLgZCzUEUyRt2b8AO1xvrAeYq7sP+NjTXtQc5Oz2bCxXyPI6Eg1u7b0bHZaR7+cYQa4VV2pbwxv956i5uHxbr90znDccgGib29fJBlQ50VEg+WczmegysyJphqlmRJ9wCYEDkWnih4J8vOCe0SfqkfOF7fCKii0Z1qIPNcEyW29JMBfm7IQV6SvFzU5PZvBZjNpVjvWS2tcZdCuPplcZ8s6SvKjm2iESTiiWydzynYfKV/MCvSbOtT2UrjpX1njVRECSybSFHu9ur5cHmOdjHSsC/gtcs2eZhCobiFPlb9eS4XXWAwg1khxRxDXbIALemeCMrwmIZDz6RaUFWcZxOxmJA7wYWOWyPGmearG2dRjymKOus+JL12LZEf+xDqhsAcciMG1rtYvBKo6R4wq8fR6AvZX4rwustZq7ZPqGuuqf5dDWdVHAstdx3u9V3LVLMzFzH+bDBuRlA/uFmRXKD/i5zw+QdGvJ7tmNwcrrnFJoENptel4oXTFI+1stWRuwBr4e4x04ypqO9Dy2K98rSij6pSFqPcQ1v7aTCCD0A085ZajhAaC3HozByt8in0MGXWHG1e7yZULDiQ8zhtuDxQYvT8jnIXiJ3UkEb8QZHeB3WoUkWN01m9EivkbideHAxNv29S+J/JyUGv2kPZg7KYkZDouyz06c+w6G01uoI0bY8OSaQ5iVuTv5Bfs4opvrXUom1ItsKA7tj5MxoQJSb4HdGVI/a9PKdWW0O5VK0y2J+g/lqWGsaK5vMFdP8kEEgaItICvYSsMKnyGFqOi+ByyOyy0r0kLHcYQizyOcJ5v/r9a cT8wtgUQ Th5slP5V2rNHeEWhn25Y6J3EM+EjHoZDrEzAgps6k/S84JsqOEzg0k1JriJMiMj9caT9kdzEHehGIynNgNCUZVkECSmiq7dqCfnvJvUysHLH2dNljAiUI8PTxgJc3iTs/1o/jEGN+i0zQel8srVwvZ5HP+9R6YcQz+gbydgMhUPfGQ5OjCHG7SVv81O+XxaftdEc8 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: On 27/03/2024 09:34, David Hildenbrand wrote: > On 26.03.24 18:51, Ryan Roberts wrote: >> On 26/03/2024 17:39, David Hildenbrand wrote: >>> On 26.03.24 18:32, Ryan Roberts wrote: >>>> On 26/03/2024 17:04, David Hildenbrand wrote: >>>>>>>>> >>>>>>>>> Likely, we just want to read "the real deal" on both sides of the >>>>>>>>> pte_same() >>>>>>>>> handling. >>>>>>>> >>>>>>>> Sorry I'm not sure I understand? You mean read the full pte including >>>>>>>> access/dirty? That's the same as dropping the patch, right? Of course if >>>>>>>> we do >>>>>>>> that, we still have to keep pte_get_lockless() around for this case. In an >>>>>>>> ideal >>>>>>>> world we would convert everything over to ptep_get_lockless_norecency() and >>>>>>>> delete ptep_get_lockless() to remove the ugliness from arm64. >>>>>>> >>>>>>> Yes, agreed. Patch #3 does not look too crazy and it wouldn't really affect >>>>>>> any >>>>>>> architecture. >>>>>>> >>>>>>> I do wonder if pte_same_norecency() should be defined per architecture >>>>>>> and the >>>>>>> default would be pte_same(). So we could avoid the mkold etc on all other >>>>>>> architectures. >>>>>> >>>>>> Wouldn't that break it's semantics? The "norecency" of >>>>>> ptep_get_lockless_norecency() means "recency information in the returned pte >>>>>> may >>>>>> be incorrect". But the "norecency" of pte_same_norecency() means "ignore the >>>>>> access and dirty bits when you do the comparison". >>>>> >>>>> My idea was that ptep_get_lockless_norecency() would return the actual >>>>> result on >>>>> these architectures. So e.g., on x86, there would be no actual change in >>>>> generated code. >>>> >>>> I think this is a bad plan... You'll end up with subtle differences between >>>> architectures. >>>> >>>>> >>>>> But yes, the documentation of these functions would have to be improved. >>>>> >>>>> Now I wonder if ptep_get_lockless_norecency() should actively clear >>>>> dirty/accessed bits to more easily find any actual issues where the bits still >>>>> matter ... >>>> >>>> I did a version that took that approach. Decided it was not as good as this way >>>> though. Now for the life of me, I can't remember my reasoning. >>> >>> Maybe because there are some code paths that check accessed/dirty without >>> "correctness" implications? For example, if the PTE is already dirty, no need to >>> set it dirty etc? >> >> I think I decided I was penalizing the architectures that don't care because all >> their ptep_get_norecency() and ptep_get_lockless_norecency() need to explicitly >> clear access/dirty. And I would have needed ptep_get_norecency() from day 1 so >> that I could feed its result into pte_same(). > > True. With ptep_get_norecency() you're also penalizing other architectures. > Therefore my original thought about making the behavior arch-specific, but the > arch has to make sure to get the combination of > ptep_get_lockless_norecency()+ptep_same_norecency() is right. > > So if an arch decide to ignore bits in ptep_get_lockless_norecency(), it must > make sure to also ignore them in ptep_same_norecency(), and must be able to > handle access/dirty bit changes differently. > > Maybe one could have one variant for "hw-managed access/dirty" vs. "sw managed > accessed or dirty". Only the former would end up ignoring stuff here, the latter > would not. > > But again, just some random thoughts how this affects other architectures and > how we could avoid it. The issue I describe in patch #3 would be gone if > ptep_same_norecency() would just do a ptep_same() check on other architectures > -- and would make it easier to sell :) Perhaps - let me chew on that for a bit. It doesn't feel as easy as you suggest to me. But I can't put my finger on why...