Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp140675lql; Fri, 12 Apr 2024 06:20:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXY1B3/P1+irc2oYWMhsdMDmeg3YXwnn7ehxjFDJJkvUPpxJHW+qf7GU/GQwexr7MtVtsBqrPYDgHr5HeAvKp0MfvztLDixGXSL0CIEfg== X-Google-Smtp-Source: AGHT+IG3qqVptsNZGcPl5rT4E1ZbaHeuEXq1tq06iwAW1YjPZBDbiBTr+yPDPDchkYw5MgqKq3cU X-Received: by 2002:a05:6a21:35c4:b0:1a7:ad53:d3a3 with SMTP id ba4-20020a056a2135c400b001a7ad53d3a3mr3172648pzc.35.1712928023917; Fri, 12 Apr 2024 06:20:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712928023; cv=pass; d=google.com; s=arc-20160816; b=GnOtWFeRwseF2PTrEx5wGSQaomwdGHf6RYmmgEQUEd3MULRR/GU5dBRon4KniuNH+g WEYGPurEp2qEyeP4gZaJISG5zLdrjJDjhISgIXJuIH9QgLpVRm6kuWEqADo/UZ+0UFvD hIVAFv3OJEZTFShQpKhF7JbunRcy+6O7aMokrdqB+PLsixYH+JZtZRypMfrfs10EhkDn rQoypfdGr+n0+6IVKruKR1wgKXkWuQMpCgGW97jR8I/F18BvfXYWYDezC5h50M1qulw+ 9zOIEZKlibP9TrufGxKsUx6LOP/mRfBglVm6PCorMHc3Dfz4NpAU+Cy6fhg1mdtpWb7j ZrYQ== 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=1+lJ7+ZZX3/NEYgHfIsoLoMFQrQ/J0jCuOJKmQPqRuY=; fh=v/ZIPGFTxC8d1MMVbwyojvDvopPRKsRhmXNzvjHdZnQ=; b=W8Q/IywnyFYGXVmUNKdY2WXdMsIE+PSB9vt3Tlju3l1GcsBqxlxfqQeoegJ7vlJ8+V p6EqLSdPPTMbZR1HJ1BH5nuSmHHYODiMzIQzgjfeGOx8l+vmcmaDgVUOjqhU3XE3Ma/v xi5Pw7gSoEqLFgSoQ2G127wc1pInA6WMKHrLXg+kumCXHSWjsw3+uXPVQ3gYd7mGXGoe l/dxYwt4sxbdK1K6KVN7TetF0QZqDqfxweK0vy3BQ3YF7lJk7/bPcon3eux07HX8CGag c+eJ0/HIJCof3Foyuv6HvMWlJHilx/L5lNu3Uj49V6jRDUvRPt6otNjLl2GHP5zdkS6a PRhw==; 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-142712-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142712-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u9-20020a170902e5c900b001e0d08fc3cbsi3316744plf.411.2024.04.12.06.20.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 06:20:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142712-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-142712-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142712-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0B5E3282FC0 for ; Fri, 12 Apr 2024 13:20:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16A0A824A4; Fri, 12 Apr 2024 13:19:23 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD30B824A1 for ; Fri, 12 Apr 2024 13:19:20 +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=1712927962; cv=none; b=WAec3QYQa8gbGpCyyLnAWQGtd1OL8kQjLMY9hxLnplnI8rhNWHmPpsfY3xIf7rnq1KyAVlSWXkKgOMWHqCns0L3IVm9SR59cn8S0UYMAY5W5rKp23CeVwLYGou45vQl5in6XqJ6vPOtEr/tkGPKkepAV7/POdhT/sznkulsuG2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712927962; c=relaxed/simple; bh=6GOvSwEX9Td7SESPCI99hrQz+78agXQpQFSBUKolXkU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MdC20IN9sP0m1NsAXP7Y9+ZFocB2H853B/IxEnInnZPXf2PTOLx5C7axiizY025bov5T6d1tX7glRtcaGhXnD/4lsquqA1HhJQnNYcL5PIjFYZIosBFR3xfctSbTh5gUXlOKSu5erE/m2uCgG2lLVkzDkPqtruIqNJp/m7jHF9o= 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 565FB113E; Fri, 12 Apr 2024 06:19:49 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B89813F766; Fri, 12 Apr 2024 06:19:18 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , David Hildenbrand , Donald Dutile , Eric Chanudet Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Itaru Kitayama Subject: [PATCH v3 1/3] arm64: mm: Don't remap pgtables per-cont(pte|pmd) block Date: Fri, 12 Apr 2024 14:19:06 +0100 Message-Id: <20240412131908.433043-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240412131908.433043-1-ryan.roberts@arm.com> References: <20240412131908.433043-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 A large part of the kernel boot time is creating the kernel linear map page tables. When rodata=full, all memory is mapped by pte. And when there is lots of physical ram, there are lots of pte tables to populate. The primary cost associated with this is mapping and unmapping the pte table memory in the fixmap; at unmap time, the TLB entry must be invalidated and this is expensive. Previously, each pmd and pte table was fixmapped/fixunmapped for each cont(pte|pmd) block of mappings (16 entries with 4K granule). This means we ended up issuing 32 TLBIs per (pmd|pte) table during the population phase. Let's fix that, and fixmap/fixunmap each page once per population, for a saving of 31 TLBIs per (pmd|pte) table. This gives a significant boot speedup. Execution time of map_mem(), which creates the kernel linear map page tables, was measured on different machines with different RAM configs: | Apple M2 VM | Ampere Altra| Ampere Altra| Ampere Altra | VM, 16G | VM, 64G | VM, 256G | Metal, 512G ---------------|-------------|-------------|-------------|------------- | ms (%) | ms (%) | ms (%) | ms (%) ---------------|-------------|-------------|-------------|------------- before | 168 (0%) | 2198 (0%) | 8644 (0%) | 17447 (0%) after | 78 (-53%) | 435 (-80%) | 1723 (-80%) | 3779 (-78%) Signed-off-by: Ryan Roberts Tested-by: Itaru Kitayama Tested-by: Eric Chanudet --- arch/arm64/mm/mmu.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 495b732d5af3..9f1d69b7b494 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -172,12 +172,9 @@ bool pgattr_change_is_safe(u64 old, u64 new) return ((old ^ new) & ~mask) == 0; } -static void init_pte(pmd_t *pmdp, unsigned long addr, unsigned long end, +static void init_pte(pte_t *ptep, unsigned long addr, unsigned long end, phys_addr_t phys, pgprot_t prot) { - pte_t *ptep; - - ptep = pte_set_fixmap_offset(pmdp, addr); do { pte_t old_pte = __ptep_get(ptep); @@ -192,8 +189,6 @@ static void init_pte(pmd_t *pmdp, unsigned long addr, unsigned long end, phys += PAGE_SIZE; } while (ptep++, addr += PAGE_SIZE, addr != end); - - pte_clear_fixmap(); } static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, @@ -204,6 +199,7 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, { unsigned long next; pmd_t pmd = READ_ONCE(*pmdp); + pte_t *ptep; BUG_ON(pmd_sect(pmd)); if (pmd_none(pmd)) { @@ -219,6 +215,7 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, } BUG_ON(pmd_bad(pmd)); + ptep = pte_set_fixmap_offset(pmdp, addr); do { pgprot_t __prot = prot; @@ -229,20 +226,21 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, (flags & NO_CONT_MAPPINGS) == 0) __prot = __pgprot(pgprot_val(prot) | PTE_CONT); - init_pte(pmdp, addr, next, phys, __prot); + init_pte(ptep, addr, next, phys, __prot); + ptep += pte_index(next) - pte_index(addr); phys += next - addr; } while (addr = next, addr != end); + + pte_clear_fixmap(); } -static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end, +static void init_pmd(pmd_t *pmdp, unsigned long addr, unsigned long end, phys_addr_t phys, pgprot_t prot, phys_addr_t (*pgtable_alloc)(int), int flags) { unsigned long next; - pmd_t *pmdp; - pmdp = pmd_set_fixmap_offset(pudp, addr); do { pmd_t old_pmd = READ_ONCE(*pmdp); @@ -268,8 +266,6 @@ static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end, } phys += next - addr; } while (pmdp++, addr = next, addr != end); - - pmd_clear_fixmap(); } static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr, @@ -279,6 +275,7 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr, { unsigned long next; pud_t pud = READ_ONCE(*pudp); + pmd_t *pmdp; /* * Check for initial section mappings in the pgd/pud. @@ -297,6 +294,7 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr, } BUG_ON(pud_bad(pud)); + pmdp = pmd_set_fixmap_offset(pudp, addr); do { pgprot_t __prot = prot; @@ -307,10 +305,13 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr, (flags & NO_CONT_MAPPINGS) == 0) __prot = __pgprot(pgprot_val(prot) | PTE_CONT); - init_pmd(pudp, addr, next, phys, __prot, pgtable_alloc, flags); + init_pmd(pmdp, addr, next, phys, __prot, pgtable_alloc, flags); + pmdp += pmd_index(next) - pmd_index(addr); phys += next - addr; } while (addr = next, addr != end); + + pmd_clear_fixmap(); } static void alloc_init_pud(p4d_t *p4dp, unsigned long addr, unsigned long end, -- 2.25.1