linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: "Christoph Lameter (Ampere)" <cl@gentwo.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Marc Zyngier <maz@kernel.org>, Will Deacon <will@kernel.org>,
	Ryan Roberts <ryan.roberts@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Vishal Moola <vishal.moola@gmail.com>
Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org
Subject: Re: [PATCH] ARM64: Implement arch_report_meminfo()
Date: Thu, 14 Dec 2023 13:02:00 +0000	[thread overview]
Message-ID: <b0d7b928-ecc5-4203-8269-423dee08b1ff@arm.com> (raw)
In-Reply-To: <79f9a0ad-80cc-1fc5-2d48-cc5ba82bd844@gentwo.org>

On 2023-12-08 9:11 pm, Christoph Lameter (Ampere) wrote:
> 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 <cl@linux.com>
> 
> 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);

It seems somewhat suspect that these counts only ever increase. It's not 
often that we change or remove parts of the linear map, but it certainly 
can happen.

Thanks,
Robin.

>               /*
>                * 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
> +
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


  parent reply	other threads:[~2023-12-14 13:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-08 21:11 Christoph Lameter (Ampere)
2023-12-12 18:31 ` Yang Shi
2023-12-14  5:25   ` Christoph Lameter (Ampere)
2023-12-14 13:02 ` Robin Murphy [this message]
2023-12-14 21:35   ` Christoph Lameter (Ampere)
2023-12-15 19:44     ` Robin Murphy
2023-12-18 17:49       ` Christoph Lameter (Ampere)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b0d7b928-ecc5-4203-8269-423dee08b1ff@arm.com \
    --to=robin.murphy@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=cl@gentwo.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=vishal.moola@gmail.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox