From nobody Thu Feb 12 14:45:35 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EF6EB10A2A for ; Thu, 4 Apr 2024 14:33: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=1712241202; cv=none; b=PXNkjzxq0giVdZG7zP2lKuD8Zy8NGtenttYYtAfDF3wG3CnDKV1ZHJjmOLtllkLGZ9Sf2N7Xp1B974+jmPxUt+Uv221lkQWA5EEz5CXn6DkeFyTPphiCCg2Q/NYcZ/r5evhRu2Ub/gO/fICi+CtHmVFagfH1u9i5mXkQoILtziY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712241202; c=relaxed/simple; bh=2W4jAY56ItNGNPH6UriMSM9dPK2eYLyKbq/Ye3HCnGw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TEtgxNcjtAXFn9XqFqacOYFmLXHM7k9q5a/IRWaDX13ToUkckVwXF5DJfM9kVpOtsN/+VS4DajsMcEuGGr+5Sx2rR0gxXkl8bMzZZbpxEaCnJ3rpJIP5xcRpaVfhxbubkXPXcOGNYPn0SEAXvxdF+bejw9RLyRNc0pnGuo3mGIA= 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 191FC1007; Thu, 4 Apr 2024 07:33:51 -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 E9A1A3F64C; Thu, 4 Apr 2024 07:33: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 v2 1/4] arm64: mm: Don't remap pgtables per-cont(pte|pmd) block Date: Thu, 4 Apr 2024 15:33:05 +0100 Message-Id: <20240404143308.2224141-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240404143308.2224141-1-ryan.roberts@arm.com> References: <20240404143308.2224141-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: quoted-printable Content-Type: text/plain; charset="utf-8" A large part of the kernel boot time is creating the kernel linear map page tables. When rodata=3Dfull, 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 Acked-by: Mark Rutland Tested-by: Eric Chanudet Tested-by: Itaru Kitayama ---------------|-------------|-------------|-------------|------------- | ms (%) | ms (%) | ms (%) | ms (%) ---------------|-------------|-------------|-------------|------------- before | 153 (0%) | 2227 (0%) | 8798 (0%) | 17442 (0%) after | 77 (-49%) | 431 (-81%) | 1727 (-80%) | 3796 (-78%) Signed-off-by: Ryan Roberts Tested-by: Itaru Kitayama Tested-by: Eric Chanudet --- arch/arm64/mm/mmu.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 495b732d5af3..fd91b5bdb514 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) =3D=3D 0; } =20 -static void init_pte(pmd_t *pmdp, unsigned long addr, unsigned long end, - phys_addr_t phys, pgprot_t prot) +static pte_t *init_pte(pte_t *ptep, unsigned long addr, unsigned long end, + phys_addr_t phys, pgprot_t prot) { - pte_t *ptep; - - ptep =3D pte_set_fixmap_offset(pmdp, addr); do { pte_t old_pte =3D __ptep_get(ptep); =20 @@ -193,7 +190,7 @@ static void init_pte(pmd_t *pmdp, unsigned long addr, u= nsigned long end, phys +=3D PAGE_SIZE; } while (ptep++, addr +=3D PAGE_SIZE, addr !=3D end); =20 - pte_clear_fixmap(); + return ptep; } =20 static void alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, @@ -204,6 +201,7 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned l= ong addr, { unsigned long next; pmd_t pmd =3D READ_ONCE(*pmdp); + pte_t *ptep; =20 BUG_ON(pmd_sect(pmd)); if (pmd_none(pmd)) { @@ -219,6 +217,7 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned l= ong addr, } BUG_ON(pmd_bad(pmd)); =20 + ptep =3D pte_set_fixmap_offset(pmdp, addr); do { pgprot_t __prot =3D prot; =20 @@ -229,20 +228,20 @@ static void alloc_init_cont_pte(pmd_t *pmdp, unsigned= long addr, (flags & NO_CONT_MAPPINGS) =3D=3D 0) __prot =3D __pgprot(pgprot_val(prot) | PTE_CONT); =20 - init_pte(pmdp, addr, next, phys, __prot); + ptep =3D init_pte(ptep, addr, next, phys, __prot); =20 phys +=3D next - addr; } while (addr =3D next, addr !=3D end); + + pte_clear_fixmap(); } =20 -static void init_pmd(pud_t *pudp, unsigned long addr, unsigned long end, - phys_addr_t phys, pgprot_t prot, - phys_addr_t (*pgtable_alloc)(int), int flags) +static pmd_t *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; =20 - pmdp =3D pmd_set_fixmap_offset(pudp, addr); do { pmd_t old_pmd =3D READ_ONCE(*pmdp); =20 @@ -269,7 +268,7 @@ static void init_pmd(pud_t *pudp, unsigned long addr, u= nsigned long end, phys +=3D next - addr; } while (pmdp++, addr =3D next, addr !=3D end); =20 - pmd_clear_fixmap(); + return pmdp; } =20 static void alloc_init_cont_pmd(pud_t *pudp, unsigned long addr, @@ -279,6 +278,7 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned l= ong addr, { unsigned long next; pud_t pud =3D READ_ONCE(*pudp); + pmd_t *pmdp; =20 /* * Check for initial section mappings in the pgd/pud. @@ -297,6 +297,7 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned l= ong addr, } BUG_ON(pud_bad(pud)); =20 + pmdp =3D pmd_set_fixmap_offset(pudp, addr); do { pgprot_t __prot =3D prot; =20 @@ -307,10 +308,13 @@ static void alloc_init_cont_pmd(pud_t *pudp, unsigned= long addr, (flags & NO_CONT_MAPPINGS) =3D=3D 0) __prot =3D __pgprot(pgprot_val(prot) | PTE_CONT); =20 - init_pmd(pudp, addr, next, phys, __prot, pgtable_alloc, flags); + pmdp =3D init_pmd(pmdp, addr, next, phys, __prot, pgtable_alloc, + flags); =20 phys +=3D next - addr; } while (addr =3D next, addr !=3D end); + + pmd_clear_fixmap(); } =20 static void alloc_init_pud(p4d_t *p4dp, unsigned long addr, unsigned long = end, --=20 2.25.1