[23/31] mm/mglru: allow pte_offset_map_nolock() to fail

Message ID 242721-1e64-845e-226a-bf2b2dc72dd@google.com
State New
Headers
Series mm: allow pte_offset_map[_lock]() to fail |

Commit Message

Hugh Dickins May 22, 2023, 5:19 a.m. UTC
  MGLRU's walk_pte_range() use the safer pte_offset_map_nolock(), rather
than pte_lockptr(), to get the ptl for its trylock.  Just return false
and move on to next extent if it fails, like when the trylock fails.
Remove the VM_WARN_ON_ONCE(pmd_leaf) since that will happen, rarely.

Signed-off-by: Hugh Dickins <hughd@google.com>
---
 mm/vmscan.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)
  

Comments

Yu Zhao May 22, 2023, 5:26 a.m. UTC | #1
On Sun, May 21, 2023 at 11:19 PM Hugh Dickins <hughd@google.com> wrote:
>
> MGLRU's walk_pte_range() use the safer pte_offset_map_nolock(), rather
> than pte_lockptr(), to get the ptl for its trylock.  Just return false
> and move on to next extent if it fails, like when the trylock fails.
> Remove the VM_WARN_ON_ONCE(pmd_leaf) since that will happen, rarely.
>
> Signed-off-by: Hugh Dickins <hughd@google.com>

Acked-by: Yu Zhao <yuzhao@google.com>
  

Patch

diff --git a/mm/vmscan.c b/mm/vmscan.c
index d257916f39e5..1c344589c145 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3992,15 +3992,15 @@  static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
 	struct pglist_data *pgdat = lruvec_pgdat(walk->lruvec);
 	int old_gen, new_gen = lru_gen_from_seq(walk->max_seq);
 
-	VM_WARN_ON_ONCE(pmd_leaf(*pmd));
-
-	ptl = pte_lockptr(args->mm, pmd);
-	if (!spin_trylock(ptl))
+	pte = pte_offset_map_nolock(args->mm, pmd, start & PMD_MASK, &ptl);
+	if (!pte)
 		return false;
+	if (!spin_trylock(ptl)) {
+		pte_unmap(pte);
+		return false;
+	}
 
 	arch_enter_lazy_mmu_mode();
-
-	pte = pte_offset_map(pmd, start & PMD_MASK);
 restart:
 	for (i = pte_index(start), addr = start; addr != end; i++, addr += PAGE_SIZE) {
 		unsigned long pfn;
@@ -4041,10 +4041,8 @@  static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
 	if (i < PTRS_PER_PTE && get_next_vma(PMD_MASK, PAGE_SIZE, args, &start, &end))
 		goto restart;
 
-	pte_unmap(pte);
-
 	arch_leave_lazy_mmu_mode();
-	spin_unlock(ptl);
+	pte_unmap_unlock(pte, ptl);
 
 	return suitable_to_scan(total, young);
 }