Skip to content

Commit

Permalink
thp: keep huge zero page pinned until tlb flush
Browse files Browse the repository at this point in the history
Andrea has found[1] a race condition on MMU-gather based TLB flush vs
split_huge_page() or shrinker which frees huge zero under us (patch 1/2
and 2/2 respectively).

With new THP refcounting, we don't need patch 1/2: mmu_gather keeps the
page pinned until flush is complete and the pin prevents the page from
being split under us.

We still need patch 2/2.  This is simplified version of Andrea's patch.
We don't need fancy encoding.

[1] http://lkml.kernel.org/r/[email protected]

Signed-off-by: Kirill A. Shutemov <[email protected]>
Reported-by: Andrea Arcangeli <[email protected]>
Reviewed-by: Andrea Arcangeli <[email protected]>
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kiryl authored and torvalds committed Apr 29, 2016
1 parent 66ee95d commit aa88b68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions include/linux/huge_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static inline bool is_huge_zero_pmd(pmd_t pmd)
}

struct page *get_huge_zero_page(void);
void put_huge_zero_page(void);

#else /* CONFIG_TRANSPARENT_HUGEPAGE */
#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
Expand Down Expand Up @@ -208,6 +209,10 @@ static inline bool is_huge_zero_page(struct page *page)
return false;
}

static inline void put_huge_zero_page(void)
{
BUILD_BUG();
}

static inline struct page *follow_devmap_pmd(struct vm_area_struct *vma,
unsigned long addr, pmd_t *pmd, int flags)
Expand Down
6 changes: 3 additions & 3 deletions mm/huge_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ struct page *get_huge_zero_page(void)
return READ_ONCE(huge_zero_page);
}

static void put_huge_zero_page(void)
void put_huge_zero_page(void)
{
/*
* Counter should never go to zero here. Only shrinker can put
Expand Down Expand Up @@ -1684,12 +1684,12 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
if (vma_is_dax(vma)) {
spin_unlock(ptl);
if (is_huge_zero_pmd(orig_pmd))
put_huge_zero_page();
tlb_remove_page(tlb, pmd_page(orig_pmd));
} else if (is_huge_zero_pmd(orig_pmd)) {
pte_free(tlb->mm, pgtable_trans_huge_withdraw(tlb->mm, pmd));
atomic_long_dec(&tlb->mm->nr_ptes);
spin_unlock(ptl);
put_huge_zero_page();
tlb_remove_page(tlb, pmd_page(orig_pmd));
} else {
struct page *page = pmd_page(orig_pmd);
page_remove_rmap(page, true);
Expand Down
5 changes: 5 additions & 0 deletions mm/swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,11 @@ void release_pages(struct page **pages, int nr, bool cold)
zone = NULL;
}

if (is_huge_zero_page(page)) {
put_huge_zero_page();
continue;
}

page = compound_head(page);
if (!put_page_testzero(page))
continue;
Expand Down

0 comments on commit aa88b68

Please sign in to comment.