mm-swap-simplify-folio-swap-allocation.patch removed from -mm tree
The quilt patch titled
Subject: mm, swap: simplify folio swap allocation
has been removed from the -mm tree. Its filename was
mm-swap-simplify-folio-swap-allocation.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Kairui Song <[email protected]>
Subject: mm, swap: simplify folio swap allocation
Date: Fri, 14 Mar 2025 00:59:35 +0800
With slot cache gone, clean up the allocation helpers even more. folio_alloc_swap will be the only entry for allocation and adding the folio to swap cache (except suspend), making it opposite of folio_free_swap.
---
include/linux/swap.h | 8 +- mm/shmem.c | 21 ++----- mm/swap.h | 6 -- mm/swap_state.c | 57 --------------------- mm/swapfile.c | 111 ++++++++++++++++++++++++++--------------- mm/vmscan.c | 16 +++++ 6 files changed, 95 insertions(+), 124 deletions(-)
include/linux/swap.h renamed from include/linux/swap.h~mm-swap-simplify-folio-swap-allocation +3 -5
@@ -478,7 +478,7 @@ static inline long get_nr_swap_pages(voi }extern void si_swapinfo (struct sysinfo *); -swp_entry_t folio_alloc_swap (struct folio *folio); +int folio_alloc_swap (struct folio *folio,gfp_t gfp_mask);bool folio_free_swap (struct folio *folio);void put_swap_folio (struct folio *folio,swp_entry_t entry);extern swp_entry_t get_swap_page_of_type (int );
@@ -586,11 +586,9 @@ static inline int swp_swapcount(swp_entrreturn 0 ; } -static inline swp_entry_t folio_alloc_swap (struct folio *folio) +static inline int folio_alloc_swap (struct folio *folio,gfp_t gfp_mask) { -swp_entry_t entry; - entry.val =0 ; -return entry; +return -EINVAL ; }static inline bool folio_free_swap (struct folio *folio)
mm/shmem.c renamed from mm/shmem.c~mm-swap-simplify-folio-swap-allocation +6 -15
@@ -1533,7 +1533,6 @@ static int shmem_writepage(struct page *struct inode *inode = mapping->host;struct shmem_inode_info *info =SHMEM_I (inode);struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb); -swp_entry_t swap;pgoff_t index;int nr_pages;bool split = false;
@@ -1615,14 +1614,6 @@ try_split:folio_mark_uptodate (folio); } - swap =folio_alloc_swap (folio); -if (!swap.val) { -if (nr_pages >1 ) - goto try_split; - - goto redirty; - } -/* * Add inode to shmem_unuse()'s list of swapped-out inodes, * if it's not already there. Do it now before the folio is
@@ -1635,20 +1626,20 @@ try_split:if (list_empty (&info->swaplist))list_add (&info->swaplist, &shmem_swaplist); -if (add_to_swap_cache (folio, swap, - __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN, -NULL ) ==0 ) { +if (!folio_alloc_swap (folio, __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN)) {shmem_recalc_inode (inode,0 , nr_pages); -swap_shmem_alloc (swap, nr_pages); -shmem_delete_from_page_cache (folio,swp_to_radix_entry (swap)); +swap_shmem_alloc (folio->swap, nr_pages); +shmem_delete_from_page_cache (folio,swp_to_radix_entry (folio->swap));mutex_unlock (&shmem_swaplist_mutex);BUG_ON (folio_mapped (folio));return swap_writepage (&folio->page, wbc); } +list_del_init (&info->swaplist);mutex_unlock (&shmem_swaplist_mutex); -put_swap_folio (folio, swap); +if (nr_pages >1 ) + goto try_split; redirty:folio_mark_dirty (folio);if (wbc->for_reclaim)
mm/swapfile.c renamed from mm/swapfile.c~mm-swap-simplify-folio-swap-allocation +72 -39
151 lines not on this page · raw message
mm/swap.h renamed from mm/swap.h~mm-swap-simplify-folio-swap-allocation +0 -6
@@ -50,7 +50,6 @@ static inline pgoff_t swap_cache_index(s }void show_swap_cache_info (void ); -bool add_to_swap (struct folio *folio);void *get_shadow_from_swap_cache (swp_entry_t entry);int add_to_swap_cache (struct folio *folio,swp_entry_t entry,gfp_t gfp,void **shadowp);
@@ -163,11 +162,6 @@ struct folio *filemap_get_incore_folio(sreturn filemap_get_folio (mapping, index); } -static inline bool add_to_swap (struct folio *folio) -{ -return false; -} -static inline void *get_shadow_from_swap_cache (swp_entry_t entry) {return NULL ;
mm/swap_state.c renamed from mm/swap_state.c~mm-swap-simplify-folio-swap-allocation +0 -57
63 lines not on this page · raw message
mm/vmscan.c renamed from mm/vmscan.c~mm-swap-simplify-folio-swap-allocation +14 -2
@@ -1289,7 +1289,7 @@ retry: split_folio_to_list(folio, folio_list)) goto activate_locked; } -if (!add_to_swap (folio)) { +if (folio_alloc_swap (folio, __GFP_HIGH | __GFP_NOWARN)) {int __maybe_unused order =folio_order (folio);if (!folio_test_large (folio))
@@ -1305,9 +1305,21 @@ retry: }#endif count_mthp_stat (order,MTHP_STAT_SWPOUT_FALLBACK ); -if (!add_to_swap (folio)) +if (folio_alloc_swap (folio, __GFP_HIGH | __GFP_NOWARN)) goto activate_locked_split; } +/* +* Normally the folio will be dirtied in unmap because its +* pte should be dirty. A special case is MADV_FREE page. The +* page's pte could have dirty bit cleared but the folio's +* SwapBacked flag is still set because clearing the dirty bit +* and SwapBacked flag has no lock protected. For such folio, +* unmap will not set dirty bit for it, so folio reclaim will +* not write the folio out. This can cause data corruption when +* the folio is swapped in later. Always setting the dirty flag +* for the folio solves the problem. +*/ +folio_mark_dirty (folio); } }
_
Patches currently in -mm which might be from [email protected] are