From 1aa277e8bb6bfed5aa0e9c60450393dc06ab3767 Mon Sep 17 00:00:00 2001 From: Andrea Arcangeli Date: Wed, 28 Sep 2011 10:50:22 +1000 Subject: [PATCH] thp-tail-page-refcounting-fix-6 Signed-off-by: Andrea Arcangeli Cc: Michel Lespinasse Cc: Michel Lespinasse Cc: Minchan Kim Signed-off-by: Andrew Morton <> --- include/linux/mm.h | 2 +- mm/internal.h | 5 +++++ mm/swap.c | 12 +++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 527c5bb4188a..95426cdc396e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -377,7 +377,7 @@ static inline int page_count(struct page *page) return atomic_read(&compound_head(page)->_count); } -extern int __get_page_tail(struct page *page); +extern bool __get_page_tail(struct page *page); static inline void get_page(struct page *page) { diff --git a/mm/internal.h b/mm/internal.h index cd09cca70423..2189af491783 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -59,6 +59,11 @@ static inline void __get_page_tail_foll(struct page *page, atomic_inc(&page->_mapcount); } +/* + * This is meant to be called as the FOLL_GET operation of + * follow_page() and it must be called while holding the proper PT + * lock while the pte (or pmd_trans_huge) is still mapping the page. + */ static inline void get_page_foll(struct page *page) { if (unlikely(PageTail(page))) diff --git a/mm/swap.c b/mm/swap.c index 93c0b582ee06..1c5576ae3552 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -79,6 +79,7 @@ static void put_compound_page(struct page *page) if (unlikely(PageTail(page))) { /* __split_huge_page_refcount can run under us */ struct page *page_head = compound_trans_head(page); + if (likely(page != page_head && get_page_unless_zero(page_head))) { unsigned long flags; @@ -143,7 +144,11 @@ void put_page(struct page *page) } EXPORT_SYMBOL(put_page); -int __get_page_tail(struct page *page) +/* + * This function is exported but must not be called by anything other + * than get_page(). It implements the slow path of get_page(). + */ +bool __get_page_tail(struct page *page) { /* * This takes care of get_page() if run on a tail page @@ -154,8 +159,9 @@ int __get_page_tail(struct page *page) * split_huge_page(). */ unsigned long flags; - int got = 0; + bool got = false; struct page *page_head = compound_trans_head(page); + if (likely(page != page_head && get_page_unless_zero(page_head))) { /* * page_head wasn't a dangling pointer but it @@ -167,7 +173,7 @@ int __get_page_tail(struct page *page) /* here __split_huge_page_refcount won't run anymore */ if (likely(PageTail(page))) { __get_page_tail_foll(page, false); - got = 1; + got = true; } compound_unlock_irqrestore(page_head, flags); if (unlikely(!got)) -- 2.39.5