extern void prep_transhuge_page(struct page *page);
 extern void free_transhuge_page(struct page *page);
 
+bool can_split_huge_page(struct page *page, int *pextra_pins);
 int split_huge_page_to_list(struct page *page, struct list_head *list);
 static inline int split_huge_page(struct page *page)
 {
 
 #define thp_get_unmapped_area  NULL
 
+static inline bool
+can_split_huge_page(struct page *page, int *pextra_pins)
+{
+       BUILD_BUG();
+       return false;
+}
 static inline int
 split_huge_page_to_list(struct page *page, struct list_head *list)
 {
 
        return ret;
 }
 
+/* Racy check whether the huge page can be split */
+bool can_split_huge_page(struct page *page, int *pextra_pins)
+{
+       int extra_pins;
+
+       /* Additional pins from radix tree */
+       if (PageAnon(page))
+               extra_pins = PageSwapCache(page) ? HPAGE_PMD_NR : 0;
+       else
+               extra_pins = HPAGE_PMD_NR;
+       if (pextra_pins)
+               *pextra_pins = extra_pins;
+       return total_mapcount(page) == page_count(page) - extra_pins - 1;
+}
+
 /*
  * This function splits huge page into normal pages. @page can point to any
  * subpage of huge page to split. Split doesn't change the position of @page.
                        ret = -EBUSY;
                        goto out;
                }
-               extra_pins = PageSwapCache(page) ? HPAGE_PMD_NR : 0;
                mapping = NULL;
                anon_vma_lock_write(anon_vma);
        } else {
                        goto out;
                }
 
-               /* Addidional pins from radix tree */
-               extra_pins = HPAGE_PMD_NR;
                anon_vma = NULL;
                i_mmap_lock_read(mapping);
        }
         * Racy check if we can split the page, before freeze_page() will
         * split PMDs
         */
-       if (total_mapcount(head) != page_count(head) - extra_pins - 1) {
+       if (!can_split_huge_page(head, &extra_pins)) {
                ret = -EBUSY;
                goto out_unlock;
        }
 
                    !PageSwapCache(page)) {
                        if (!(sc->gfp_mask & __GFP_IO))
                                goto keep_locked;
+                       /* cannot split THP, skip it */
+                       if (PageTransHuge(page) &&
+                           !can_split_huge_page(page, NULL))
+                               goto activate_locked;
                        if (!add_to_swap(page)) {
                                if (!PageTransHuge(page))
                                        goto activate_locked;