linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhaoyang Huang <huangzhaoyang@gmail.com>
To: Ard Biesheuvel <ardb@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Nicholas Piggin <npiggin@gmail.com>,
	Mike Rapoport <rppt@kernel.org>,
	Pavel Tatashin <pasha.tatashin@soleen.com>,
	Christophe Leroy <christophe.leroy@csgroup.eu>,
	Jonathan Marek <jonathan@marek.ca>,
	Zhaoyang Huang <zhaoyang.huang@unisoc.com>,
	"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH] arch: arm64: try to use PTE_CONT when change page attr
Date: Thu, 18 Nov 2021 19:39:43 +0800	[thread overview]
Message-ID: <CAGWkznG-M985L6Zg89iv3171PWKscZ2cNwdL0F6A_bqs2zs7Dw@mail.gmail.com> (raw)
In-Reply-To: <1637223483-2867-1-git-send-email-huangzhaoyang@gmail.com>

forget the criteria for judging the linear address range, so please
ignore this patch

On Thu, Nov 18, 2021 at 4:18 PM Huangzhaoyang <huangzhaoyang@gmail.com> wrote:
>
> From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
>
> kernel will use the min granularity when rodata_full enabled which
> make TLB pressure high. Furthermore, there is no PTE_CONT applied.
> Try to improve these a little by apply PTE_CONT when change page's
> attr.
>
> Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> ---
>  arch/arm64/mm/pageattr.c | 62 ++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 58 insertions(+), 4 deletions(-)
>
> diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> index a3bacd7..0b6a354 100644
> --- a/arch/arm64/mm/pageattr.c
> +++ b/arch/arm64/mm/pageattr.c
> @@ -61,8 +61,13 @@ static int change_memory_common(unsigned long addr, int numpages,
>         unsigned long start = addr;
>         unsigned long size = PAGE_SIZE * numpages;
>         unsigned long end = start + size;
> +       unsigned long cont_pte_start = 0;
> +       unsigned long cont_pte_end = 0;
> +       unsigned long cont_pmd_start = 0;
> +       unsigned long cont_pmd_end = 0;
> +       pgprot_t orig_set_mask = set_mask;
>         struct vm_struct *area;
> -       int i;
> +       int i = 0;
>
>         if (!PAGE_ALIGNED(addr)) {
>                 start &= PAGE_MASK;
> @@ -98,9 +103,58 @@ static int change_memory_common(unsigned long addr, int numpages,
>          */
>         if (rodata_full && (pgprot_val(set_mask) == PTE_RDONLY ||
>                             pgprot_val(clear_mask) == PTE_RDONLY)) {
> -               for (i = 0; i < area->nr_pages; i++) {
> -                       __change_memory_common((u64)page_address(area->pages[i]),
> -                                              PAGE_SIZE, set_mask, clear_mask);
> +               cont_pmd_start = (start + ~CONT_PMD_MASK + 1) & CONT_PMD_MASK;
> +               cont_pmd_end = cont_pmd_start + ~CONT_PMD_MASK + 1;
> +               cont_pte_start = (start + ~CONT_PTE_MASK + 1) & CONT_PTE_MASK;
> +               cont_pte_end = cont_pte_start + ~CONT_PTE_MASK + 1;
> +
> +               if (addr <= cont_pmd_start && end > cont_pmd_end) {
> +                       do {
> +                               __change_memory_common((u64)page_address(area->pages[i]),
> +                                               PAGE_SIZE, set_mask, clear_mask);
> +                               i++;
> +                               addr++;
> +                       } while(addr < cont_pmd_start);
> +                       do {
> +                               set_mask = __pgprot(pgprot_val(set_mask) | PTE_CONT);
> +                               __change_memory_common((u64)page_address(area->pages[i]),
> +                                               PAGE_SIZE, set_mask, clear_mask);
> +                               i++;
> +                               addr++;
> +                       } while(addr < cont_pmd_end);
> +                       set_mask = orig_set_mask;
> +                       do {
> +                               __change_memory_common((u64)page_address(area->pages[i]),
> +                                               PAGE_SIZE, set_mask, clear_mask);
> +                               i++;
> +                               addr++;
> +                       } while(addr <= end);
> +               } else if (addr <= cont_pte_start && end > cont_pte_end) {
> +                       do {
> +                               __change_memory_common((u64)page_address(area->pages[i]),
> +                                               PAGE_SIZE, set_mask, clear_mask);
> +                               i++;
> +                               addr++;
> +                       } while(addr < cont_pte_start);
> +                       do {
> +                               set_mask = __pgprot(pgprot_val(set_mask) | PTE_CONT);
> +                               __change_memory_common((u64)page_address(area->pages[i]),
> +                                               PAGE_SIZE, set_mask, clear_mask);
> +                               i++;
> +                               addr++;
> +                       } while(addr < cont_pte_end);
> +                       set_mask = orig_set_mask;
> +                       do {
> +                               __change_memory_common((u64)page_address(area->pages[i]),
> +                                               PAGE_SIZE, set_mask, clear_mask);
> +                               i++;
> +                               addr++;
> +                       } while(addr <= end);
> +               } else {
> +                       for (i = 0; i < area->nr_pages; i++) {
> +                               __change_memory_common((u64)page_address(area->pages[i]),
> +                                               PAGE_SIZE, set_mask, clear_mask);
> +                       }
>                 }
>         }
>
> --
> 1.9.1
>

      reply	other threads:[~2021-11-18 11:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18  8:18 [RFC PATCH] arch: arm64: try to use PTE_CONT when change page attr Huangzhaoyang
2021-11-18 11:39 ` Zhaoyang Huang [this message]

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=CAGWkznG-M985L6Zg89iv3171PWKscZ2cNwdL0F6A_bqs2zs7Dw@mail.gmail.com \
    --to=huangzhaoyang@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=jonathan@marek.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=npiggin@gmail.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=rppt@kernel.org \
    --cc=will@kernel.org \
    --cc=zhaoyang.huang@unisoc.com \
    /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;
as well as URLs for NNTP newsgroup(s).