Skip to contentSkip to conversation

mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type()

PATCH Superseded Youngjun Park 3 participants 5 messages Nov 1, 2025 – Nov 2, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Youngjun Park

author reviewer
#0 lore raw

PATCH 1/1 mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type()

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()")
mm/swapfile.c +1 -3
index 543f303f101d..66a502cd747b 100644
@@ -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);
 	}
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · 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.

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 [email protected] # 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

Quoted 23 lines
Fixes 4f78252da887 ("mm: swap: move nr_swap_pages counter decrement from folio_alloc_swap() to swap_range_alloc()")
mm/swapfile.c +1 -4
index 543f303f101d..66a502cd747b 100644
@@ -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

author reviewer
#2 lore raw
Quoted 9 lines · Chris Li
Quoted 7 lines · 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.

Quoted 8 lines

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 [email protected] # v6.17-rc1

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

Best Regards,
Youngjun Park

reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Youngjun Park
Quoted 10 lines · 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()")

As Chris mentioned, we need to add Cc: [email protected].

Otherwise,

author reviewer
#4 lore raw
Quoted 7 lines · Barry Song
Quoted 6 lines · 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.

Quoted 6 lines
Quoted 4 lines

Remove the duplicate decrement.

Fixes 4f78252da887 ("mm: swap: move nr_swap_pages counter decrement from folio_alloc_swap() to swap_range_alloc()")

As Chris mentioned, we need to add Cc: [email protected].

Okay I add on my v2 patch as Chris mentioned.

Quoted 3 lines

Otherwise,

Thank you for the review.

Best regards,
Youngjun Park