diff options
| author | Kemeng Shi <shikemeng@huaweicloud.com> | 2025-03-26 00:25:27 +0800 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2025-05-11 17:48:14 -0700 |
| commit | d4f8000bd6b0cc33c9dddd369e72a13c4c080cb1 (patch) | |
| tree | 48710ba89a80feb47edd63809593a21161fe01a8 /mm/swapfile.c | |
| parent | 4d71d9062dd7b2ace56f2351b9f3f06e6c0acf81 (diff) | |
| download | linux-d4f8000bd6b0cc33c9dddd369e72a13c4c080cb1.tar.gz linux-d4f8000bd6b0cc33c9dddd369e72a13c4c080cb1.tar.bz2 linux-d4f8000bd6b0cc33c9dddd369e72a13c4c080cb1.zip | |
mm: swap: factor out helper to drop cache of entries within a single cluster
Factor out helper swap_entries_put_cache() from put_swap_folio() to serve
as a general-purpose routine for dropping cache flag of entries within a
single cluster.
Link: https://lkml.kernel.org/r/20250325162528.68385-8-shikemeng@huaweicloud.com
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Tim Chen <tim.c.chen@linux.intel.com>
Reviewed-by: Baoquan He <bhe@redhat.com>
Cc: Kairui Song <kasong@tencent.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/swapfile.c')
| -rw-r--r-- | mm/swapfile.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c index 4f4fc74239d6..953dcd99006e 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1463,6 +1463,22 @@ put_out: return NULL; } +static void swap_entries_put_cache(struct swap_info_struct *si, + swp_entry_t entry, int nr) +{ + unsigned long offset = swp_offset(entry); + struct swap_cluster_info *ci; + + ci = lock_cluster(si, offset); + if (swap_only_has_cache(si, offset, nr)) + swap_entries_free(si, ci, entry, nr); + else { + for (int i = 0; i < nr; i++, entry.val++) + swap_entry_put_locked(si, ci, entry, SWAP_HAS_CACHE); + } + unlock_cluster(ci); +} + static bool swap_entries_put_map(struct swap_info_struct *si, swp_entry_t entry, int nr) { @@ -1607,8 +1623,6 @@ void swap_free_nr(swp_entry_t entry, int nr_pages) */ void put_swap_folio(struct folio *folio, swp_entry_t entry) { - unsigned long offset = swp_offset(entry); - struct swap_cluster_info *ci; struct swap_info_struct *si; int size = 1 << swap_entry_order(folio_order(folio)); @@ -1616,14 +1630,7 @@ void put_swap_folio(struct folio *folio, swp_entry_t entry) if (!si) return; - ci = lock_cluster(si, offset); - if (swap_only_has_cache(si, offset, size)) - swap_entries_free(si, ci, entry, size); - else { - for (int i = 0; i < size; i++, entry.val++) - swap_entry_put_locked(si, ci, entry, SWAP_HAS_CACHE); - } - unlock_cluster(ci); + swap_entries_put_cache(si, entry, size); } int __swap_count(swp_entry_t entry) |
