lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHbLzkrxzLs4Ye9oPLJU_xNYBC7SGs_r0q9mznXFmKuaFPmHGw@mail.gmail.com>
Date:   Tue, 10 May 2022 15:35:13 -0700
From:   Yang Shi <shy828301@...il.com>
To:     Andrew Morton <akpm@...ux-foundation.org>
Cc:     Vlastimil Babka <vbabka@...e.cz>,
        "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
        Miaohe Lin <linmiaohe@...wei.com>,
        Song Liu <songliubraving@...com>,
        Rik van Riel <riel@...riel.com>,
        Matthew Wilcox <willy@...radead.org>, Zi Yan <ziy@...dia.com>,
        "Theodore Ts'o" <tytso@....edu>, Linux MM <linux-mm@...ck.org>,
        Linux FS-devel Mailing List <linux-fsdevel@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [v4 PATCH 6/8] mm: khugepaged: make hugepage_vma_check() non-static

On Tue, May 10, 2022 at 2:05 PM Andrew Morton <akpm@...ux-foundation.org> wrote:
>
> On Tue, 10 May 2022 13:32:20 -0700 Yang Shi <shy828301@...il.com> wrote:
>
> > The hugepage_vma_check() could be reused by khugepaged_enter() and
> > khugepaged_enter_vma_merge(), but it is static in khugepaged.c.
> > Make it non-static and declare it in khugepaged.h.
> >
> > ..
> >
> > @@ -508,20 +508,13 @@ void __khugepaged_enter(struct mm_struct *mm)
> >  void khugepaged_enter_vma_merge(struct vm_area_struct *vma,
> >                              unsigned long vm_flags)
> >  {
> > -     unsigned long hstart, hend;
> > -
> > -     /*
> > -      * khugepaged only supports read-only files for non-shmem files.
> > -      * khugepaged does not yet work on special mappings. And
> > -      * file-private shmem THP is not supported.
> > -      */
> > -     if (!hugepage_vma_check(vma, vm_flags))
> > -             return;
> > -
> > -     hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK;
> > -     hend = vma->vm_end & HPAGE_PMD_MASK;
> > -     if (hstart < hend)
> > -             khugepaged_enter(vma, vm_flags);
> > +     if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) &&
> > +         khugepaged_enabled() &&
> > +         (((vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK) <
> > +          (vma->vm_end & HPAGE_PMD_MASK))) {
>
> Reviewing these bounds-checking tests is so hard :(  Can we simplify?

Yeah, I think they can be moved into a helper with a more descriptive name.

>
> > +             if (hugepage_vma_check(vma, vm_flags))
> > +                     __khugepaged_enter(vma->vm_mm);
> > +     }
> >  }
>
> void khugepaged_enter_vma(struct vm_area_struct *vma,
>                           unsigned long vm_flags)
> {
>         if (test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags))
>                 return;
>         if (!khugepaged_enabled())
>                 return;
>         if (round_up(vma->vm_start, HPAGE_PMD_SIZE) >=
>                         (vma->vm_end & HPAGE_PMD_MASK))
>                 return;         /* vma is too small */
>         if (!hugepage_vma_check(vma, vm_flags))
>                 return;
>         __khugepaged_enter(vma->vm_mm);
> }
>
>
> Also, it might be slightly faster to have checked MMF_VM_HUGEPAGE
> before khugepaged_enabled(), but it looks odd.  And it might be slower,
> too - more pointer chasing.

I think most configurations have always or madvise mode set
(khugepaged_enabled() return true), so having checked MMF_VM_HUGEPAGE
before khugepaged_enabled() seems slightly better, but anyway it
should not have measurable effect IMHO.

>
> I wish someone would document hugepage_vma_check().

I will clean up all the stuff further in a new patchset, for example,
trying to consolidate all the different
hugepage_suitable/enabled/active checks.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ