From: "Zach O'Keefe" <zokeefe@google.com>
To: Yang Shi <shy828301@gmail.com>
Cc: Vlastimil Babka <vbabka@suse.cz>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Matthew Wilcox <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Linux MM <linux-mm@kvack.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [v3 PATCH 4/7] mm: khugepaged: use transhuge_vma_suitable replace open-code
Date: Fri, 10 Jun 2022 17:27:51 -0700 [thread overview]
Message-ID: <CAAa6QmT4mvpLMdtRV+tJJsPBBbPGuWVzKs5eoFBahG0s_Mba0Q@mail.gmail.com> (raw)
In-Reply-To: <CAHbLzkpOQrshbBDfHjGVDbpcfdV7hgiwav6TyaZTzm_cq4PeDw@mail.gmail.com>
On Fri, Jun 10, 2022 at 3:04 PM Yang Shi <shy828301@gmail.com> wrote:
>
> On Fri, Jun 10, 2022 at 9:59 AM Yang Shi <shy828301@gmail.com> wrote:
> >
> > On Thu, Jun 9, 2022 at 6:52 PM Zach O'Keefe <zokeefe@google.com> wrote:
> > >
> > > On Mon, Jun 6, 2022 at 2:44 PM Yang Shi <shy828301@gmail.com> wrote:
> > > >
> > > > The hugepage_vma_revalidate() needs to check if the address is still in
> > > > the aligned HPAGE_PMD_SIZE area of the vma when reacquiring mmap_lock,
> > > > but it was open-coded, use transhuge_vma_suitable() to do the job. And
> > > > add proper comments for transhuge_vma_suitable().
> > > >
> > > > Signed-off-by: Yang Shi <shy828301@gmail.com>
> > > > ---
> > > > include/linux/huge_mm.h | 6 ++++++
> > > > mm/khugepaged.c | 5 +----
> > > > 2 files changed, 7 insertions(+), 4 deletions(-)
> > > >
> > > > diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
> > > > index a8f61db47f2a..79d5919beb83 100644
> > > > --- a/include/linux/huge_mm.h
> > > > +++ b/include/linux/huge_mm.h
> > > > @@ -128,6 +128,12 @@ static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma)
> > > > return false;
> > > > }
> > > >
> > > > +/*
> > > > + * Do the below checks:
> > > > + * - For non-anon vma, check if the vm_pgoff is HPAGE_PMD_NR aligned.
> > > > + * - For all vmas, check if the haddr is in an aligned HPAGE_PMD_SIZE
> > > > + * area.
> > > > + */
> > >
> > > AFAIK we aren't checking if vm_pgoff is HPAGE_PMD_NR aligned, but
> > > rather that linear_page_index(vma, round_up(vma->vm_start,
> > > HPAGE_PMD_SIZE)) is HPAGE_PMD_NR aligned within vma->vm_file. I was
> >
> > Yeah, you are right.
> >
> > > pretty confused about this (hopefully I have it right now - if not -
> > > case and point :) ), so it might be a good opportunity to add some
> > > extra commentary to help future travelers understand why this
> > > constraint exists.
> >
> > I'm not fully sure I understand this 100%. I think this is related to
> > how page cache is structured. I will try to add more comments.
>
> How's about "The underlying THP is always properly aligned in page
> cache, but it may be across the boundary of VMA if the VMA is
> misaligned, so the THP can't be PMD mapped for this case."
I could certainly still be wrong / am learning here - but I *thought*
the reason for this check was to make sure that the hugepage
to-be-collapsed is naturally aligned within the file (since, AFAIK,
without this constraint, different mm's might have different ideas
about where hugepages in the file should be).
> >
> > >
> > > Also I wonder while we're at it if we can rename this to
> > > transhuge_addr_aligned() or transhuge_addr_suitable() or something.
> >
> > I think it is still actually used to check vma.
> >
> > >
> > > Otherwise I think the change is a nice cleanup.
> > >
> > > > static inline bool transhuge_vma_suitable(struct vm_area_struct *vma,
> > > > unsigned long addr)
> > > > {
> > > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> > > > index 7a5d1c1a1833..ca1754d3a827 100644
> > > > --- a/mm/khugepaged.c
> > > > +++ b/mm/khugepaged.c
> > > > @@ -951,7 +951,6 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
> > > > struct vm_area_struct **vmap)
> > > > {
> > > > struct vm_area_struct *vma;
> > > > - unsigned long hstart, hend;
> > > >
> > > > if (unlikely(khugepaged_test_exit(mm)))
> > > > return SCAN_ANY_PROCESS;
> > > > @@ -960,9 +959,7 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
> > > > if (!vma)
> > > > return SCAN_VMA_NULL;
> > > >
> > > > - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
> > > > - hend = vma->vm_end & HPAGE_PMD_MASK;
> > > > - if (address < hstart || address + HPAGE_PMD_SIZE > hend)
> > > > + if (!transhuge_vma_suitable(vma, address))
> > > > return SCAN_ADDRESS_RANGE;
> > > > if (!hugepage_vma_check(vma, vma->vm_flags))
> > > > return SCAN_VMA_CHECK;
> > > > --
> > > > 2.26.3
> > > >
> > > >
next prev parent reply other threads:[~2022-06-11 0:28 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-06 21:44 [mm-unstable v3 PATCH 0/7] Cleanup transhuge_xxx helpers Yang Shi
2022-06-06 21:44 ` [v3 PATCH 1/7] mm: khugepaged: check THP flag in hugepage_vma_check() Yang Shi
2022-06-09 17:49 ` Zach O'Keefe
2022-06-10 7:09 ` Miaohe Lin
2022-06-06 21:44 ` [v3 PATCH 2/7] mm: thp: introduce transhuge_vma_size_ok() helper Yang Shi
2022-06-09 22:21 ` Zach O'Keefe
2022-06-10 0:08 ` Yang Shi
2022-06-10 0:51 ` Zach O'Keefe
2022-06-10 16:38 ` Yang Shi
2022-06-10 21:24 ` Yang Shi
2022-06-10 7:20 ` Miaohe Lin
2022-06-10 16:47 ` Yang Shi
2022-06-06 21:44 ` [v3 PATCH 3/7] mm: khugepaged: remove the redundant anon vma check Yang Shi
2022-06-09 23:23 ` Zach O'Keefe
2022-06-10 0:01 ` Yang Shi
2022-06-10 7:23 ` Miaohe Lin
2022-06-10 7:28 ` Miaohe Lin
2022-06-06 21:44 ` [v3 PATCH 4/7] mm: khugepaged: use transhuge_vma_suitable replace open-code Yang Shi
2022-06-10 1:51 ` Zach O'Keefe
2022-06-10 16:59 ` Yang Shi
2022-06-10 22:03 ` Yang Shi
2022-06-11 0:27 ` Zach O'Keefe [this message]
2022-06-11 3:25 ` Yang Shi
2022-06-11 21:43 ` Zach O'Keefe
2022-06-14 17:40 ` Yang Shi
2022-06-06 21:44 ` [v3 PATCH 5/7] mm: thp: kill transparent_hugepage_active() Yang Shi
2022-06-10 1:02 ` Zach O'Keefe
2022-06-10 17:02 ` Yang Shi
2022-06-13 15:06 ` Zach O'Keefe
2022-06-14 19:16 ` Yang Shi
2022-06-06 21:44 ` [v3 PATCH 6/7] mm: thp: kill __transhuge_page_enabled() Yang Shi
2022-06-10 2:22 ` Zach O'Keefe
2022-06-10 17:24 ` Yang Shi
2022-06-10 21:07 ` Yang Shi
2022-06-13 14:54 ` Zach O'Keefe
2022-06-14 18:51 ` Yang Shi
2022-06-14 23:55 ` Zach O'Keefe
2022-06-06 21:44 ` [v3 PATCH 7/7] mm: khugepaged: reorg some khugepaged helpers Yang Shi
2022-06-09 23:32 ` [mm-unstable v3 PATCH 0/7] Cleanup transhuge_xxx helpers Zach O'Keefe
2022-06-10 7:08 ` Miaohe Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAAa6QmT4mvpLMdtRV+tJJsPBBbPGuWVzKs5eoFBahG0s_Mba0Q@mail.gmail.com \
--to=zokeefe@google.com \
--cc=akpm@linux-foundation.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shy828301@gmail.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).