summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoungjun Park <youngjun.park@lge.com>2025-12-01 18:53:26 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-12-07 06:27:40 +0900
commit5ddd41b6877ff3c19a82ebdb1281a01b767c2f45 (patch)
treea785f401088c0bccdbf5db6a9e38f21683a280e3
parentb4368b7f97014e1015445d61abd0b27c4c6e8424 (diff)
downloadlinux-5ddd41b6877ff3c19a82ebdb1281a01b767c2f45.tar.gz
linux-5ddd41b6877ff3c19a82ebdb1281a01b767c2f45.tar.bz2
linux-5ddd41b6877ff3c19a82ebdb1281a01b767c2f45.zip
mm: swap: remove duplicate nr_swap_pages decrement in get_swap_page_of_type()
[ Upstream commit f5e31a196edcd1f1bb44f26b6f9299b9a5b9b3c4 ] 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. 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: 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> 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> [ adjusted context ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--mm/swapfile.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index ad438a4d0e68..73065d75d0e1 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1866,10 +1866,8 @@ swp_entry_t get_swap_page_of_type(int type)
if (get_swap_device_info(si)) {
if (si->flags & SWP_WRITEOK) {
offset = cluster_alloc_swap_entry(si, 0, 1);
- if (offset) {
+ if (offset)
entry = swp_entry(si->type, offset);
- atomic_long_dec(&nr_swap_pages);
- }
}
put_swap_device(si);
}