Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp44067rdh; Tue, 13 Feb 2024 08:55:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXNSBQFGV6861fYJvezw9KEFIpYWywUfGUwUuXVZ2x98yhanDKSMzZ/JxCXp1o3TwwS2XGbePK2GiU569XTTN/E6yjzymM6R/SHP7gxVg== X-Google-Smtp-Source: AGHT+IFVuT/7XwyqxamFF0kjyPLhuE8FFtnxpxNGfnLozreQrgfj0LZNZRxzekUIj2fIKyfHAc4K X-Received: by 2002:a05:6808:2384:b0:3c0:4129:9467 with SMTP id bp4-20020a056808238400b003c041299467mr24262oib.0.1707843306731; Tue, 13 Feb 2024 08:55:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707843306; cv=pass; d=google.com; s=arc-20160816; b=mGG8c7VWUgW24HkARu62O/adToQ0TmtWbhwm7YkxrjiiFcn06F6Odu7mGAY2QK56xw /LNDOHw52HK6Q0FK1dWp4477CQPw+6J6ZfD9sTyMnYrCVMsJ3rSokUnU95wSaj/LGhTK XxSXMGRcAXVcaAmaPV83VLc35JuV9LZREESfvQto+OiSY/hZLjelSFhWI3beZAljIkQA WQtLnFoSbWge3RmTZMaRZsuQ33L80UN3Fkw/LvNfaIz5EX84y8t4mbBLI+hs3ZlX+kDv b0DIE4u5CFo98SBq5EbfpOdDz4D3N84ATB+mdD4E7cigFsggO+1dc5S/WN591j7awiZk Ph5A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=CMri00MoKhSqJ8uAcIfrMINrdTHiogXtd3Ypy52vvSs=; fh=ZnAV+iFWrkuW0p9Lg6bv83SwxBhmNEk920e/kXz6T+Q=; b=vocCkA5MWVJMiIq7Piqr3MMtXChF01yyAAlNjlLXKXffcaUnlnH9o9BfU24pPCYQfb qoVmnoOgP2OlPwelVfUWScDARcmWmpUBdZbEdQBi8Ybu0tvgHjIf1yxKbY+sdyzhmqYU AmTd79delJhsXKtiOETcLVfUe+BBu1AoH1hY1tii42IGxXx2wk9SIfzhmLdbRfNIYf0l OSb8cgypZIsLpfgC4lDbzJdm5S7GxbBrsC/S1NkeqqVYeMmcllKxXQ74JE9IGMb/XxSS 7KTuzWzGVcngCPuHUxm/yjNkIMFo225iSOaQnD/YsU9S8PcnyQuP2xQdngQau/6SwlDl 5wyg==; 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-63946-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63946-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCXaY+YEIilP2/Jndi/+dw+Vhfcpi0j7xO2lGF5tIKZrpa2WEuZ9/gYJUjtS0HQSOhw0v1W3Tj3cUt1aUN4WMCcLt4zaCSUheaddxsIL5g== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r11-20020ad4576b000000b006894f48199asi391308qvx.359.2024.02.13.08.55.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 08:55:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63946-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-63946-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63946-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 755651C22B8C for ; Tue, 13 Feb 2024 16:55:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5AFF25FB9D; Tue, 13 Feb 2024 16:55:00 +0000 (UTC) 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 >