From patchwork Fri Dec 8 21:11:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Christoph Lameter (Ampere)" X-Patchwork-Id: 13485851 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 B06C7C4167B for ; Fri, 8 Dec 2023 21:12:33 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:cc:To:From:Date: 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=y5QabML49W/5fyPZwuhf9qv2DQhnQ850LC1f/jdStQU=; b=IpE3jl7zWlMd+Cq284VfVhRkFH rD2qyn/DPe5Flsl52bUiVCfD3Kv9EPrk13JbFKiedU7aPnHxtEkc3nXsqiXjGeMvVMkMGVUOXO2Oc 6sMtRdoLTM2ImK07lpiCFZ5W/JuXOwNp+F1tYl2V+0KJCNERf8q6kYKto0Hy9RLwUy5ntbdvAaBax oHFrnXo/vCfrpCcNgz1l3C1vEon20hTHjQzf0wzfyimcoLtTSonN31DHzNSGYX74hztIMq1yxYgFk mLskXbEBLatIbwcjPOV2JsCckicGnva2mfvOTOhzcENfum2ed+urJSeHP698vmrZ3Q16MDbf4ViUf xD6MPajA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBi8i-00GZuV-0g; Fri, 08 Dec 2023 21:12:04 +0000 Received: from gentwo.org ([62.72.0.81]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBi8g-00GZtj-0k for linux-arm-kernel@lists.infradead.org; Fri, 08 Dec 2023 21:12:03 +0000 Received: by gentwo.org (Postfix, from userid 1003) id 3B1CC48F47; Fri, 8 Dec 2023 13:11:58 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by gentwo.org (Postfix) with ESMTP id 3474848F45; Fri, 8 Dec 2023 13:11:58 -0800 (PST) Date: Fri, 8 Dec 2023 13:11:58 -0800 (PST) From: "Christoph Lameter (Ampere)" To: Catalin Marinas , Marc Zyngier , Will Deacon , Ryan Roberts , Mark Rutland , Vishal Moola cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH] ARM64: Implement arch_report_meminfo() Message-ID: <79f9a0ad-80cc-1fc5-2d48-cc5ba82bd844@gentwo.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231208_131202_292730_31CBC5C7 X-CRM114-Status: GOOD ( 11.15 ) 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 X86 has information in /proc/meminfo showing the use of large mappings for the kernel direct map. This has now also become important for ARM since the kernel default CONFIG_RODATA_FULL_DEFAULT_ENABLED forces 4K PTE use for the direct map and users may not be aware of the performance impact of the increased TLB use etc. The output of /proc/meminfo on ARM64 is then after this patch: 4K page size: Hugepagesize: 2048 kB Hugetlb: 0 kB DirectMap4k: 155912 kB CONT DMap4k: 1176 kB DirectMap2M: 722944 kB CONT DMap2M: 28672 kB DirectMap1G: 534773760 kB 64K page size: Hugepagesize: 524288 kB Hugetlb: 0 kB DirectMap64k: 882624 kB CONT DMap64k: 19904 kB DirectMap512M: 534773760 kB CONT DMap512M: 0 kB DirectMap4096G: 0 kB Signed-off-by: Christoph Lameter Signed-off-by: Christoph Lameter (Ampere) Index: linux/arch/arm64/mm/mmu.c =================================================================== --- linux.orig/arch/arm64/mm/mmu.c +++ linux/arch/arm64/mm/mmu.c @@ -66,6 +66,12 @@ u32 __boot_cpu_mode[] = { BOOT_CPU_MODE_ */ long __section(".mmuoff.data.write") __early_cpu_boot_status; +static atomic_t nr_pte; +static atomic_t nr_pmd; +static atomic_t nr_pud; +static atomic_t nr_pte_cont; +static atomic_t nr_pmd_cont; + /* * Empty_zero_page is a special page that is used for zero-initialized data * and COW. @@ -179,6 +185,7 @@ static void init_pte(pmd_t *pmdp, unsign pte_t old_pte = READ_ONCE(*ptep); set_pte(ptep, pfn_pte(__phys_to_pfn(phys), prot)); + atomic_inc(&nr_pte); /* * After the PTE entry has been populated once, we @@ -223,8 +230,10 @@ static void alloc_init_cont_pte(pmd_t *p /* use a contiguous mapping if the range is suitably aligned */ if ((((addr | next | phys) & ~CONT_PTE_MASK) == 0) && - (flags & NO_CONT_MAPPINGS) == 0) + (flags & NO_CONT_MAPPINGS) == 0) { __prot = __pgprot(pgprot_val(prot) | PTE_CONT); + atomic_inc(&nr_pte_cont); + } init_pte(pmdp, addr, next, phys, __prot); @@ -249,6 +258,7 @@ static void init_pmd(pud_t *pudp, unsign if (((addr | next | phys) & ~PMD_MASK) == 0 && (flags & NO_BLOCK_MAPPINGS) == 0) { pmd_set_huge(pmdp, phys, prot); + atomic_inc(&nr_pmd); /* * After the PMD entry has been populated once, we @@ -301,8 +311,10 @@ static void alloc_init_cont_pmd(pud_t *p /* use a contiguous mapping if the range is suitably aligned */ if ((((addr | next | phys) & ~CONT_PMD_MASK) == 0) && - (flags & NO_CONT_MAPPINGS) == 0) + (flags & NO_CONT_MAPPINGS) == 0) { __prot = __pgprot(pgprot_val(prot) | PTE_CONT); + atomic_inc(&nr_pmd_cont); + } init_pmd(pudp, addr, next, phys, __prot, pgtable_alloc, flags); @@ -346,7 +358,7 @@ static void alloc_init_pud(pgd_t *pgdp, ((addr | next | phys) & ~PUD_MASK) == 0 && (flags & NO_BLOCK_MAPPINGS) == 0) { pud_set_huge(pudp, phys, prot); - + atomic_inc(&nr_pud); /* * After the PUD entry has been populated once, we * only allow updates to the permission attributes. @@ -1486,3 +1498,35 @@ void ptep_modify_prot_commit(struct vm_a { set_pte_at(vma->vm_mm, addr, ptep, pte); } + +#ifdef CONFIG_PROC_FS +void arch_report_meminfo(struct seq_file *m) +{ + unsigned long pagesize_in_kb = PAGE_SIZE / 1024; + + seq_printf(m, "DirectMap%luk: %8lu kB\n", + pagesize_in_kb, + (unsigned long)atomic_read(&nr_pte) * pagesize_in_kb); + + seq_printf(m, "CONT DMap%luk: %8lu kB\n", + pagesize_in_kb, + (unsigned long)atomic_read(&nr_pte_cont) * pagesize_in_kb); + + pagesize_in_kb = PMD_SIZE / 1024; + + seq_printf(m, "DirectMap%luM: %8lu kB\n", + pagesize_in_kb / 1024, + (unsigned long)atomic_read(&nr_pmd) * pagesize_in_kb); + + seq_printf(m, "CONT DMap%luM: %8lu kB\n", + pagesize_in_kb / 1024, + (unsigned long)atomic_read(&nr_pmd_cont) * pagesize_in_kb); + + pagesize_in_kb = PUD_SIZE / 1024; + + seq_printf(m, "DirectMap%luG: %10lu kB\n", + pagesize_in_kb >> 20, + (unsigned long)atomic_read(&nr_pud) * pagesize_in_kb); +} +#endif +