linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type()
@ 2025-11-01 13:41 Youngjun Park
  2025-11-01 19:12 ` Chris Li
  2025-11-01 20:55 ` Barry Song
  0 siblings, 2 replies; 5+ messages in thread
From: Youngjun Park @ 2025-11-01 13:41 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, Kemeng Shi, Kairui Song, Nhat Pham, Baoquan He,
	Barry Song, Chris Li, youngjun.park

After commit 4f78252da887, nr_swap_pages is decremented in
swap_range_alloc(). Since cluster_alloc_swap_entry() calls
swap_range_alloc() internally, the decrement in get_swap_page_of_type()
causes double-decrementing.

Remove the duplicate decrement.

Fixes: 4f78252da887 ("mm: swap: move nr_swap_pages counter decrement from folio_alloc_swap() to swap_range_alloc()")
Signed-off-by: Youngjun Park <youngjun.park@lge.com>

diff --git a/mm/swapfile.c b/mm/swapfile.c
index 543f303f101d..66a502cd747b 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2020,10 +2020,8 @@ swp_entry_t get_swap_page_of_type(int type)
 			local_lock(&percpu_swap_cluster.lock);
 			offset = cluster_alloc_swap_entry(si, 0, 1);
 			local_unlock(&percpu_swap_cluster.lock);
-			if (offset) {
+			if (offset)
 				entry = swp_entry(si->type, offset);
-				atomic_long_dec(&nr_swap_pages);
-			}
 		}
 		put_swap_device(si);
 	}
-- 
2.34.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type()
  2025-11-01 13:41 [PATCH] mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type() Youngjun Park
@ 2025-11-01 19:12 ` Chris Li
  2025-11-02  8:26   ` YoungJun Park
  2025-11-01 20:55 ` Barry Song
  1 sibling, 1 reply; 5+ messages in thread
From: Chris Li @ 2025-11-01 19:12 UTC (permalink / raw)
  To: Youngjun Park, Andrew Morton
  Cc: linux-mm, Kemeng Shi, Kairui Song, Nhat Pham, Baoquan He, Barry Song

On Sat, Nov 1, 2025 at 6:42 AM Youngjun Park <youngjun.park@lge.com> wrote:
>
> After commit 4f78252da887, nr_swap_pages is decremented in
> swap_range_alloc(). Since cluster_alloc_swap_entry() calls
> swap_range_alloc() internally, the decrement in get_swap_page_of_type()
> causes double-decrementing.
>
> Remove the duplicate decrement.

Acked-by: Chris Li <chrisl@kernel.org>

Thanks for the good catch. Indeed there is duplication, but only
affects the hibernation usage of swap as far as I can tell.
This bug is in v6.17-rc1 upwards including v6.17 as well. You might
want to add the stable tag:

Cc: stable@vger.kernel.org # v6.17-rc1

Hi Andrew,

Please apply. Can you add the above line or Youngjun needs to send out
a new version to include the stable line?

Chris

>
> Fixes: 4f78252da887 ("mm: swap: move nr_swap_pages counter decrement from folio_alloc_swap() to swap_range_alloc()")
> Signed-off-by: Youngjun Park <youngjun.park@lge.com>
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 543f303f101d..66a502cd747b 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2020,10 +2020,8 @@ swp_entry_t get_swap_page_of_type(int type)
>                         local_lock(&percpu_swap_cluster.lock);
>                         offset = cluster_alloc_swap_entry(si, 0, 1);
>                         local_unlock(&percpu_swap_cluster.lock);
> -                       if (offset) {
> +                       if (offset)
>                                 entry = swp_entry(si->type, offset);
> -                               atomic_long_dec(&nr_swap_pages);
> -                       }
>                 }
>                 put_swap_device(si);
>         }
> --
> 2.34.1
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type()
  2025-11-01 13:41 [PATCH] mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type() Youngjun Park
  2025-11-01 19:12 ` Chris Li
@ 2025-11-01 20:55 ` Barry Song
  2025-11-02  8:28   ` YoungJun Park
  1 sibling, 1 reply; 5+ messages in thread
From: Barry Song @ 2025-11-01 20:55 UTC (permalink / raw)
  To: Youngjun Park
  Cc: Andrew Morton, linux-mm, Kemeng Shi, Kairui Song, Nhat Pham,
	Baoquan He, Chris Li

On Sat, Nov 1, 2025 at 9:42 PM Youngjun Park <youngjun.park@lge.com> wrote:
>
> After commit 4f78252da887, nr_swap_pages is decremented in
> swap_range_alloc(). Since cluster_alloc_swap_entry() calls
> swap_range_alloc() internally, the decrement in get_swap_page_of_type()
> causes double-decrementing.
>
> Remove the duplicate decrement.
>
> Fixes: 4f78252da887 ("mm: swap: move nr_swap_pages counter decrement from folio_alloc_swap() to swap_range_alloc()")
> Signed-off-by: Youngjun Park <youngjun.park@lge.com>

As Chris mentioned, we need to add Cc: stable@vger.kernel.org.

Otherwise,
Reviewed-by: Barry Song <baohua@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type()
  2025-11-01 19:12 ` Chris Li
@ 2025-11-02  8:26   ` YoungJun Park
  0 siblings, 0 replies; 5+ messages in thread
From: YoungJun Park @ 2025-11-02  8:26 UTC (permalink / raw)
  To: Chris Li
  Cc: Andrew Morton, linux-mm, Kemeng Shi, Kairui Song, Nhat Pham,
	Baoquan He, Barry Song

On Sat, Nov 01, 2025 at 12:12:44PM -0700, Chris Li wrote:
> On Sat, Nov 1, 2025 at 6:42 AM Youngjun Park <youngjun.park@lge.com> wrote:
> >
> > After commit 4f78252da887, nr_swap_pages is decremented in
> > swap_range_alloc(). Since cluster_alloc_swap_entry() calls
> > swap_range_alloc() internally, the decrement in get_swap_page_of_type()
> > causes double-decrementing.
> >
> > Remove the duplicate decrement.
> 
> Acked-by: Chris Li <chrisl@kernel.org>
> 
> Thanks for the good catch. Indeed there is duplication, but only
> affects the hibernation usage of swap as far as I can tell.
> This bug is in v6.17-rc1 upwards including v6.17 as well. You might
> want to add the stable tag:
> 
> Cc: stable@vger.kernel.org # v6.17-rc1

I add the Cc tag on v2 patch
Thank you for review

Best Regards,
Youngjun Park


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type()
  2025-11-01 20:55 ` Barry Song
@ 2025-11-02  8:28   ` YoungJun Park
  0 siblings, 0 replies; 5+ messages in thread
From: YoungJun Park @ 2025-11-02  8:28 UTC (permalink / raw)
  To: Barry Song
  Cc: Andrew Morton, linux-mm, Kemeng Shi, Kairui Song, Nhat Pham,
	Baoquan He, Chris Li

On Sun, Nov 02, 2025 at 04:55:46AM +0800, Barry Song wrote:
> On Sat, Nov 1, 2025 at 9:42 PM Youngjun Park <youngjun.park@lge.com> wrote:
> >
> > After commit 4f78252da887, nr_swap_pages is decremented in
> > swap_range_alloc(). Since cluster_alloc_swap_entry() calls
> > swap_range_alloc() internally, the decrement in get_swap_page_of_type()
> > causes double-decrementing.
> >
> > Remove the duplicate decrement.
> >
> > Fixes: 4f78252da887 ("mm: swap: move nr_swap_pages counter decrement from folio_alloc_swap() to swap_range_alloc()")
> > Signed-off-by: Youngjun Park <youngjun.park@lge.com>
> 
> As Chris mentioned, we need to add Cc: stable@vger.kernel.org.

Okay I add on my v2 patch as Chris mentioned.

> Otherwise,
> Reviewed-by: Barry Song <baohua@kernel.org>
>
Thank you for the review.

Best regards,
Youngjun Park 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-11-02  8:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-01 13:41 [PATCH] mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type() Youngjun Park
2025-11-01 19:12 ` Chris Li
2025-11-02  8:26   ` YoungJun Park
2025-11-01 20:55 ` Barry Song
2025-11-02  8:28   ` YoungJun Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox