Skip to content

Commit f5e31a1

Browse files
youngjuniakpm00
authored andcommitted
mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type()
After commit 4f78252, 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. As a representative userspace-visible runtime example of the impact, /proc/meminfo reports increasingly inaccurate SwapFree values. The discrepancy grows with each swap allocation, and during hibernation when large amounts of memory are written to swap, the reported value can deviate significantly from actual available swap space, misleading users and monitoring tools. Remove the duplicate decrement. Link: https://lkml.kernel.org/r/20251102082456.79807-1-youngjun.park@lge.com Fixes: 4f78252 ("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> Acked-by: Chris Li <chrisl@kernel.org> Reviewed-by: Barry Song <baohua@kernel.org> Reviewed-by: Kairui Song <kasong@tencent.com> Acked-by: Nhat Pham <nphamcs@gmail.com> Cc: Baoquan He <bhe@redhat.com> Cc: Kemeng Shi <shikemeng@huaweicloud.com> Cc: <stable@vger.kernel.org> [6.17+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 1c2a936 commit f5e31a1

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

mm/swapfile.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,10 +2005,8 @@ swp_entry_t get_swap_page_of_type(int type)
20052005
local_lock(&percpu_swap_cluster.lock);
20062006
offset = cluster_alloc_swap_entry(si, 0, 1);
20072007
local_unlock(&percpu_swap_cluster.lock);
2008-
if (offset) {
2008+
if (offset)
20092009
entry = swp_entry(si->type, offset);
2010-
atomic_long_dec(&nr_swap_pages);
2011-
}
20122010
}
20132011
put_swap_device(si);
20142012
}

0 commit comments

Comments
 (0)