Re: [PATCH 3/9] mm/damon/vaddr: cleanup using pmd_trans_huge_lock()

From: SeongJae Park
Date: Mon Nov 17 2025 - 10:44:38 EST


On Wed, 12 Nov 2025 07:41:06 -0800 SeongJae Park <sj@xxxxxxxxxx> wrote:

> Three pmd walk functions in vaddr.c are using pmd_trans_huge() and
> pmd_lock() to handle THPs. Simplify the code by replacing the two
> function calls with a single pmd_trans_huge_lock() call.
>
> Note that this cleanup is not only reducing the lines of code, but also
> simplifies code execution flows for migration entries case, as kindly
> explained [1] by Hugh, who suggested this cleanup.
>
> [1] https://lore.kernel.org/296c2b3f-6748-158f-b85d-2952165c0588@xxxxxxxxxx
>
> Suggested-by: Hugh Dickins <hughd@xxxxxxxxxx>
> Signed-off-by: SeongJae Park <sj@xxxxxxxxxx>
> ---
> mm/damon/vaddr.c | 48 ++++++++++++------------------------------------
> 1 file changed, 12 insertions(+), 36 deletions(-)
>
> diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
> index 7e834467b2d8..0ad1ce120aa1 100644
> --- a/mm/damon/vaddr.c
> +++ b/mm/damon/vaddr.c
> @@ -307,24 +307,14 @@ static int damon_mkold_pmd_entry(pmd_t *pmd, unsigned long addr,
> unsigned long next, struct mm_walk *walk)
> {
> pte_t *pte;
> - pmd_t pmde;
> spinlock_t *ptl;
>
> - if (pmd_trans_huge(pmdp_get(pmd))) {
> - ptl = pmd_lock(walk->mm, pmd);
> - pmde = pmdp_get(pmd);
> -
> - if (!pmd_present(pmde)) {
> - spin_unlock(ptl);
> - return 0;
> - }
> -
> - if (pmd_trans_huge(pmde)) {
> + ptl = pmd_trans_huge_lock(pmd, walk->vma);
> + if (ptl) {
> + if (pmd_present(pmdp_get(pmd)))
> damon_pmdp_mkold(pmd, walk->vma, addr);
> - spin_unlock(ptl);
> - return 0;
> - }
> spin_unlock(ptl);
> + return 0;
> }
>
> pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
> @@ -446,21 +436,12 @@ static int damon_young_pmd_entry(pmd_t *pmd, unsigned long addr,
> struct damon_young_walk_private *priv = walk->private;
>
> #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> - if (pmd_trans_huge(pmdp_get(pmd))) {
> - pmd_t pmde;
> -
> - ptl = pmd_lock(walk->mm, pmd);
> - pmde = pmdp_get(pmd);
> + ptl = pmd_trans_huge_lock(pmd, walk->vma);
> + if (ptl) {
> + pmd_t pmde = pmdp_get(pmd);

Kernel test robot reported [1] this is making m68k build fails. Andrew, could
you please add below attaching patch as a fix?

[1] https://lore.kernel.org/202511172257.CjElDcRX-lkp@xxxxxxxxx


Thanks,
SJ

[...]

---- >8 ----