On Tue, Mar 8, 2022 at 1:34 PM Zach O'Keefe <zokeefe@xxxxxxxxxx> wrote: > > Later in the series, we want to find a pmd and take different actions, > depending on if the pmd maps a thp or not. Currently, mm_find_pmd() > returns NULL if a valid pmd maps a thp, and so we can't use it directly. > > Split mm_find_pmd() into 2 parts: mm_find_pmd_raw(), which returns a > raw pmd pointer, and the logic that filters out non-present none, or > huge pmds. mm_find_pmd_raw() can then be reused later in the series. > > Signed-off-by: Zach O'Keefe <zokeefe@xxxxxxxxxx> > --- > mm/internal.h | 1 + > mm/rmap.c | 15 +++++++++++++-- > 2 files changed, 14 insertions(+), 2 deletions(-) > > diff --git a/mm/internal.h b/mm/internal.h > index 86277d90a5e2..aaea25bb9096 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -166,6 +166,7 @@ extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reason > /* > * in mm/rmap.c: > */ > +pmd_t *mm_find_pmd_raw(struct mm_struct *mm, unsigned long address); > extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address); > > /* > diff --git a/mm/rmap.c b/mm/rmap.c > index 70375c331083..0ae99affcb27 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -758,13 +758,12 @@ unsigned long page_address_in_vma(struct page *page, struct vm_area_struct *vma) > return vma_address(page, vma); > } > > -pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address) > +pmd_t *mm_find_pmd_raw(struct mm_struct *mm, unsigned long address) Typically we have the new helper and the users in the same patch. It would make the review easier. > { > pgd_t *pgd; > p4d_t *p4d; > pud_t *pud; > pmd_t *pmd = NULL; > - pmd_t pmde; > > pgd = pgd_offset(mm, address); > if (!pgd_present(*pgd)) > @@ -779,6 +778,18 @@ pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address) > goto out; > > pmd = pmd_offset(pud, address); > +out: > + return pmd; > +} > + > +pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address) > +{ > + pmd_t pmde; > + pmd_t *pmd; > + > + pmd = mm_find_pmd_raw(mm, address); > + if (!pmd) > + goto out; > /* > * Some THP functions use the sequence pmdp_huge_clear_flush(), set_pmd_at() > * without holding anon_vma lock for write. So when looking for a > -- > 2.35.1.616.g0bdcbb4464-goog >