The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wandun Chen" <chenwandun1@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH v2 2/4] mm/mlock: wait for migration to finish when mlocking a folio
Date: Tue, 07 Jul 2026 13:13:52 +0000	[thread overview]
Message-ID: <20260707131353.104F51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707125925.3725177-3-chenwandun1@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Returning ACTION_AGAIN from the PTE loop causes double-counting of folio mlock_count, permanently stranding folios on the unevictable list.
--

--- Patch [2]: [PATCH v2 2/4] mm/mlock: wait for migration to finish when mlocking a folio ---
commit 5e064939ab68367720d5bb81c64aebdb067992b6
Author: Wandun Chen <chenwandun@lixiang.com>

mm/mlock: wait for migration to finish when mlocking a folio

This commit modifies mlock to wait for migration entries when
compaction_allow_unevictable is false. This prevents spike latency in
RT kernels caused by page faults waiting on migration after mlocking.

Link: https://lore.kernel.org/lkml/c8793c0f-7156-4cb7-9e6e-7909397e2fff@kernel.org/#t

> diff --git a/mm/mlock.c b/mm/mlock.c
> index 97e49038d8d33..ac65de40b22b9 100644
> --- a/mm/mlock.c
> +++ b/mm/mlock.c

[ ... ]

> @@ -383,8 +393,17 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr,
>  
>  	for (pte = start_pte; addr != end; pte++, addr += PAGE_SIZE) {
>  		ptent = ptep_get(pte);
> -		if (!pte_present(ptent))
> +		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;

[Severity: High]
Does returning ACTION_AGAIN from within the PTE loop cause mlock_count to be
inflated for previously processed PTEs?

If the loop processes some present PTEs (calling mlock_folio() on them) and
then encounters a migration entry, it returns ACTION_AGAIN. This causes the
generic page table walker to restart the callback from the original PMD start
address:

mm/pagewalk.c:walk_pmd_range() {
again:
	...
	if (ops->pmd_entry)
		err = ops->pmd_entry(pmd, addr, next, walk);
	if (err)
		break;

	if (walk->action == ACTION_AGAIN)
		goto again;
	...
}

Because addr was not advanced in walk_pmd_range(), mlock_pte_range() will
process the earlier PTEs a second time, incrementing folio->mlock_count again.
When the VMA is later unmapped, mlock_count will never reach zero, permanently
stranding these folios on the unevictable list and leaking memory.

> +			}
>  			continue;
> +		}
>  		folio = vm_normal_folio(vma, addr, ptent);
>  		if (!folio || folio_is_zone_device(folio))
>  			continue;

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

  reply	other threads:[~2026-07-07 13:13 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 [this message]
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
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=20260707131353.104F51F000E9@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