Skip to contentSkip to conversation

mm/swap: allocate swap slots in batches

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 116/142 mm/swap: allocate swap slots in batches

From: Tim Chen <[email protected]>
Subject: mm/swap: allocate swap slots in batches

Currently, the swap slots are allocated one page at a time, causing contention to the swap_info lock protecting the swap partition on every page being swapped.

This patch adds new functions get_swap_pages and scan_swap_map_slots to request multiple swap slots at once. This will reduces the lock contention on the swap_info lock. Also scan_swap_map_slots can operate more efficiently as swap slots often occurs in clusters close to each other on a swap device and it is quicker to allocate them together.

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.h |    2 
 mm/swapfile.c        |  136 +++++++++++++++++++++++++++++++++--------
 2 files changed, 113 insertions(+), 25 deletions(-)
include/linux/swap.h renamed from include/linux/swap.h~mm-swap-allocate-swap-slots-in-batches +2 -0
diff -puN include/linux/swap.h~mm-swap-allocate-swap-slots-in-batches include/linux/swap.h
@@ -27,6 +27,7 @@ struct bio;
 #define SWAP_FLAGS_VALID	(SWAP_FLAG_PRIO_MASK | SWAP_FLAG_PREFER | \
 				 SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | \
 				 SWAP_FLAG_DISCARD_PAGES)
+#define SWAP_BATCH 64
 
 static inline int current_is_kswapd(void)
 {
@@ -386,6 +387,7 @@ static inline long get_nr_swap_pages(voi
 extern void si_swapinfo(struct sysinfo *);
 extern swp_entry_t get_swap_page(void);
 extern swp_entry_t get_swap_page_of_type(int);
+extern int get_swap_pages(int n, swp_entry_t swp_entries[]);
 extern int add_swap_count_continuation(swp_entry_t, gfp_t);
 extern void swap_shmem_alloc(swp_entry_t);
 extern int swap_duplicate(swp_entry_t);
mm/swapfile.c renamed from mm/swapfile.c~mm-swap-allocate-swap-slots-in-batches +111 -25

220 lines not on this page · raw message

_