Skip to contentSkip to conversation

swap: Check mapping_empty() for swap cache before being freed

PATCH Applied Huang Ying 1 participant 1 message Jun 8, 2021

Subsystems (2)
lore
Share & tools
lore

Huang Ying

author
#0 lore raw

PATCH 1/1 swap: Check mapping_empty() for swap cache before being freed

To check whether all pages and shadow entries in swap cache has been removed before swap cache is freed.

Cc Miaohe Lin <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Joonsoo Kim <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Vlastimil Babka <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Dan Williams <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ilya Dryomov <[email protected]>

---

BTW: The patch reverts the following patch in -mm tree in effect.

mm/swap: remove unused global variable nr_swapper_spaces

---
 mm/swap_state.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
mm/swap_state.c +9 -1
index 95e391f46468..c56aa9ac050d 100644
@@ -37,6 +37,7 @@ static const struct address_space_operations swap_aops = {
 };
 
 struct address_space *swapper_spaces[MAX_SWAPFILES] __read_mostly;
+static unsigned int nr_swapper_spaces[MAX_SWAPFILES] __read_mostly;
 static bool enable_vma_readahead __read_mostly = true;
 
 #define SWAP_RA_WIN_SHIFT	(PAGE_SHIFT / 2)
@@ -684,6 +685,7 @@ int init_swap_address_space(unsigned int type, unsigned long nr_pages)
 		/* swap cache doesn't use writeback related tags */
 		mapping_set_no_writeback_tags(space);
 	}
+	nr_swapper_spaces[type] = nr;
 	swapper_spaces[type] = spaces;
 
 	return 0;
@@ -691,7 +693,13 @@ int init_swap_address_space(unsigned int type, unsigned long nr_pages)
 
 void exit_swap_address_space(unsigned int type)
 {
-	kvfree(swapper_spaces[type]);
+	int i;
+	struct address_space *spaces = swapper_spaces[type];
+
+	for (i = 0; i < nr_swapper_spaces[type]; i++)
+		VM_WARN_ON_ONCE(!mapping_empty(&spaces[i]));
+	kvfree(spaces);
+	nr_swapper_spaces[type] = 0;
 	swapper_spaces[type] = NULL;
 }
 
Signature · 1 line
2.30.2