From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 666B95F852 for ; Tue, 13 Feb 2024 16:54:58 +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=1707843299; cv=none; b=sxZcc1YncEn2HsseYBedodAOpmyl2P++9di+KqD5UxbFl3FcUecm3KEzHtRj6K4S3dymAyhj7P8u8/2ZmARdkZ+rNJLjBYRXYnVAKEicAPYxT1LH22cBBqQZla/PI2bdOU9vq0x4HA1BAyZ7YOZA795Jsa8anKr2RRzOqH9rCQY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707843299; c=relaxed/simple; bh=6r2sJzbh/wD5ErlkQRvpbpFzmFT6Ly0IdbfwOHZ+bNw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bnsEdgLasftiXcvdn+NVkuPw5sgTQeNkKUmouN1Q92/N6U0TiaRT+UjOSvcfYmM2n9xzIMIn2GhNPv2zDbCtwxxpuyJ+aE5uFUWlSYSrkJAEtTDeUKCnPQxr3x84ZA7rlrDMLi1SJOg2INjWBrjNJFp4xCTEJwYPH4SpqhwrTX0= 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 E5C0DDA7; Tue, 13 Feb 2024 08:55:38 -0800 (PST) Received: from FVFF77S0Q05N.cambridge.arm.com (FVFF77S0Q05N.cambridge.arm.com [10.1.36.130]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DE5853F5A1; Tue, 13 Feb 2024 08:54:53 -0800 (PST) Date: Tue, 13 Feb 2024 16:54:51 +0000 From: Mark Rutland To: Ryan Roberts Cc: Catalin Marinas , Will Deacon , Ard Biesheuvel , Marc Zyngier , James Morse , Andrey Ryabinin , Andrew Morton , Matthew Wilcox , David Hildenbrand , Kefeng Wang , John Hubbard , Zi Yan , Barry Song <21cnbao@gmail.com>, Alistair Popple , Yang Shi , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , "Naveen N. Rao" , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , linux-arm-kernel@lists.infradead.org, x86@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 23/25] arm64/mm: Implement pte_batch_hint() Message-ID: References: <20240202080756.1453939-1-ryan.roberts@arm.com> <20240202080756.1453939-24-ryan.roberts@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240202080756.1453939-24-ryan.roberts@arm.com> On Fri, Feb 02, 2024 at 08:07:54AM +0000, Ryan Roberts wrote: > When core code iterates over a range of ptes and calls ptep_get() for > each of them, if the range happens to cover contpte mappings, the number > of pte reads becomes amplified by a factor of the number of PTEs in a > contpte block. This is because for each call to ptep_get(), the > implementation must read all of the ptes in the contpte block to which > it belongs to gather the access and dirty bits. > > This causes a hotspot for fork(), as well as operations that unmap > memory such as munmap(), exit and madvise(MADV_DONTNEED). Fortunately we > can fix this by implementing pte_batch_hint() which allows their > iterators to skip getting the contpte tail ptes when gathering the batch > of ptes to operate on. This results in the number of PTE reads returning > to 1 per pte. > > Tested-by: John Hubbard > Signed-off-by: Ryan Roberts Acked-by: Mark Rutland Mark. > --- > arch/arm64/include/asm/pgtable.h | 9 +++++++++ > 1 file changed, 9 insertions(+) > > diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h > index ad04adb7b87f..353ea67b5d75 100644 > --- a/arch/arm64/include/asm/pgtable.h > +++ b/arch/arm64/include/asm/pgtable.h > @@ -1220,6 +1220,15 @@ static inline void contpte_try_unfold(struct mm_struct *mm, unsigned long addr, > __contpte_try_unfold(mm, addr, ptep, pte); > } > > +#define pte_batch_hint pte_batch_hint > +static inline unsigned int pte_batch_hint(pte_t *ptep, pte_t pte) > +{ > + if (!pte_valid_cont(pte)) > + return 1; > + > + return CONT_PTES - (((unsigned long)ptep >> 3) & (CONT_PTES - 1)); > +} > + > /* > * The below functions constitute the public API that arm64 presents to the > * core-mm to manipulate PTE entries within their page tables (or at least this > -- > 2.25.1 >