linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: Wei Yang <richard.weiyang@gmail.com>
Cc: linux-mm@kvack.org, dev.jain@arm.com,
	Usama Arif <usamaarif642@gmail.com>,
	baohua@kernel.org, Matthew Wilcox <willy@infradead.org>,
	david@redhat.com, ziy@nvidia.com, akpm@linux-foundation.org,
	ryan.roberts@arm.com, baolin.wang@linux.alibaba.com,
	npache@redhat.com, lorenzo.stoakes@oracle.com,
	Liam.Howlett@oracle.com
Subject: Re: [Patch v2] mm/khugepaged: unify pmd folio installation with map_anon_folio_pmd()
Date: Tue, 7 Oct 2025 09:16:51 +0800	[thread overview]
Message-ID: <32f2278f-2491-49d1-8c9b-5b359a2dacbb@linux.dev> (raw)
In-Reply-To: <20251007005022.24413-1-richard.weiyang@gmail.com>



On 2025/10/7 08:50, Wei Yang wrote:
> Currently we install pmd folio with map_anon_folio_pmd() in
> __do_huge_pmd_anonymous_page() and do_huge_zero_wp_pmd(). While in
> collapse_huge_page(), it is done with identical code except statistics
> adjustment.
> 
> Unify the process with map_anon_folio_pmd() to install pmd folio. Split
> it to map_anon_folio_pmd_pf() and map_anon_folio_pmd_nopf() to be used
> in page fault or not respectively.
> 
> No functional change is intended.
> 
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Lance Yang <lance.yang@linux.dev>
> Cc: Dev Jain <dev.jain@arm.com>
> Cc: Zi Yan <ziy@nvidia.com>
> Cc: Usama Arif <usamaarif642@gmail.com>
> Cc: Matthew Wilcox <willy@infradead.org>

Nice cleanup!

Acked-by: Lance Yang <lance.yang@linux.dev>

But one nit below.

> 
> ---
> v2:
>    * split to map_anon_folio_pmd_[no]pf() suggested by Matthew
> ---
>   include/linux/huge_mm.h |  6 ++++++
>   mm/huge_memory.c        | 14 ++++++++++----
>   mm/khugepaged.c         |  9 +--------
>   3 files changed, 17 insertions(+), 12 deletions(-)
> 
> diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> index e3ed008a076a..277ade3b7640 100644
> --- a/include/linux/huge_mm.h
> +++ b/include/linux/huge_mm.h
> @@ -539,6 +539,8 @@ void split_huge_pmd_locked(struct vm_area_struct *vma, unsigned long address,
>   			   pmd_t *pmd, bool freeze);
>   bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr,
>   			   pmd_t *pmdp, struct folio *folio);
> +void map_anon_folio_pmd_nopf(struct folio *folio, pmd_t *pmd,
> +		struct vm_area_struct *vma, unsigned long haddr);
>   
>   #else /* CONFIG_TRANSPARENT_HUGEPAGE */
>   
> @@ -629,6 +631,10 @@ static inline bool unmap_huge_pmd_locked(struct vm_area_struct *vma,
>   	return false;
>   }
>   
> +void map_anon_folio_pmd_nopf(struct folio *folio, pmd_t *pmd,
> +		struct vm_area_struct *vma, unsigned long haddr)
> +{}

Nit: can you put the braces on separate lines?

+void map_anon_folio_pmd_nopf(struct folio *folio, pmd_t *pmd,
+		struct vm_area_struct *vma, unsigned long haddr)
+{
+}

AFAIK, this is the preferred style in kernel for empty function bodies.

> +
>   #define split_huge_pud(__vma, __pmd, __address)	\
>   	do { } while (0)
>   
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index f13de93637bf..88960530b1d5 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -1217,7 +1217,7 @@ static struct folio *vma_alloc_anon_folio_pmd(struct vm_area_struct *vma,
>   	return folio;
>   }
>   
> -static void map_anon_folio_pmd(struct folio *folio, pmd_t *pmd,
> +void map_anon_folio_pmd_nopf(struct folio *folio, pmd_t *pmd,
>   		struct vm_area_struct *vma, unsigned long haddr)
>   {
>   	pmd_t entry;
> @@ -1228,11 +1228,17 @@ static void map_anon_folio_pmd(struct folio *folio, pmd_t *pmd,
>   	folio_add_lru_vma(folio, vma);
>   	set_pmd_at(vma->vm_mm, haddr, pmd, entry);
>   	update_mmu_cache_pmd(vma, haddr, pmd);
> +	deferred_split_folio(folio, false);
> +}
> +
> +static void map_anon_folio_pmd_pf(struct folio *folio, pmd_t *pmd,
> +		struct vm_area_struct *vma, unsigned long haddr)
> +{
> +	map_anon_folio_pmd_nopf(folio, pmd, vma, haddr);
>   	add_mm_counter(vma->vm_mm, MM_ANONPAGES, HPAGE_PMD_NR);
>   	count_vm_event(THP_FAULT_ALLOC);
>   	count_mthp_stat(HPAGE_PMD_ORDER, MTHP_STAT_ANON_FAULT_ALLOC);
>   	count_memcg_event_mm(vma->vm_mm, THP_FAULT_ALLOC);
> -	deferred_split_folio(folio, false);
>   }
>   
>   static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf)
> @@ -1271,7 +1277,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf)
>   			return ret;
>   		}
>   		pgtable_trans_huge_deposit(vma->vm_mm, vmf->pmd, pgtable);
> -		map_anon_folio_pmd(folio, vmf->pmd, vma, haddr);
> +		map_anon_folio_pmd_pf(folio, vmf->pmd, vma, haddr);
>   		mm_inc_nr_ptes(vma->vm_mm);
>   		spin_unlock(vmf->ptl);
>   	}
> @@ -1877,7 +1883,7 @@ static vm_fault_t do_huge_zero_wp_pmd(struct vm_fault *vmf)
>   	if (ret)
>   		goto release;
>   	(void)pmdp_huge_clear_flush(vma, haddr, vmf->pmd);
> -	map_anon_folio_pmd(folio, vmf->pmd, vma, haddr);
> +	map_anon_folio_pmd_pf(folio, vmf->pmd, vma, haddr);
>   	goto unlock;
>   release:
>   	folio_put(folio);
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index f4f57ba69d72..ce7181b6ae4e 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -1224,17 +1224,10 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address,
>   	__folio_mark_uptodate(folio);
>   	pgtable = pmd_pgtable(_pmd);
>   
> -	_pmd = folio_mk_pmd(folio, vma->vm_page_prot);
> -	_pmd = maybe_pmd_mkwrite(pmd_mkdirty(_pmd), vma);
> -
>   	spin_lock(pmd_ptl);
>   	BUG_ON(!pmd_none(*pmd));
> -	folio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE);
> -	folio_add_lru_vma(folio, vma);
>   	pgtable_trans_huge_deposit(mm, pmd, pgtable);
> -	set_pmd_at(mm, address, pmd, _pmd);
> -	update_mmu_cache_pmd(vma, address, pmd);
> -	deferred_split_folio(folio, false);
> +	map_anon_folio_pmd_nopf(folio, pmd, vma, address);
>   	spin_unlock(pmd_ptl);
>   
>   	folio = NULL;



  reply	other threads:[~2025-10-07  1:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07  0:50 Wei Yang
2025-10-07  1:16 ` Lance Yang [this message]
2025-10-07  4:06 ` Anshuman Khandual
2025-10-07  9:54   ` Dev Jain
2025-10-07 12:24     ` Lance Yang
2025-10-07 13:11       ` Dev Jain
2025-10-07 14:59         ` Zi Yan
2025-10-08  1:20           ` Wei Yang
2025-10-07  8:53 ` David Hildenbrand
2025-10-07 15:05 ` Zi Yan

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=32f2278f-2491-49d1-8c9b-5b359a2dacbb@linux.dev \
    --to=lance.yang@linux.dev \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=dev.jain@arm.com \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=npache@redhat.com \
    --cc=richard.weiyang@gmail.com \
    --cc=ryan.roberts@arm.com \
    --cc=usamaarif642@gmail.com \
    --cc=willy@infradead.org \
    --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