Skip to contentSkip to conversation

mm, swap: skip swapcache for swapin of synchronous device

PATCH New [email protected] 1 participant 1 message Nov 16, 2017

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 31/131 mm, swap: skip swapcache for swapin of synchronous device

From: Minchan Kim <[email protected]>
Subject: mm, swap: skip swapcache for swapin of synchronous device

With fast swap storage, the platforms want to use swap more aggressively and swap-in is crucial to application latency.

The rw_page() based synchronous devices like zram, pmem and btt are such fast storage. When I profile swapin performance with zram lz4 decompress test, S/W overhead is more than 70%. Maybe, it would be bigger in nvdimm.

This patch aims to reduce swap-in latency by skipping swapcache if the swap device is synchronous device like rw_page based device. It enhances 45% my swapin test(5G sequential swapin, no readahead, from 2.41sec to 1.64sec).

Cc Dan Williams <[email protected]>
Cc Ross Zwisler <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ilya Dryomov <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Huang Ying <[email protected]>

---

 include/linux/swap.h |   11 ++++++++
 mm/memory.c          |   52 ++++++++++++++++++++++++++++-------------
 mm/page_io.c         |    6 ++--
 mm/swapfile.c        |   11 +++++---
 4 files changed, 57 insertions(+), 23 deletions(-)
include/linux/swap.h renamed from include/linux/swap.h~mm-swap-skip-swapcache-for-swapin-of-synchronous-device +11 -0
diff -puN include/linux/swap.h~mm-swap-skip-swapcache-for-swapin-of-synchronous-device include/linux/swap.h
@@ -466,6 +466,7 @@ 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 struct swap_info_struct *swp_swap_info(swp_entry_t entry);
 extern bool reuse_swap_page(struct page *, int *);
 extern int try_to_free_swap(struct page *);
 struct backing_dev_info;
@@ -474,6 +475,16 @@ extern void exit_swap_address_space(unsi
 
 #else /* CONFIG_SWAP */
 
+static inline int swap_readpage(struct page *page, bool do_poll)
+{
+	return 0;
+}
+
+static inline struct swap_info_struct *swp_swap_info(swp_entry_t entry)
+{
+	return NULL;
+}
+
 #define swap_address_space(entry)		(NULL)
 #define get_nr_swap_pages()			0L
 #define total_swap_pages			0L
mm/memory.c renamed from mm/memory.c~mm-swap-skip-swapcache-for-swapin-of-synchronous-device +36 -16

102 lines not on this page · raw message

mm/page_io.c renamed from mm/page_io.c~mm-swap-skip-swapcache-for-swapin-of-synchronous-device +3 -3
diff -puN mm/page_io.c~mm-swap-skip-swapcache-for-swapin-of-synchronous-device mm/page_io.c
@@ -347,7 +347,7 @@ out:
 	return ret;
 }
 
-int swap_readpage(struct page *page, bool do_poll)
+int swap_readpage(struct page *page, bool synchronous)
 {
 	struct bio *bio;
 	int ret = 0;
@@ -355,7 +355,7 @@ int swap_readpage(struct page *page, boo
 	blk_qc_t qc;
 	struct gendisk *disk;
 
-	VM_BUG_ON_PAGE(!PageSwapCache(page), page);
+	VM_BUG_ON_PAGE(!PageSwapCache(page) && !synchronous, page);
 	VM_BUG_ON_PAGE(!PageLocked(page), page);
 	VM_BUG_ON_PAGE(PageUptodate(page), page);
 	if (frontswap_load(page) == 0) {
@@ -403,7 +403,7 @@ int swap_readpage(struct page *page, boo
 	count_vm_event(PSWPIN);
 	bio_get(bio);
 	qc = submit_bio(bio);
-	while (do_poll) {
+	while (synchronous) {
 		set_current_state(TASK_UNINTERRUPTIBLE);
 		if (!READ_ONCE(bio->bi_private))
 			break;
mm/swapfile.c renamed from mm/swapfile.c~mm-swap-skip-swapcache-for-swapin-of-synchronous-device +7 -4
diff -puN mm/swapfile.c~mm-swap-skip-swapcache-for-swapin-of-synchronous-device mm/swapfile.c
@@ -3455,10 +3455,15 @@ int swapcache_prepare(swp_entry_t entry)
 	return __swap_duplicate(entry, SWAP_HAS_CACHE);
 }
 
+struct swap_info_struct *swp_swap_info(swp_entry_t entry)
+{
+	return swap_info[swp_type(entry)];
+}
+
 struct swap_info_struct *page_swap_info(struct page *page)
 {
-	swp_entry_t swap = { .val = page_private(page) };
-	return swap_info[swp_type(swap)];
+	swp_entry_t entry = { .val = page_private(page) };
+	return swp_swap_info(entry);
 }
 
 /*
@@ -3466,7 +3471,6 @@ struct swap_info_struct *page_swap_info(
  */
 struct address_space *__page_file_mapping(struct page *page)
 {
-	VM_BUG_ON_PAGE(!PageSwapCache(page), page);
 	return page_swap_info(page)->swap_file->f_mapping;
 }
 EXPORT_SYMBOL_GPL(__page_file_mapping);
@@ -3474,7 +3478,6 @@ EXPORT_SYMBOL_GPL(__page_file_mapping);
 pgoff_t __page_file_index(struct page *page)
 {
 	swp_entry_t swap = { .val = page_private(page) };
-	VM_BUG_ON_PAGE(!PageSwapCache(page), page);
 	return swp_offset(swap);
 }
 EXPORT_SYMBOL_GPL(__page_file_index);

_