Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp691589rdb; Fri, 2 Feb 2024 00:26:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFA9ZVYY6SLm5qhpuPU1HdGhIwff+HZ5rNHx0pT9ZyojKDJlcf0wW1qytrQknETd18iE7/M X-Received: by 2002:a05:6a20:6298:b0:19c:8412:2dd8 with SMTP id o24-20020a056a20629800b0019c84122dd8mr2026704pze.15.1706862374496; Fri, 02 Feb 2024 00:26:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706862374; cv=pass; d=google.com; s=arc-20160816; b=DdoFo2n6Is2yRuIbc59pcS0Hoc13YNngsAa0nFhmHKZ1te2/TzbMCDnmW1H6bhj9Op eA1WPA56djAAOHmP6MJwxlKSQqNYJz9DCSqux92O/0by90/sPeo5BnY+g9Dfg/iiPTrr 4ccCfx0TQ44O0yVlsUXjbWeAg1M/AwGM/QTC01WlNtx2moehFPFi+jjfsWbqrKVKFGpZ SxbgOYjPLeywSFbBucL73sFLo60TLztG8EuJraSucdtnfsdoEe85JJEvN3Wj6fxS1L6B XRJZT3aTqZgGdOC/5mQNRxdCvoy/uAPqavB7ApnZxOhMN79JRBDUKXxcfNxU6sUw1cgU cX8g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=j94fI+UszkXDyyB5sUGdHbBs/R63iGXwtMWb4oxj3U4=; fh=Jl4mtpjQ1d1kGpQQxMpylLjUFcYiqUg1kkVHywqLs0o=; b=MOzP61YBIgFqnRlS4vTg44zNBfNiBJdTMGRSM1Nvqafs2RWEPqNDMr4MwiKN5l5xbz n2mXnesPzXGqnz9g8cCMp2fBR+Byff+kHDOqs0ledM0lhDDVQ1j4eGIeacVI/gQDh5X5 WQEJHkjPSw97H8rUbkhD/fVWFM0jO0FTJjZeRUaST2ZJLOQa1AK//u+ChjLWYrr+sowW 3m/MmYMHlzbHll5cYyD36ajN/LmZ2LLH6GmIgabEPVUo1vDnOIRDVv/mTPxwl6uyYL4T GD7XQuKhHTFyws9+FE40zofRd+ZlycKVL23eJESBkyNxoQN4XtkakrWewAlS8D+vVCFc cxqg==; 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-49436-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49436-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCV2TjTFnNRKm4l8x0/ZQpC4m/ObpmP5Y16s1o1P0ktWB+uBlOa9Z6w61SU/uHlsuGVg2yXw48HgejA9j3X5YpHgF3LfRWcvzESddMHI9Q== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x6-20020a63db46000000b005cd89d9fae3si1228911pgi.634.2024.02.02.00.26.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 00:26:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49436-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-49436-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49436-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CB971B2911C for ; Fri, 2 Feb 2024 08:15:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 025345026D; Fri, 2 Feb 2024 08:09:47 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B33F50264 for ; Fri, 2 Feb 2024 08:09:44 +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=1706861386; cv=none; b=NUF0sKmGPsQ9fVxR1dUyN5HeNEVYpTY2zUJl/FemqCeYcHMD79EnDj1D9gfvQoCP5UEft1Q+j9Y/YjIq+N0CKvJFKPJ4dyKblWFkyOrei0O45lg8wGFNMc1jxS9MOo4BpK5VajywJ8A1JWyI6gVFHDOyMPUY1cMdj2nFP6iR7KY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706861386; c=relaxed/simple; bh=gA3rmQESQEtijo//ggjn7IksyLg2S12e6/K2IAx3W1w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rE+pRQ8eTfTFQn7N7K1We4UKdrTRcG3bgBNG5z2RIMJRd0erz76J6VfTWZgwFglK9NB1A0h0AR/QTcPmNy+FzXJZtV8gi3g/qpBu37FrEdK2T4fghb/V4lyiXvapJCNuk3Fcczl3JN/1H6Nkm20wm+KZadfULlLoMhJnzuZvE8I= 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 87EF01BF3; Fri, 2 Feb 2024 00:10:26 -0800 (PST) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9C0C43F5A1; Fri, 2 Feb 2024 00:09:40 -0800 (PST) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Ard Biesheuvel , Marc Zyngier , James Morse , Andrey Ryabinin , Andrew Morton , Matthew Wilcox , Mark Rutland , 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" Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, x86@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 23/25] arm64/mm: Implement pte_batch_hint() Date: Fri, 2 Feb 2024 08:07:54 +0000 Message-Id: <20240202080756.1453939-24-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240202080756.1453939-1-ryan.roberts@arm.com> References: <20240202080756.1453939-1-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-Transfer-Encoding: 8bit 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 --- 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