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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGsJ_4wxPk+bk9UM+PvA3x=LJG+mWmTD3e2HSEsS83X3vMWTJQ@mail.gmail.com>
Date: Mon, 3 Jun 2024 16:14:39 +1200
From: Barry Song <21cnbao@...il.com>
To: Lance Yang <ioworker0@...il.com>
Cc: akpm@...ux-foundation.org, ryan.roberts@....com, david@...hat.com, 
	baolin.wang@...ux.alibaba.com, ziy@...dia.com, fengwei.yin@...el.com, 
	ying.huang@...el.com, libang.li@...group.com, linux-mm@...ck.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/1] mm/mlock: implement folio_mlock_step() using folio_pte_batch()

On Mon, Jun 3, 2024 at 3:31 PM Lance Yang <ioworker0@...il.com> wrote:
>
> Let's make folio_mlock_step() simply a wrapper around folio_pte_batch(),
> which will greatly reduce the cost of ptep_get() when scanning a range of
> contptes.
>
> Signed-off-by: Lance Yang <ioworker0@...il.com>
> ---
>  mm/mlock.c | 23 ++++++-----------------
>  1 file changed, 6 insertions(+), 17 deletions(-)
>
> diff --git a/mm/mlock.c b/mm/mlock.c
> index 30b51cdea89d..1ae6232d38cf 100644
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -307,26 +307,15 @@ void munlock_folio(struct folio *folio)
>  static inline unsigned int folio_mlock_step(struct folio *folio,
>                 pte_t *pte, unsigned long addr, unsigned long end)
>  {
> -       unsigned int count, i, nr = folio_nr_pages(folio);
> -       unsigned long pfn = folio_pfn(folio);
> -       pte_t ptent = ptep_get(pte);
> -
> -       if (!folio_test_large(folio))
> +       if (likely(!folio_test_large(folio)))
>                 return 1;
>
> -       count = pfn + nr - pte_pfn(ptent);
> -       count = min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT);
> -
> -       for (i = 0; i < count; i++, pte++) {
> -               pte_t entry = ptep_get(pte);
> -
> -               if (!pte_present(entry))
> -                       break;
> -               if (pte_pfn(entry) - pfn >= nr)
> -                       break;
> -       }
> +       const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY;
> +       int max_nr = (end - addr) / PAGE_SIZE;
> +       pte_t ptent = ptep_get(pte);
>
> -       return i;
> +       return folio_pte_batch(folio, addr, pte, ptent, max_nr, fpb_flags, NULL,
> +                              NULL, NULL);
>  }

what about a minimum change as below?
index 30b51cdea89d..e8b98f84fbd2 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -307,26 +307,15 @@ void munlock_folio(struct folio *folio)
 static inline unsigned int folio_mlock_step(struct folio *folio,
                pte_t *pte, unsigned long addr, unsigned long end)
 {
-       unsigned int count, i, nr = folio_nr_pages(folio);
-       unsigned long pfn = folio_pfn(folio);
+       unsigned int count = (end - addr) >> PAGE_SHIFT;
        pte_t ptent = ptep_get(pte);
+       const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY;

        if (!folio_test_large(folio))
                return 1;

-       count = pfn + nr - pte_pfn(ptent);
-       count = min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT);
-
-       for (i = 0; i < count; i++, pte++) {
-               pte_t entry = ptep_get(pte);
-
-               if (!pte_present(entry))
-                       break;
-               if (pte_pfn(entry) - pfn >= nr)
-                       break;
-       }
-
-       return i;
+       return folio_pte_batch(folio, addr, pte, ptent, count, fpb_flags, NULL,
+                              NULL, NULL);
 }



>
>  static inline bool allow_mlock_munlock(struct folio *folio,
> --
> 2.33.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ