Re: [PATCH 09/31] mm/pagewalkers: ACTION_AGAIN if pte_offset_map_lock() fails

From: SeongJae Park
Date: Tue May 23 2023 - 14:07:13 EST


Hello Hugh,

On Sun, 21 May 2023 22:00:15 -0700 (PDT) Hugh Dickins <hughd@xxxxxxxxxx> wrote:

> Simple walk_page_range() users should set ACTION_AGAIN to retry when
> pte_offset_map_lock() fails.
>
> No need to check pmd_trans_unstable(): that was precisely to avoid the
> possiblity of calling pte_offset_map() on a racily removed or inserted
> THP entry, but such cases are now safely handled inside it. Likewise
> there is no need to check pmd_none() or pmd_bad() before calling it.
>
> Signed-off-by: Hugh Dickins <hughd@xxxxxxxxxx>

For below mm/damon part,

Reviewed-by: SeongJae Park <sj@xxxxxxxxxx>


Thanks,
SJ

> ---
> fs/proc/task_mmu.c | 32 ++++++++++++++++----------------
> mm/damon/vaddr.c | 12 ++++++++----
> mm/mempolicy.c | 7 ++++---
> mm/mincore.c | 9 ++++-----
> mm/mlock.c | 4 ++++
> 5 files changed, 36 insertions(+), 28 deletions(-)
>
[...]
> diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
> index 1fec16d7263e..b8762ff15c3c 100644
> --- a/mm/damon/vaddr.c
> +++ b/mm/damon/vaddr.c
> @@ -318,9 +318,11 @@ static int damon_mkold_pmd_entry(pmd_t *pmd, unsigned long addr,
> spin_unlock(ptl);
> }
>
> - if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
> - return 0;
> pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
> + if (!pte) {
> + walk->action = ACTION_AGAIN;
> + return 0;
> + }
> if (!pte_present(*pte))
> goto out;
> damon_ptep_mkold(pte, walk->mm, addr);
> @@ -464,9 +466,11 @@ static int damon_young_pmd_entry(pmd_t *pmd, unsigned long addr,
> regular_page:
> #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>
> - if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
> - return -EINVAL;
> pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
> + if (!pte) {
> + walk->action = ACTION_AGAIN;
> + return 0;
> + }
> if (!pte_present(*pte))
> goto out;
> folio = damon_get_folio(pte_pfn(*pte));
[...]