Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm, swap: no need to clear the shadow explicitly

Since we no longer bypass the swap cache, every swap-in will clear the
swap shadow by inserting the folio into the swap table. The only place we
may seem to need to free the swap shadow is when the swap slots are freed
directly without a folio (swap_put_entries_direct). But with the swap
table, that is not needed either. Freeing a slot in the swap table will
set the table entry to NULL, which erases the shadow just fine.

So just delete all explicit shadow clearing, it's no longer needed. Also,
rearrange the freeing.

Link: https://lkml.kernel.org/r/20260218-swap-table-p3-v3-12-f4e34be021a7@tencent.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Acked-by: Chris Li <chrisl@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kairui Song <ryncsn@gmail.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: kernel test robot <lkp@intel.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kairui Song and committed by
Andrew Morton
1df1a1b9 a0f79916

-24
-1
mm/swap.h
··· 290 290 struct folio *folio, swp_entry_t entry, void *shadow); 291 291 void __swap_cache_replace_folio(struct swap_cluster_info *ci, 292 292 struct folio *old, struct folio *new); 293 - void __swap_cache_clear_shadow(swp_entry_t entry, int nr_ents); 294 293 295 294 void show_swap_cache_info(void); 296 295 void swapcache_clear(struct swap_info_struct *si, swp_entry_t entry, int nr);
-21
mm/swap_state.c
··· 350 350 } 351 351 } 352 352 353 - /** 354 - * __swap_cache_clear_shadow - Clears a set of shadows in the swap cache. 355 - * @entry: The starting index entry. 356 - * @nr_ents: How many slots need to be cleared. 357 - * 358 - * Context: Caller must ensure the range is valid, all in one single cluster, 359 - * not occupied by any folio, and lock the cluster. 360 - */ 361 - void __swap_cache_clear_shadow(swp_entry_t entry, int nr_ents) 362 - { 363 - struct swap_cluster_info *ci = __swap_entry_to_cluster(entry); 364 - unsigned int ci_off = swp_cluster_offset(entry), ci_end; 365 - unsigned long old; 366 - 367 - ci_end = ci_off + nr_ents; 368 - do { 369 - old = __swap_table_xchg(ci, ci_off, null_to_swp_tb()); 370 - WARN_ON_ONCE(swp_tb_is_folio(old) || swp_tb_get_count(old)); 371 - } while (++ci_off < ci_end); 372 - } 373 - 374 353 /* 375 354 * If we are the only user, then try to free up the swap cache. 376 355 *
-2
mm/swapfile.c
··· 1287 1287 static void swap_range_free(struct swap_info_struct *si, unsigned long offset, 1288 1288 unsigned int nr_entries) 1289 1289 { 1290 - unsigned long begin = offset; 1291 1290 unsigned long end = offset + nr_entries - 1; 1292 1291 void (*swap_slot_free_notify)(struct block_device *, unsigned long); 1293 1292 unsigned int i; ··· 1311 1312 swap_slot_free_notify(si->bdev, offset); 1312 1313 offset++; 1313 1314 } 1314 - __swap_cache_clear_shadow(swp_entry(si->type, begin), nr_entries); 1315 1315 1316 1316 /* 1317 1317 * Make sure that try_to_unuse() observes si->inuse_pages reaching 0