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: <CAGsJ_4xbnAS=rbQ=adq7X0ig8Vw9fGzW5d06e6CnP3oBwpUM3w@mail.gmail.com>
Date: Mon, 8 Jul 2024 18:22:06 +1200
From: Barry Song <21cnbao@...il.com>
To: akpm@...ux-foundation.org, linux-mm@...ck.org
Cc: linux-kernel@...r.kernel.org, Barry Song <v-songbaohua@...o.com>, 
	"Huang, Ying" <ying.huang@...el.com>, Chris Li <chrisl@...nel.org>, 
	Ryan Roberts <ryan.roberts@....com>, Kairui Song <kasong@...cent.com>, 
	David Hildenbrand <david@...hat.com>, Chuanhua Han <hanchuanhua@...o.com>
Subject: Re: [PATCH] mm: Extend 'usage' parameter so that cluster_swap_free_nr()
 can be reused

On Mon, Jul 8, 2024 at 6:15 PM Barry Song <21cnbao@...il.com> wrote:
>
> From: Barry Song <v-songbaohua@...o.com>
>
> Extend a usage parameter so that cluster_swap_free_nr() can be reused by
> both swapcache_clear() and swap_free().
> __swap_entry_free() is quite similar but more tricky as it requires the
> return value of __swap_entry_free_locked() which cluster_swap_free_nr()
> doesn't support.
>
> Cc: "Huang, Ying" <ying.huang@...el.com>
> Cc: Chris Li <chrisl@...nel.org>
> Cc: Ryan Roberts <ryan.roberts@....com>
> Cc: Kairui Song <kasong@...cent.com>
> Cc: David Hildenbrand <david@...hat.com>
> Cc: Chuanhua Han <hanchuanhua@...o.com>
> Signed-off-by: Barry Song <v-songbaohua@...o.com>
> ---
>  mm/swapfile.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index f7224bc1320c..70c4a9132672 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -1352,7 +1352,8 @@ static void swap_entry_free(struct swap_info_struct *p, swp_entry_t entry)
>  }
>
>  static void cluster_swap_free_nr(struct swap_info_struct *sis,
> -               unsigned long offset, int nr_pages)
> +               unsigned long offset, int nr_pages,
> +               unsigned char usage)
>  {
>         struct swap_cluster_info *ci;
>         DECLARE_BITMAP(to_free, BITS_PER_LONG) = { 0 };
> @@ -1363,7 +1364,7 @@ static void cluster_swap_free_nr(struct swap_info_struct *sis,
>                 nr = min(BITS_PER_LONG, nr_pages);
>                 for (i = 0; i < nr; i++) {
>                         if (!__swap_entry_free_locked(sis, offset + i, 1))
> -                               bitmap_set(to_free, i, 1);
> +                               bitmap_set(to_free, i, usage);

I'm terribly sorry for the mis-operation(sent the wrong patch),
I actually mean:

if (!__swap_entry_free_locked(sis, offset + i, usage))
           bitmap_set(to_free, i, 1);

>                 }
>                 if (!bitmap_empty(to_free, BITS_PER_LONG)) {
>                         unlock_cluster_or_swap_info(sis, ci);
> @@ -1396,7 +1397,7 @@ void swap_free_nr(swp_entry_t entry, int nr_pages)
>
>         while (nr_pages) {
>                 nr = min_t(int, nr_pages, SWAPFILE_CLUSTER - offset % SWAPFILE_CLUSTER);
> -               cluster_swap_free_nr(sis, offset, nr);
> +               cluster_swap_free_nr(sis, offset, nr, 1);
>                 offset += nr;
>                 nr_pages -= nr;
>         }
> @@ -3492,15 +3493,9 @@ int swapcache_prepare(swp_entry_t entry)
>
>  void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry)
>  {
> -       struct swap_cluster_info *ci;
>         unsigned long offset = swp_offset(entry);
> -       unsigned char usage;
>
> -       ci = lock_cluster_or_swap_info(si, offset);
> -       usage = __swap_entry_free_locked(si, offset, SWAP_HAS_CACHE);
> -       unlock_cluster_or_swap_info(si, ci);
> -       if (!usage)
> -               free_swap_slot(entry);
> +       cluster_swap_free_nr(si, offset, 1, SWAP_HAS_CACHE);
>  }
>
>  struct swap_info_struct *swp_swap_info(swp_entry_t entry)
> --
> 2.39.2
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ