mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yin Tirui <yintirui@gmail.com>
To: akpm@linux-foundation.org, david@kernel.org, ziy@nvidia.com
Cc: ljs@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com,
	baohua@kernel.org, lance.yang@linux.dev, ryan.roberts@arm.com,
	nico.pache@linux.dev, usama.arif@linux.dev, liam@infradead.org,
	kas@kernel.org, wangkefeng.wang@huawei.com,
	chenjun102@huawei.com, yintirui@gmail.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH RFC v2 4/9] mm/huge_memory: use normal_or_softleaf_folio_pmd() in the PMD split path
Date: Wed, 11 Nov 2026 01:59:19 +0800	[thread overview]
Message-ID: <20261110175924.2945538-5-yintirui@gmail.com> (raw)
In-Reply-To: <20261110175924.2945538-1-yintirui@gmail.com>

Get the folio once with normal_or_softleaf_folio_pmd() and decide the
deposit once with vma_has_deposited_pgtable(), as zap_huge_pmd() does. That
makes split and zap classify an entry the same way, and drops
vma_is_mm_managed() from this path.

Behaviour changes only where the entry and the VMA flags disagree, which no
in-tree path produces.

Signed-off-by: Yin Tirui <yintirui@gmail.com>
---
 mm/huge_memory.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 85813114fde1..d0ff2957e47f 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3217,7 +3217,7 @@ static void unmap_huge_pmd_entry(struct vm_area_struct *vma,
 	 * We are going to unmap this huge page. So
 	 * just go ahead and zap it
 	 */
-	if (arch_needs_pgtable_deposit())
+	if (vma_has_deposited_pgtable(vma))
 		zap_deposited_table(mm, pmd);
 
 	if (!folio)
@@ -3244,6 +3244,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
 {
 	struct mm_struct *mm = vma->vm_mm;
 	pmd_t old_pmd = *pmd;
+	const bool is_present = pmd_present(old_pmd);
 	struct folio *folio;
 	struct page *page;
 	pgtable_t pgtable;
@@ -3277,16 +3278,18 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
 		return;
 	}
 
-	if (!vma_is_anonymous(vma)) {
-		const bool is_present = pmd_present(old_pmd);
+	folio = normal_or_softleaf_folio_pmd(vma, haddr, old_pmd, is_present);
 
-		if (!vma_is_mm_managed(vma) || is_huge_zero_pmd(old_pmd))
-			folio = NULL;
-		else if (is_present)
-			folio = page_folio(pmd_page(old_pmd));
-		else
-			folio = softleaf_to_folio(softleaf_from_pmd(old_pmd));
+	/*
+	 * A non-present entry which is neither a migration nor a device
+	 * private entry is corrupt, and pmd_to_softleaf_folio() has already
+	 * warned about it. Leave it alone rather than act on a PFN which
+	 * means nothing.
+	 */
+	if (unlikely(!is_present && !folio))
+		return;
 
+	if (!vma_is_anonymous(vma)) {
 		unmap_huge_pmd_entry(vma, haddr, pmd, folio, is_present);
 		return;
 	}
-- 
2.34.1


  parent reply	other threads:[~2026-11-10 18:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 17:59 [PATCH RFC v2 0/9] mm/huge_memory: refactor __split_huge_pmd_locked() Yin Tirui
2026-11-10 17:59 ` [PATCH RFC v2 1/9] mm/huge_memory: read the huge PMD entry once when splitting it Yin Tirui
2026-11-10 17:59 ` [PATCH RFC v2 2/9] mm/huge_memory: add and use huge_zero_pmd_can_split() Yin Tirui
2026-11-10 17:59 ` [PATCH RFC v2 3/9] mm/huge_memory: add and use unmap_huge_pmd_entry() Yin Tirui
2026-11-10 17:59 ` Yin Tirui [this message]
2026-11-10 17:59 ` [PATCH RFC v2 5/9] mm/huge_memory: dispatch on the folio when splitting a huge PMD Yin Tirui
2026-11-10 17:59 ` [PATCH RFC v2 6/9] mm/huge_memory: add and use split_huge_pmd_anon_rmap() Yin Tirui
2026-11-10 17:59 ` [PATCH RFC v2 7/9] mm/huge_memory: add struct split_pmd_state Yin Tirui
2026-11-10 17:59 ` [PATCH RFC v2 8/9] mm/huge_memory: split present and non-present huge PMDs separately Yin Tirui
2026-11-10 17:59 ` [PATCH RFC v2 9/9] mm/huge_memory: unify the migration and device private PTE loops Yin Tirui

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=20261110175924.2945538-5-yintirui@gmail.com \
    --to=yintirui@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=chenjun102@huawei.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=nico.pache@linux.dev \
    --cc=ryan.roberts@arm.com \
    --cc=usama.arif@linux.dev \
    --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

all inboxes | Powered by JetHome®