From patchwork Fri Apr 12 13:19:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13627765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3448C00A94 for ; Fri, 12 Apr 2024 13:19:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=bJf6f1KuADGr06mRx8v7yZbe74/JdW2+clXdTuBk8fs=; b=Qe2MOMmuxtVF4Y Y1xfI8U1SkzeFkOkGbXQLC+NTxtEaCngdlTmIT5tWUtIrkAnfBCZFFlcAuqDQojDgZX6Vv4bSqWkA XEps0HgKpcb6armJLDGSJ+ylfat++qDUGLw5jicnialoooDeVSEtht4UZwVPfRW/ouC2e9iHjJdk+ t5VmXwyr9I6GUZq3gXD3ENOfdtxDwOYmhA1oOIAjlHE77+b5zsXfQO7uv8H0PEEx0/kEV6Ajf2Z2O nMJl1YCKagpqKW8ENSUMlZcMXZbsKAMh5+NIKMfyaGE0PsNKzgkjmTe2FAHgOa/ZTBH8ys7qVjpI+ vpatA2Kx+c64/l/6+qXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvGoh-0000000HI2T-0X3C; Fri, 12 Apr 2024 13:19:43 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rvGoW-0000000HHv6-1SWW for linux-arm-kernel@lists.infradead.org; Fri, 12 Apr 2024 13:19:38 +0000 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 AF897339; Fri, 12 Apr 2024 06:19:47 -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 36B793F766; Fri, 12 Apr 2024 06:19:17 -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 Subject: [PATCH v3 0/3] Speed up boot with faster linear map creation Date: Fri, 12 Apr 2024 14:19:05 +0100 Message-Id: <20240412131908.433043-1-ryan.roberts@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240412_061934_265359_448E6CDF X-CRM114-Status: GOOD ( 11.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi All, It turns out that creating the linear map can take a significant proportion of the total boot time, especially when rodata=full. And most of the time is spent waiting on superfluous tlb invalidation and memory barriers. This series reworks the kernel pgtable generation code to significantly reduce the number of those TLBIs, ISBs and DSBs. See each patch for details. The below shows the execution time of map_mem() across a couple of different systems with different RAM configurations. We measure after applying each patch and show the improvement relative to base (v6.9-rc2): | Apple M2 VM | Ampere Altra| Ampere Altra| Ampere Altra | VM, 16G | VM, 64G | VM, 256G | Metal, 512G ---------------|-------------|-------------|-------------|------------- | ms (%) | ms (%) | ms (%) | ms (%) ---------------|-------------|-------------|-------------|------------- base | 168 (0%) | 2198 (0%) | 8644 (0%) | 17447 (0%) no-cont-remap | 78 (-53%) | 435 (-80%) | 1723 (-80%) | 3779 (-78%) batch-barriers | 11 (-93%) | 161 (-93%) | 656 (-92%) | 1654 (-91%) no-alloc-remap | 10 (-94%) | 104 (-95%) | 438 (-95%) | 1223 (-93%) This series applies on top of v6.9-rc2. All mm selftests pass. I've compile and boot tested various PAGE_SIZE and VA size configs. Tested-by: Itaru Kitayama Reviewed-by: Mark Rutland Reviewed-by: Ard Biesheuvel --- Changes since v2 [2] ==================== - Independently increment ptep/pmdp in alloc_init_cont_[pte|pmd]() rather than return the incremented value from int_[pte|pmd]() (per Mark) - Removed explicit barriers from alloc_init_cont_pte() and instead rely on the barriers in pte_clear_fixmap() (per Mark) - Significantly simplify approach to avoiding fixmap during alloc (patch 3 reworked) (per Mark) - Dropped patch 4 - not possible with simplified patch 3 and improvement (~2%) didn't warrant complexity (per Mark) Changes since v1 [1] ==================== - Added Tested-by tags (thanks to Eric and Itaru) - Renamed ___set_pte() -> __set_pte_nosync() (per Ard) - Reordered patches (biggest impact & least controversial first) - Reordered alloc/map/unmap functions in mmu.c to aid reader - pte_clear() -> __pte_clear() in clear_fixmap_nosync() - Reverted generic p4d_index() which caused x86 build error. Replaced with unconditional p4d_index() define under arm64. [1] https://lore.kernel.org/linux-arm-kernel/20240326101448.3453626-1-ryan.roberts@arm.com/ [2] https://lore.kernel.org/linux-arm-kernel/20240404143308.2224141-1-ryan.roberts@arm.com/ Thanks, Ryan Ryan Roberts (3): arm64: mm: Don't remap pgtables per-cont(pte|pmd) block arm64: mm: Batch dsb and isb when populating pgtables arm64: mm: Don't remap pgtables for allocate vs populate arch/arm64/include/asm/pgtable.h | 9 ++- arch/arm64/mm/mmu.c | 101 +++++++++++++++++-------------- 2 files changed, 65 insertions(+), 45 deletions(-) -- 2.25.1