mm, THP, swap: support splitting THP for THP swap out
authorHuang Ying <ying.huang@intel.com>
Wed, 6 Sep 2017 23:22:34 +0000 (16:22 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 7 Sep 2017 00:27:28 +0000 (17:27 -0700)
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/20170724051840.2309-8-ying.huang@intel.com
Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Shaohua Li <shli@kernel.org>
Cc: Rik van Riel <riel@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Ross Zwisler <ross.zwisler@intel.com> [for brd.c, zram_drv.c, pmem.c]
Cc: Vishal L Verma <vishal.l.verma@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/swap.h
mm/huge_memory.c
mm/swapfile.c

index 7176ba780e83f3901e19a1578f604baf29b855be..461cf107ad52c6f86078f4b0ba519b6dbf339083 100644 (file)
@@ -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)
 {
index 02dfe635c9fe0285f10e285936bf0b7a515f72fd..772048c233d1cfca69ddc781d9cf12c67caefc72 100644 (file)
@@ -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
@@ -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",
index 267b1fe41844b129c0f0c3e79814c96c4f28a382..42eff9e4e9721bbd952d132f591fcfd7d2427193 100644 (file)
@@ -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)
 {