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: 13485849 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A419BC4167B for ; Fri, 8 Dec 2023 21:12:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B39926B0075; Fri, 8 Dec 2023 16:12:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AE8D76B007B; Fri, 8 Dec 2023 16:12:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D7106B008A; Fri, 8 Dec 2023 16:12:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8E5FF6B0075 for ; Fri, 8 Dec 2023 16:12:01 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 603D1A0352 for ; Fri, 8 Dec 2023 21:12:01 +0000 (UTC) X-FDA: 81544898442.15.6467DB6 Received: from gentwo.org (gentwo.org [62.72.0.81]) by imf30.hostedemail.com (Postfix) with ESMTP id B758480020 for ; Fri, 8 Dec 2023 21:11:59 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=gentwo.org; spf=pass (imf30.hostedemail.com: domain of cl@gentwo.org designates 62.72.0.81 as permitted sender) smtp.mailfrom=cl@gentwo.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702069919; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=zDVMhmPmg5GHGjnXQYwlXIuMVRqsgtm3PU1dpvRsplQ=; b=OZuA9vD9mf6VysYnyFb0/ManWC6YJiLYhzmAPYtE6gH5DxXf2//BbWTLd07P9bJFt2nIkP hLgl4q36brWCrjqpmOdV36NSaFDEmrBDA7bSmdFtEOo5b4tAxlRpQFdWUEY7irU4VgHsfU PxaEPNMhfdcC4cRfNSxIHVupem6WCXc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=gentwo.org; spf=pass (imf30.hostedemail.com: domain of cl@gentwo.org designates 62.72.0.81 as permitted sender) smtp.mailfrom=cl@gentwo.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702069919; a=rsa-sha256; cv=none; b=gQnSorRo8Cg7TpdIX4R3icI9r6xLONxwFrx4ZSs1EV0mtsW+cdv/PqxSCYGKGatCU+GEL9 3U8ueh+H4AMPtLqNGik9qZxg1FyDGQD8sOYU1gP06Ytwqhqi/Z2jW6fQ3hpH1qvSOXbZ8n +WLCa/q9F5VW0tgv1mufQrhltQYhB0g= 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-Rspamd-Queue-Id: B758480020 X-Rspam-User: X-Rspamd-Server: rspam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ZHASkHkT3rWD/hGRyO4o8sGXgObSfQxSWgYqQyjudqR196dSHQdZG287S62XQ2R5ZUR0jsPmMQhvc7iZyVNwoh4D7wyc9yehJxvxxiAXbxDdqGp6CddDzITsKS8uWuVNrWEBmowFhOKvrdQ8C63fhzagTlPjh+o0LTyBf04rik9/Xlb5M74HeWK1ALTTWN4FfvHHfBv4N9Oj6dIJdFNk2ZOQMGEPkQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 +