[PATCH 4/7] mm: Shrink page list batch allocates swap slots for page swapping
From: Tim Chen
Date: Tue May 03 2016 - 17:02:32 EST
In shrink page list, we take advantage bulk allocation of swap entries
with the new get_swap_pages function. This reduces contention on a
swap device's swap_info lock. When the memory is low and the system is
actively trying to reclaim memory, both direct reclaim path and kswapd
contends on this lock when they access the same swap partition.
Signed-off-by: Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>
---
Âmm/vmscan.c | 63 ++++++++++++++++++++++++++++++++++++++++---------------------
Â1 file changed, 42 insertions(+), 21 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index e36d8a7..310e2b2 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1096,38 +1096,59 @@ static unsigned long shrink_anon_page_list(struct list_head *page_list,
Â{
 unsigned long nr_reclaimed = 0;
 enum pg_result pg_dispose;
+ swp_entry_t swp_entries[SWAP_BATCH];
+ struct page *page;
+ int m, i, k;
Â
 while (n > 0) {
- struct page *page;
 int swap_ret = SWAP_SUCCESS;
Â
- --n;
- if (list_empty(swap_pages))
- ÂÂÂÂÂÂÂreturn nr_reclaimed;
+ m = get_swap_pages(n, swp_entries);
+ if (!m)
+ goto no_swap_slots;
+ n -= m;
+ for (i = 0; i < m; ++i) {
+ if (list_empty(swap_pages)) {
+ /* free any leftover swap slots */
+ for (k = i; k < m; ++k)
+ swapcache_free(swp_entries[k]);
+ return nr_reclaimed;
+ }
+ page = lru_to_page(swap_pages);
Â
- page = lru_to_page(swap_pages);
+ list_del(&page->lru);
Â
- list_del(&page->lru);
+ /*
+ * Anonymous process memory has backing store?
+ * Try to allocate it some swap space here.
+ */
+
+ if (!add_to_swap(page, page_list, NULL)) {
+ pg_finish(page, PG_ACTIVATE_LOCKED, swap_ret,
+ &nr_reclaimed, pgactivate,
+ ret_pages, free_pages);
+ continue;
+ }
Â
- /*
- * Anonymous process memory has backing store?
- * Try to allocate it some swap space here.
- */
+ if (clean)
+ pg_dispose = handle_pgout(page_list, zone, sc,
+ ttu_flags, PAGEREF_RECLAIM_CLEAN,
+ true, true, &swap_ret, page);
+ else
+ pg_dispose = handle_pgout(page_list, zone, sc,
+ ttu_flags, PAGEREF_RECLAIM,
+ true, true, &swap_ret, page);
Â
- if (!add_to_swap(page, page_list, NULL)) {
- pg_finish(page, PG_ACTIVATE_LOCKED, swap_ret, &nr_reclaimed,
+ pg_finish(page, pg_dispose, swap_ret, &nr_reclaimed,
 pgactivate, ret_pages, free_pages);
- continue;
 }
+ }
+ return nr_reclaimed;
Â
- if (clean)
- pg_dispose = handle_pgout(page_list, zone, sc, ttu_flags,
- PAGEREF_RECLAIM_CLEAN, true, true, &swap_ret, page);
- else
- pg_dispose = handle_pgout(page_list, zone, sc, ttu_flags,
- PAGEREF_RECLAIM, true, true, &swap_ret, page);
-
- pg_finish(page, pg_dispose, swap_ret, &nr_reclaimed,
+no_swap_slots:
+ while (!list_empty(swap_pages)) {
+ page = lru_to_page(swap_pages);
+ pg_finish(page, PG_ACTIVATE_LOCKED, 0, &nr_reclaimed,
 pgactivate, ret_pages, free_pages);
 }
 return nr_reclaimed;
--Â
2.5.5