The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wandun Chen" <chenwandun1@gmail.com>
Cc: linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/4] mm/migrate: add tracepoint for folios unmapped during migration
Date: Tue, 07 Jul 2026 13:14:04 +0000	[thread overview]
Message-ID: <20260707131405.541091F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707125925.3725177-4-chenwandun1@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Returning ACTION_AGAIN from inside the PTE loop in `mlock_pte_range` causes double-counting of `mlock_count` for folios processed earlier in the same PMD.
--

--- Patch [3]: [PATCH v2 3/4] mm/migrate: add tracepoint for folios unmapped during migration ---
commit 66d2b427e02176d2cc56e534e84b38ba838aacba
Author: Wandun Chen <chenwandun@lixiang.com>

mm/migrate: add tracepoint for folios unmapped during migration

This commit adds the mm_migrate_unmap_folio tracepoint to try_to_migrate_one().
The tracepoint records the PFN, address, and flags when a folio's mapping is
replaced by a migration entry, aiding observation of mlocked folios under
migration.

> diff --git a/mm/rmap.c b/mm/rmap.c
> index d99499ae338f9..d911e6ca62e5b 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -2723,6 +2723,10 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
>  			hugetlb_remove_rmap(folio);
>  		else
>  			folio_remove_rmap_pte(folio, subpage, vma);
> +
> +		trace_mm_migrate_unmap_folio(folio_pfn(folio), address,
> +					     folio->flags.f, vma->vm_flags);
> +

[Severity: High]
When try_to_migrate_one() replaces a mapping with a migration entry here, can
this cause a double-counting issue during concurrent mlock() calls?

If mlock_pte_range() encounters this migration entry midway through a PMD
range, it sets walk->action = ACTION_AGAIN and returns 0:

mm/mlock.c:mlock_pte_range() {
	...
	for (pte = start_pte; addr != end; pte++, addr += PAGE_SIZE) {
		ptent = ptep_get(pte);
		if (!pte_present(ptent)) {
			if (unlikely((vma->vm_flags & VM_LOCKED) &&
			    !compaction_allow_unevictable() &&
			    softleaf_is_migration(softleaf_from_pte(ptent)))) {
				pte_unmap_unlock(start_pte, ptl);
				migration_entry_wait(vma->vm_mm, pmd, addr);
				walk->action = ACTION_AGAIN;
				return 0;
			}
			continue;
		}
		...
		if (vma->vm_flags & VM_LOCKED)
			mlock_folio(folio);
	...
}

Because the page walker handles ACTION_AGAIN by restarting from the beginning
of the PMD without advancing addr, will the folios processed earlier in this
PMD be processed again?

Could this cause mlock_folio() to artificially inflate their mlock_count for
each duplicate pass, permanently stranding the memory in the unevictable LRU?

>  		if (vma->vm_flags & VM_LOCKED)
>  			mlock_drain_local();
>  		folio_put(folio);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260707125925.3725177-1-chenwandun1@gmail.com?part=3

  reply	other threads:[~2026-07-07 13:14 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 12:59 [PATCH v2 0/4] mm: honour compact_unevictable_allowed in mlock and CMA paths Wandun Chen
2026-07-07 12:59 ` [PATCH v2 1/4] mm/migrate: do not migrate folios mapped into VM_LOCKED VMAs under compaction Wandun Chen
2026-07-07 13:44   ` Lorenzo Stoakes
2026-07-07 13:55     ` Lorenzo Stoakes
2026-07-09  8:25       ` Wandun
2026-07-09 15:00         ` Lorenzo Stoakes
2026-07-09  3:31     ` Wandun
2026-07-09 16:10       ` Zi Yan
2026-07-07 12:59 ` [PATCH v2 2/4] mm/mlock: wait for migration to finish when mlocking a folio Wandun Chen
2026-07-07 13:13   ` sashiko-bot
2026-07-07 14:33   ` Lorenzo Stoakes
2026-07-09  8:42     ` Sebastian Andrzej Siewior
2026-07-09 11:50     ` Wandun
2026-07-07 12:59 ` [PATCH v2 3/4] mm/migrate: add tracepoint for folios unmapped during migration Wandun Chen
2026-07-07 13:14   ` sashiko-bot [this message]
2026-07-07 12:59 ` [PATCH v2 4/4] mm/mlock: migrate folios out of CMA when mlocking a range Wandun Chen
2026-07-07 13:13   ` sashiko-bot
2026-07-07 13:36   ` Wandun
2026-07-07 14:57     ` Lorenzo Stoakes
2026-07-07 14:54   ` Lorenzo Stoakes
2026-07-09  9:13     ` Sebastian Andrzej Siewior
2026-07-09 12:25       ` Wandun
2026-07-09 10:04   ` David Hildenbrand (Arm)
2026-07-09 13:15     ` Sebastian Andrzej Siewior

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=20260707131405.541091F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=chenwandun1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /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