]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm, swap: remove no longer needed _swap_info_get
authorKairui Song <kasong@tencent.com>
Fri, 19 Dec 2025 19:43:48 +0000 (03:43 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 31 Jan 2026 22:22:58 +0000 (14:22 -0800)
There are now only two users of _swap_info_get after consolidating these
callers, folio_free_swap and swp_swapcount.

folio_free_swap already holds the folio lock, and the folio must be in the
swap cache, _swap_info_get is redundant.

For swp_swapcount, it should use get_swap_device instead.  get_swap_device
increases the device ref count, which is actually a bit safer.  The only
current use is smap walking, and the performance change here is tiny.

And after these changes, _swap_info_get is no longer used, so we can
safely remove it.

Link: https://lkml.kernel.org/r/20251220-swap-table-p2-v5-19-8862a265a033@tencent.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Reviewed-by: Baoquan He <bhe@redhat.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Chris Li <chrisl@kernel.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Cc: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Deepanshu Kartikey <kartikey406@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kairui Song <ryncsn@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/swapfile.c

index 5721018cb28a379264caa9d81a2ca57b3e67b580..c6863ff7152c9a61f2e2cbe2f285f948d815618b 100644 (file)
@@ -83,9 +83,7 @@ bool swap_migration_ad_supported;
 #endif /* CONFIG_MIGRATION */
 
 static const char Bad_file[] = "Bad swap file entry ";
-static const char Unused_file[] = "Unused swap file entry ";
 static const char Bad_offset[] = "Bad swap offset entry ";
-static const char Unused_offset[] = "Unused swap offset entry ";
 
 /*
  * all active swap_info_structs
@@ -1600,41 +1598,6 @@ void folio_put_swap(struct folio *folio, struct page *subpage)
        swap_put_entries_cluster(si, swp_offset(entry), nr_pages, false);
 }
 
-static struct swap_info_struct *_swap_info_get(swp_entry_t entry)
-{
-       struct swap_info_struct *si;
-       unsigned long offset;
-
-       if (!entry.val)
-               goto out;
-       si = swap_entry_to_info(entry);
-       if (!si)
-               goto bad_nofile;
-       if (data_race(!(si->flags & SWP_USED)))
-               goto bad_device;
-       offset = swp_offset(entry);
-       if (offset >= si->max)
-               goto bad_offset;
-       if (data_race(!si->swap_map[swp_offset(entry)]) &&
-           !swap_cache_has_folio(entry))
-               goto bad_free;
-       return si;
-
-bad_free:
-       pr_err("%s: %s%08lx\n", __func__, Unused_offset, entry.val);
-       goto out;
-bad_offset:
-       pr_err("%s: %s%08lx\n", __func__, Bad_offset, entry.val);
-       goto out;
-bad_device:
-       pr_err("%s: %s%08lx\n", __func__, Unused_file, entry.val);
-       goto out;
-bad_nofile:
-       pr_err("%s: %s%08lx\n", __func__, Bad_file, entry.val);
-out:
-       return NULL;
-}
-
 static void swap_put_entry_locked(struct swap_info_struct *si,
                                  struct swap_cluster_info *ci,
                                  unsigned long offset)
@@ -1794,7 +1757,7 @@ int swp_swapcount(swp_entry_t entry)
        pgoff_t offset;
        unsigned char *map;
 
-       si = _swap_info_get(entry);
+       si = get_swap_device(entry);
        if (!si)
                return 0;
 
@@ -1824,6 +1787,7 @@ int swp_swapcount(swp_entry_t entry)
        } while (tmp_count & COUNT_CONTINUED);
 out:
        swap_cluster_unlock(ci);
+       put_swap_device(si);
        return count;
 }
 
@@ -1858,11 +1822,12 @@ unlock_out:
 static bool folio_swapped(struct folio *folio)
 {
        swp_entry_t entry = folio->swap;
-       struct swap_info_struct *si = _swap_info_get(entry);
+       struct swap_info_struct *si;
 
-       if (!si)
-               return false;
+       VM_WARN_ON_ONCE_FOLIO(!folio_test_locked(folio), folio);
+       VM_WARN_ON_ONCE_FOLIO(!folio_test_swapcache(folio), folio);
 
+       si = __swap_entry_to_info(entry);
        if (!IS_ENABLED(CONFIG_THP_SWAP) || likely(!folio_test_large(folio)))
                return swap_entry_swapped(si, entry);