Skip to content

Commit

Permalink
mm, THP, swap: support splitting THP for THP swap out
Browse files Browse the repository at this point in the history
After adding swapping out support for THP (Transparent Huge Page), it is
possible that a THP in swap cache (partly swapped out) need to be split.
To split such a THP, the swap cluster backing the THP need to be split
too, that is, the CLUSTER_FLAG_HUGE flag need to be cleared for the swap
cluster.  The patch implemented this.

And because the THP swap writing needs the THP keeps as huge page during
writing.  The PageWriteback flag is checked before splitting.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: "Huang, Ying" <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Minchan Kim <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Shaohua Li <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: "Kirill A . Shutemov" <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Ross Zwisler <[email protected]> [for brd.c, zram_drv.c, pmem.c]
Cc: Vishal L Verma <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
yhuang-intel authored and torvalds committed Sep 7, 2017
1 parent 225311a commit 5980768
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
9 changes: 9 additions & 0 deletions include/linux/swap.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,15 @@ static inline swp_entry_t get_swap_page(struct page *page)

#endif /* CONFIG_SWAP */

#ifdef CONFIG_THP_SWAP
extern int split_swap_cluster(swp_entry_t entry);
#else
static inline int split_swap_cluster(swp_entry_t entry)
{
return 0;
}
#endif

#ifdef CONFIG_MEMCG
static inline int mem_cgroup_swappiness(struct mem_cgroup *memcg)
{
Expand Down
10 changes: 9 additions & 1 deletion mm/huge_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -2481,6 +2481,9 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
VM_BUG_ON_PAGE(!PageLocked(page), page);
VM_BUG_ON_PAGE(!PageCompound(page), page);

if (PageWriteback(page))
return -EBUSY;

if (PageAnon(head)) {
/*
* The caller does not necessarily hold an mmap_sem that would
Expand Down Expand Up @@ -2558,7 +2561,12 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
__dec_node_page_state(page, NR_SHMEM_THPS);
spin_unlock(&pgdata->split_queue_lock);
__split_huge_page(page, list, flags);
ret = 0;
if (PageSwapCache(head)) {
swp_entry_t entry = { .val = page_private(head) };

ret = split_swap_cluster(entry);
} else
ret = 0;
} else {
if (IS_ENABLED(CONFIG_DEBUG_VM) && mapcount) {
pr_alert("total_mapcount: %u, page_count(): %u\n",
Expand Down
15 changes: 15 additions & 0 deletions mm/swapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,21 @@ static void swapcache_free_cluster(swp_entry_t entry)
}
}
}

int split_swap_cluster(swp_entry_t entry)
{
struct swap_info_struct *si;
struct swap_cluster_info *ci;
unsigned long offset = swp_offset(entry);

si = _swap_info_get(entry);
if (!si)
return -EBUSY;
ci = lock_cluster(si, offset);
cluster_clear_huge(ci);
unlock_cluster(ci);
return 0;
}
#else
static inline void swapcache_free_cluster(swp_entry_t entry)
{
Expand Down

0 comments on commit 5980768

Please sign in to comment.