Skip to contentSkip to conversation

mm/swap: skip readahead only when swap slot cache is enabled

PATCH New [email protected] 1 participant 1 message Feb 22, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 120/142 mm/swap: skip readahead only when swap slot cache is enabled

From: Huang Ying <[email protected]>
Subject: mm/swap: skip readahead only when swap slot cache is enabled

Because during swap off, a swap entry may have swap_map[] == SWAP_HAS_CACHE (for example, just allocated). If we return NULL in __read_swap_cache_async(), the swap off will abort. So when swap slot cache is disabled, (for swap off), we will wait for page to be put into swap cache in such race condition. This should not be a problem for swap slot cache, because swap slot cache should be drained after clearing swap_slot_cache_enabled.

[[email protected]: fix memory leak in __read_swap_cache_async()]
Cc Aaron Lu <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Huang Ying <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Jonathan Corbet <[email protected]> escreveu:
Cc Kirill A. Shutemov <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Vladimir Davydov <[email protected]>

---

 include/linux/swap_slots.h |    2 ++
 mm/swap_slots.c            |    2 +-
 mm/swap_state.c            |   13 ++++++++++---
 3 files changed, 13 insertions(+), 4 deletions(-)
include/linux/swap_slots.h renamed from include/linux/swap_slots.h~mm-swap-skip-readahead-only-when-swap-slot-cache-is-enabled +2 -0
diff -puN include/linux/swap_slots.h~mm-swap-skip-readahead-only-when-swap-slot-cache-is-enabled include/linux/swap_slots.h
@@ -25,4 +25,6 @@ void reenable_swap_slots_cache_unlock(vo
 int enable_swap_slots_cache(void);
 int free_swap_slot(swp_entry_t entry);
 
+extern bool swap_slot_cache_enabled;
+
 #endif /* _LINUX_SWAP_SLOTS_H */
mm/swap_slots.c renamed from mm/swap_slots.c~mm-swap-skip-readahead-only-when-swap-slot-cache-is-enabled +1 -1
diff -puN mm/swap_slots.c~mm-swap-skip-readahead-only-when-swap-slot-cache-is-enabled mm/swap_slots.c
@@ -36,7 +36,7 @@
 
 static DEFINE_PER_CPU(struct swap_slots_cache, swp_slots);
 static bool	swap_slot_cache_active;
-static bool	swap_slot_cache_enabled;
+bool	swap_slot_cache_enabled;
 static bool	swap_slot_cache_initialized;
 DEFINE_MUTEX(swap_slots_cache_mutex);
 /* Serialize swap slots cache enable/disable operations */
mm/swap_state.c renamed from mm/swap_state.c~mm-swap-skip-readahead-only-when-swap-slot-cache-is-enabled +10 -3
diff -puN mm/swap_state.c~mm-swap-skip-readahead-only-when-swap-slot-cache-is-enabled mm/swap_state.c
@@ -324,9 +324,16 @@ struct page *__read_swap_cache_async(swp
 		if (found_page)
 			break;
 
-		/* Just skip read ahead for unused swap slot */
-		if (!__swp_swapcount(entry))
-			return NULL;
+		/*
+		 * Just skip read ahead for unused swap slot.
+		 * During swap_off when swap_slot_cache is disabled,
+		 * we have to handle the race between putting
+		 * swap entry in swap cache and marking swap slot
+		 * as SWAP_HAS_CACHE.  That's done in later part of code or
+		 * else swap_off will be aborted if we return NULL.
+		 */
+		if (!__swp_swapcount(entry) && swap_slot_cache_enabled)
+			break;
 
 		/*
 		 * Get a new page to read into from swap.

_