Skip to contentSkip to conversation

mm/swap: skip read ahead for unreferenced swap slots

PATCH Superseded Tim Chen 1 participant 1 message Sep 27, 2016

Subsystems (2)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Tim Chen

author
#0 lore raw

PATCH 4/8 mm/swap: skip read ahead for unreferenced swap slots

We can avoid needlessly allocating page for swap slots that are not used by anyone. No pages have to be read in for these slots.

---
 include/linux/swap.h |  6 ++++++
 mm/swap_state.c      |  4 ++++
 mm/swapfile.c        | 47 +++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 51 insertions(+), 6 deletions(-)
include/linux/swap.h +6 -0
index 5302cce..68ab90c 100644
@@ -422,6 +422,7 @@ extern unsigned int count_swap_pages(int, int);
 extern sector_t map_swap_page(struct page *, struct block_device **);
 extern sector_t swapdev_block(int, pgoff_t);
 extern int page_swapcount(struct page *);
+extern int __swp_swapcount(swp_entry_t entry);
 extern int swp_swapcount(swp_entry_t entry);
 extern struct swap_info_struct *page_swap_info(struct page *);
 extern bool reuse_swap_page(struct page *, int *);
@@ -516,6 +517,11 @@ static inline int page_swapcount(struct page *page)
 	return 0;
 }
 
+static inline int __swp_swapcount(swp_entry_t entry)
+{
+	return 0;
+}
+
 static inline int swp_swapcount(swp_entry_t entry)
 {
 	return 0;
mm/swap_state.c +4 -0
index 102595c..579807d 100644
@@ -316,6 +316,10 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
 	*new_page_allocated = false;
 
 	do {
+		/* Just skip read ahead for unused swap slot */
+		if (!__swp_swapcount(entry))
+			return NULL;
+
 		/*
 		 * First check the swap cache.  Since this is normally
 		 * called after lookup_swap_cache() failed, re-calling
mm/swapfile.c +41 -6

73 lines not on this page · raw message

Signature · 7 lines
2.5.5

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>