[PATCH -mm -v9 3/3] mm, THP, swap: Enable THP swap optimization only if has compound map

From: Huang, Ying
Date: Wed Apr 19 2017 - 03:06:58 EST


From: Huang Ying <ying.huang@xxxxxxxxx>

If there is no compound map for a THP (Transparent Huge Page), it is
possible that the map count of some sub-pages of the THP is 0. So it
is better to split the THP before swapping out. In this way, the
sub-pages not mapped will be freed, and we can avoid the unnecessary
swap out operations for these sub-pages.

Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
Signed-off-by: "Huang, Ying" <ying.huang@xxxxxxxxx>
---
mm/swap_state.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/mm/swap_state.c b/mm/swap_state.c
index 3a3217f68937..b025c9878e5e 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -192,9 +192,15 @@ int add_to_swap(struct page *page, struct list_head *list)
VM_BUG_ON_PAGE(!PageLocked(page), page);
VM_BUG_ON_PAGE(!PageUptodate(page), page);

- /* cannot split, skip it */
- if (unlikely(PageTransHuge(page)) && !can_split_huge_page(page, NULL))
- return 0;
+ if (unlikely(PageTransHuge(page))) {
+ /* cannot split, skip it */
+ if (!can_split_huge_page(page, NULL))
+ return 0;
+ /* fallback to split huge page firstly if no PMD map */
+ if (!compound_mapcount(page) &&
+ split_huge_page_to_list(page, list))
+ return 0;
+ }

retry:
entry = get_swap_page(page);
--
2.11.0