linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Kefeng Wang <wangkefeng.wang@huawei.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	linux-mm@kvack.org
Cc: Zi Yan <ziy@nvidia.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Liam.Howlett@oracle.com,
	Sidhartha Kumar <sidhartha.kumar@oracle.com>
Subject: Re: [PATCH v3 3/3] mm: huge_memory: use folio_needs_prot_numa() for pmd folio
Date: Thu, 16 Oct 2025 21:19:37 +0200	[thread overview]
Message-ID: <fefe4510-c105-4e7b-8468-3ef6e32a244e@redhat.com> (raw)
In-Reply-To: <20251015123516.2703660-4-wangkefeng.wang@huawei.com>

On 15.10.25 14:35, Kefeng Wang wrote:
> Rename prot_numa_skip() to folio_needs_prot_numa(), and remove
> ret by directly return value instead of goto style.
> 
> The folio checks for prot numa should be suitable for pmd folio
> too, which helps to avoid unnecessary pmd change and folio
> migration attempts.

It would be good to describe here which additional checks we are now 
performing in the PMD case.

Because that's a real change.

> 
> Reviewed-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>   mm/huge_memory.c | 21 +++++++--------------
>   mm/internal.h    |  2 ++
>   mm/mprotect.c    | 45 +++++++++++++++++++++++----------------------
>   3 files changed, 32 insertions(+), 36 deletions(-)
> 
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 1d1b74950332..c7364dcb96c1 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -2395,8 +2395,7 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
>   #endif
>   
>   	if (prot_numa) {
> -		struct folio *folio;
> -		bool toptier;
> +		int target_node = NUMA_NO_NODE;
>   		/*
>   		 * Avoid trapping faults against the zero page. The read-only
>   		 * data is likely to be read-cached on the local CPU and
> @@ -2408,19 +2407,13 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
>   		if (pmd_protnone(*pmd))
>   			goto unlock;
>   
> -		folio = pmd_folio(*pmd);
> -		toptier = node_is_toptier(folio_nid(folio));
> -		/*
> -		 * Skip scanning top tier node if normal numa
> -		 * balancing is disabled
> -		 */
> -		if (!(sysctl_numa_balancing_mode & NUMA_BALANCING_NORMAL) &&
> -		    toptier)
> -			goto unlock;
> +		/* Get target node for single threaded private VMAs */
> +		if (!(vma->vm_flags & VM_SHARED) &&
> +		    atomic_read(&vma->vm_mm->mm_users) == 1)
> +			target_node = numa_node_id();
>   
> -		if (folio_use_access_time(folio))
> -			folio_xchg_access_time(folio,
> -					       jiffies_to_msecs(jiffies));
> +		if (!folio_needs_prot_numa(pmd_folio(*pmd), vma, target_node))
> +			goto unlock;
>   	}
>   	/*
>   	 * In case prot_numa, we are under mmap_read_lock(mm). It's critical
> diff --git a/mm/internal.h b/mm/internal.h
> index 1561fc2ff5b8..5f63d5c049b1 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -1378,6 +1378,8 @@ void vunmap_range_noflush(unsigned long start, unsigned long end);
>   
>   void __vunmap_range_noflush(unsigned long start, unsigned long end);
>   
> +bool folio_needs_prot_numa(struct folio *folio, struct vm_area_struct *vma,
> +		int target_node);
>   int numa_migrate_check(struct folio *folio, struct vm_fault *vmf,
>   		      unsigned long addr, int *flags, bool writable,
>   		      int *last_cpupid);
> diff --git a/mm/mprotect.c b/mm/mprotect.c
> index ed44aadb7aaa..0ae8f4a277b2 100644
> --- a/mm/mprotect.c
> +++ b/mm/mprotect.c
> @@ -118,26 +118,30 @@ static int mprotect_folio_pte_batch(struct folio *folio, pte_t *ptep,
>   	return folio_pte_batch_flags(folio, NULL, ptep, &pte, max_nr_ptes, flags);
>   }
>   
> -static bool prot_numa_skip(struct vm_area_struct *vma, int target_node,
> -		struct folio *folio)
> +/**
> + * folio_needs_prot_numa() - Whether the folio needs prot numa
> + * @folio: The folio.
> + * @vma: The VMA mapping.
> + * @target_node: The numa node being accessed.
> + *
> + * Return: Returns true if folio needs prot numa and the access time of
> + *	   folio is adjusted. Returns false otherwise.

I guess you could drop the other Returns like

Return: true if .... Otherwise false.

> + */
> +bool folio_needs_prot_numa(struct folio *folio, struct vm_area_struct *vma,
> +		int target_node)

[...]

>   
>   /* Set nr_ptes number of ptes, starting from idx */
> @@ -314,8 +315,8 @@ static long change_pte_range(struct mmu_gather *tlb,
>   			 * Avoid trapping faults against the zero or KSM
>   			 * pages. See similar comment in change_huge_pmd.
>   			 */
> -			if (prot_numa && prot_numa_skip(vma, target_node,
> -							folio)) {
> +			if (prot_numa && !folio_needs_prot_numa(folio, vma,
> +								target_node)) {

You can fit that into a single line to improve readability. Alternatively

if (prot_numa &&
     !folio_needs ...)

>   				/* determine batch to skip */
>   				nr_ptes = mprotect_folio_pte_batch(folio,
>   					  pte, oldpte, max_nr_ptes, /* flags = */ 0);


-- 
Cheers

David / dhildenb



  reply	other threads:[~2025-10-16 19:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-15 12:35 [PATCH v3 0/3] mm: some optimizations for prot numa Kefeng Wang
2025-10-15 12:35 ` [PATCH v3 1/3] mm: mprotect: always skip dma pinned folio in prot_numa_skip() Kefeng Wang
2025-10-15 15:32   ` Lorenzo Stoakes
2025-10-16  1:00     ` Kefeng Wang
2025-10-16 21:10       ` Andrew Morton
2025-10-17  8:46         ` Lorenzo Stoakes
2025-10-17 14:12         ` Kefeng Wang
2025-10-16  1:14   ` Zi Yan
2025-10-16 17:53   ` Dev Jain
2025-10-15 12:35 ` [PATCH v3 2/3] mm: mprotect: avoid unnecessary struct page accessing if pte_protnone() Kefeng Wang
2025-10-15 15:43   ` Lorenzo Stoakes
2025-10-15 17:45     ` David Hildenbrand
2025-10-16  1:07       ` Kefeng Wang
2025-10-17  8:47         ` Lorenzo Stoakes
2025-10-17  8:46       ` Lorenzo Stoakes
2025-10-16  1:28   ` Zi Yan
2025-10-16  1:35     ` Kefeng Wang
2025-10-16 18:02   ` Dev Jain
2025-10-15 12:35 ` [PATCH v3 3/3] mm: huge_memory: use folio_needs_prot_numa() for pmd folio Kefeng Wang
2025-10-16 19:19   ` David Hildenbrand [this message]
2025-10-17 10:07   ` Lorenzo Stoakes
2025-10-17 14:13     ` Kefeng Wang

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=fefe4510-c105-4e7b-8468-3ef6e32a244e@redhat.com \
    --to=david@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=dev.jain@arm.com \
    --cc=lance.yang@linux.dev \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=ryan.roberts@arm.com \
    --cc=sidhartha.kumar@oracle.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=ziy@nvidia.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