Commit b5ff4133 authored by T.J. Alumbaugh's avatar T.J. Alumbaugh Committed by Andrew Morton

mm: multi-gen LRU: improve walk_pmd_range()

Improve readability of walk_pmd_range() and walk_pmd_range_locked().

Link: https://lkml.kernel.org/r/20230118001827.1040870-7-talumbau@google.comSigned-off-by: default avatarT.J. Alumbaugh <talumbau@google.com>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 37cc9997
...@@ -3999,8 +3999,8 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end, ...@@ -3999,8 +3999,8 @@ static bool walk_pte_range(pmd_t *pmd, unsigned long start, unsigned long end,
} }
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG)
static void walk_pmd_range_locked(pud_t *pud, unsigned long next, struct vm_area_struct *vma, static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area_struct *vma,
struct mm_walk *args, unsigned long *bitmap, unsigned long *start) struct mm_walk *args, unsigned long *bitmap, unsigned long *first)
{ {
int i; int i;
pmd_t *pmd; pmd_t *pmd;
...@@ -4013,18 +4013,19 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long next, struct vm_area ...@@ -4013,18 +4013,19 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long next, struct vm_area
VM_WARN_ON_ONCE(pud_leaf(*pud)); VM_WARN_ON_ONCE(pud_leaf(*pud));
/* try to batch at most 1+MIN_LRU_BATCH+1 entries */ /* try to batch at most 1+MIN_LRU_BATCH+1 entries */
if (*start == -1) { if (*first == -1) {
*start = next; *first = addr;
bitmap_zero(bitmap, MIN_LRU_BATCH);
return; return;
} }
i = next == -1 ? 0 : pmd_index(next) - pmd_index(*start); i = addr == -1 ? 0 : pmd_index(addr) - pmd_index(*first);
if (i && i <= MIN_LRU_BATCH) { if (i && i <= MIN_LRU_BATCH) {
__set_bit(i - 1, bitmap); __set_bit(i - 1, bitmap);
return; return;
} }
pmd = pmd_offset(pud, *start); pmd = pmd_offset(pud, *first);
ptl = pmd_lockptr(args->mm, pmd); ptl = pmd_lockptr(args->mm, pmd);
if (!spin_trylock(ptl)) if (!spin_trylock(ptl))
...@@ -4035,15 +4036,16 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long next, struct vm_area ...@@ -4035,15 +4036,16 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long next, struct vm_area
do { do {
unsigned long pfn; unsigned long pfn;
struct folio *folio; struct folio *folio;
unsigned long addr = i ? (*start & PMD_MASK) + i * PMD_SIZE : *start;
/* don't round down the first address */
addr = i ? (*first & PMD_MASK) + i * PMD_SIZE : *first;
pfn = get_pmd_pfn(pmd[i], vma, addr); pfn = get_pmd_pfn(pmd[i], vma, addr);
if (pfn == -1) if (pfn == -1)
goto next; goto next;
if (!pmd_trans_huge(pmd[i])) { if (!pmd_trans_huge(pmd[i])) {
if (arch_has_hw_nonleaf_pmd_young() && if (arch_has_hw_nonleaf_pmd_young() && get_cap(LRU_GEN_NONLEAF_YOUNG))
get_cap(LRU_GEN_NONLEAF_YOUNG))
pmdp_test_and_clear_young(vma, addr, pmd + i); pmdp_test_and_clear_young(vma, addr, pmd + i);
goto next; goto next;
} }
...@@ -4072,12 +4074,11 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long next, struct vm_area ...@@ -4072,12 +4074,11 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long next, struct vm_area
arch_leave_lazy_mmu_mode(); arch_leave_lazy_mmu_mode();
spin_unlock(ptl); spin_unlock(ptl);
done: done:
*start = -1; *first = -1;
bitmap_zero(bitmap, MIN_LRU_BATCH);
} }
#else #else
static void walk_pmd_range_locked(pud_t *pud, unsigned long next, struct vm_area_struct *vma, static void walk_pmd_range_locked(pud_t *pud, unsigned long addr, struct vm_area_struct *vma,
struct mm_walk *args, unsigned long *bitmap, unsigned long *start) struct mm_walk *args, unsigned long *bitmap, unsigned long *first)
{ {
} }
#endif #endif
...@@ -4090,9 +4091,9 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end, ...@@ -4090,9 +4091,9 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end,
unsigned long next; unsigned long next;
unsigned long addr; unsigned long addr;
struct vm_area_struct *vma; struct vm_area_struct *vma;
unsigned long pos = -1; unsigned long bitmap[BITS_TO_LONGS(MIN_LRU_BATCH)];
unsigned long first = -1;
struct lru_gen_mm_walk *walk = args->private; struct lru_gen_mm_walk *walk = args->private;
unsigned long bitmap[BITS_TO_LONGS(MIN_LRU_BATCH)] = {};
VM_WARN_ON_ONCE(pud_leaf(*pud)); VM_WARN_ON_ONCE(pud_leaf(*pud));
...@@ -4131,18 +4132,17 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end, ...@@ -4131,18 +4132,17 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end,
if (pfn < pgdat->node_start_pfn || pfn >= pgdat_end_pfn(pgdat)) if (pfn < pgdat->node_start_pfn || pfn >= pgdat_end_pfn(pgdat))
continue; continue;
walk_pmd_range_locked(pud, addr, vma, args, bitmap, &pos); walk_pmd_range_locked(pud, addr, vma, args, bitmap, &first);
continue; continue;
} }
#endif #endif
walk->mm_stats[MM_NONLEAF_TOTAL]++; walk->mm_stats[MM_NONLEAF_TOTAL]++;
if (arch_has_hw_nonleaf_pmd_young() && if (arch_has_hw_nonleaf_pmd_young() && get_cap(LRU_GEN_NONLEAF_YOUNG)) {
get_cap(LRU_GEN_NONLEAF_YOUNG)) {
if (!pmd_young(val)) if (!pmd_young(val))
continue; continue;
walk_pmd_range_locked(pud, addr, vma, args, bitmap, &pos); walk_pmd_range_locked(pud, addr, vma, args, bitmap, &first);
} }
if (!walk->force_scan && !test_bloom_filter(walk->lruvec, walk->max_seq, pmd + i)) if (!walk->force_scan && !test_bloom_filter(walk->lruvec, walk->max_seq, pmd + i))
...@@ -4159,7 +4159,7 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end, ...@@ -4159,7 +4159,7 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end,
update_bloom_filter(walk->lruvec, walk->max_seq + 1, pmd + i); update_bloom_filter(walk->lruvec, walk->max_seq + 1, pmd + i);
} }
walk_pmd_range_locked(pud, -1, vma, args, bitmap, &pos); walk_pmd_range_locked(pud, -1, vma, args, bitmap, &first);
if (i < PTRS_PER_PMD && get_next_vma(PUD_MASK, PMD_SIZE, args, &start, &end)) if (i < PTRS_PER_PMD && get_next_vma(PUD_MASK, PMD_SIZE, args, &start, &end))
goto restart; goto restart;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment