From: Michel Lespinasse <walken@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: Andrea Arcangeli <aarcange@redhat.com>,
Hugh Dickins <hughd@google.com>,
Minchan Kim <minchan.kim@gmail.com>,
Johannes Weiner <jweiner@redhat.com>,
Rik van Riel <riel@redhat.com>, Mel Gorman <mgorman@suse.de>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Shaohua Li <shaohua.li@intel.com>
Subject: [PATCH 9/9] mm: make sure tail page counts are stable before splitting THP pages
Date: Fri, 19 Aug 2011 00:48:31 -0700 [thread overview]
Message-ID: <1313740111-27446-10-git-send-email-walken@google.com> (raw)
In-Reply-To: <1313740111-27446-1-git-send-email-walken@google.com>
As described in the page_cache_get_speculative() comment
in pagemap.h, the count of all pages coming out of the allocator
must be considered unstable unless an RCU grace period has passed
since the pages were allocated.
This is an issue for THP because __split_huge_page_refcount()
depends on tail page counts being stable.
By setting a cookie on THP pages when they are allocated, we are able
to ensure the tail page counts are stable before splitting such pages.
In the typical case, the THP page should be old enough by the time we
try to split it, so that we won't have to wait.
Signed-off-by: Michel Lespinasse <walken@google.com>
---
mm/huge_memory.c | 33 +++++++++++++++++++++++++++++----
1 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 81532f2..46c0c0b 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -657,15 +657,23 @@ static inline struct page *alloc_hugepage_vma(int defrag,
unsigned long haddr, int nd,
gfp_t extra_gfp)
{
- return alloc_pages_vma(alloc_hugepage_gfpmask(defrag, extra_gfp),
+ struct page *page;
+ page = alloc_pages_vma(alloc_hugepage_gfpmask(defrag, extra_gfp),
HPAGE_PMD_ORDER, vma, haddr, nd);
+ if (page)
+ page_get_gp_cookie(page);
+ return page;
}
#ifndef CONFIG_NUMA
static inline struct page *alloc_hugepage(int defrag)
{
- return alloc_pages(alloc_hugepage_gfpmask(defrag, 0),
+ struct page *page;
+ page = alloc_pages(alloc_hugepage_gfpmask(defrag, 0),
HPAGE_PMD_ORDER);
+ if (page)
+ page_get_gp_cookie(page);
+ return page;
}
#endif
@@ -1209,7 +1217,7 @@ static void __split_huge_page_refcount(struct page *page)
BUG_ON(page_mapcount(page_tail));
page_tail->_mapcount = page->_mapcount;
- BUG_ON(page_tail->mapping);
+ BUG_ON(page_tail->mapping); /* see page_clear_gp_cookie() */
page_tail->mapping = page->mapping;
page_tail->index = ++head_index;
@@ -1387,9 +1395,11 @@ static void __split_huge_page(struct page *page,
int split_huge_page(struct page *page)
{
struct anon_vma *anon_vma;
- int ret = 1;
+ int ret;
+retry:
BUG_ON(!PageAnon(page));
+ ret = 1;
anon_vma = page_lock_anon_vma(page);
if (!anon_vma)
goto out;
@@ -1397,6 +1407,21 @@ int split_huge_page(struct page *page)
if (!PageCompound(page))
goto out_unlock;
+ /*
+ * Make sure the tail page counts are stable before splitting the page.
+ * See the page_cache_get_speculative() comment in pagemap.h.
+ */
+ if (!page_gp_cookie_elapsed(page)) {
+ page_unlock_anon_vma(anon_vma);
+ synchronize_rcu();
+ goto retry;
+ }
+
+ /*
+ * Make sure page_tail->mapping is cleared before we split up the page.
+ */
+ page_clear_gp_cookie(page);
+
BUG_ON(!PageSwapBacked(page));
__split_huge_page(page, anon_vma);
count_vm_event(THP_SPLIT);
--
1.7.3.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-08-19 7:49 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-19 7:48 [PATCH 0/9] Use RCU to stabilize page counts Michel Lespinasse
2011-08-19 7:48 ` [PATCH 1/9] mm: rcu read lock for getting reference on pages in migration_entry_wait() Michel Lespinasse
2011-08-19 7:48 ` [PATCH 2/9] mm: avoid calling get_page_unless_zero() when charging cgroups Michel Lespinasse
2011-08-19 7:48 ` [PATCH 3/9] mm: rcu read lock when getting from tail to head page Michel Lespinasse
2011-08-19 7:48 ` [PATCH 4/9] mm: use get_page in deactivate_page() Michel Lespinasse
2011-08-19 7:48 ` [PATCH 5/9] kvm: use get_page instead of get_page_unless_zero Michel Lespinasse
2011-08-19 7:48 ` [PATCH 6/9] mm: assert that get_page_unless_zero() callers hold the rcu lock Michel Lespinasse
2011-08-19 23:28 ` Andi Kleen
2011-08-19 7:48 ` [PATCH 7/9] rcu: rcu_get_gp_cookie() / rcu_gp_cookie_elapsed() stand-ins Michel Lespinasse
2011-08-19 7:48 ` [PATCH 8/9] mm: add API for setting a grace period cookie on compound pages Michel Lespinasse
2011-08-19 7:48 ` Michel Lespinasse [this message]
2011-08-19 7:53 ` [PATCH 0/9] Use RCU to stabilize page counts Michel Lespinasse
2011-08-22 21:33 ` [PATCH] thp: tail page refcounting fix Andrea Arcangeli
2011-08-23 14:55 ` Andrea Arcangeli
2011-08-23 16:45 ` Minchan Kim
2011-08-23 16:54 ` Andrea Arcangeli
2011-08-23 19:52 ` Michel Lespinasse
2011-08-24 0:09 ` Andrea Arcangeli
2011-08-24 0:27 ` Andrea Arcangeli
2011-08-24 13:34 ` [PATCH] thp: tail page refcounting fix #2 Andrea Arcangeli
2011-08-26 6:24 ` Michel Lespinasse
2011-08-26 16:10 ` Andrea Arcangeli
2011-08-26 18:54 ` [PATCH] thp: tail page refcounting fix #3 Andrea Arcangeli
2011-08-27 9:41 ` Michel Lespinasse
2011-08-27 17:34 ` [PATCH] thp: tail page refcounting fix #4 Andrea Arcangeli
2011-08-29 4:20 ` Minchan Kim
2011-09-01 15:24 ` [PATCH] thp: tail page refcounting fix #5 Andrea Arcangeli
2011-09-01 22:27 ` Michel Lespinasse
2011-09-01 23:28 ` Andrew Morton
2011-09-01 23:45 ` Andi Kleen
2011-09-02 0:20 ` Andrea Arcangeli
2011-09-02 1:17 ` Andi Kleen
2011-09-02 0:03 ` Andrew Morton
2011-09-08 16:51 ` [PATCH] thp: tail page refcounting fix #6 Andrea Arcangeli
2011-09-23 15:57 ` Peter Zijlstra
2011-09-30 13:58 ` Andrea Arcangeli
2011-10-16 20:37 ` thp: gup_fast ppc tail refcounting [was Re: [PATCH] thp: tail page refcounting fix #6] Andrea Arcangeli
2011-10-16 20:37 ` [PATCH 1/4] powerpc: remove superfluous PageTail checks on the pte gup_fast Andrea Arcangeli
2011-10-16 20:37 ` [PATCH 2/4] powerpc: get_hugepte() don't put_page() the wrong page Andrea Arcangeli
2011-10-16 20:37 ` [PATCH 3/4] powerpc: gup_hugepte() avoid to free the head page too many times Andrea Arcangeli
2011-10-16 20:37 ` [PATCH 4/4] powerpc: gup_hugepte() support THP based tail recounting Andrea Arcangeli
2011-10-16 20:40 ` thp: gup_fast ppc tail refcounting [was Re: [PATCH] thp: tail page refcounting fix #6] Andrea Arcangeli
2011-10-16 20:40 ` [PATCH 1/4] powerpc: remove superfluous PageTail checks on the pte gup_fast Andrea Arcangeli
2011-10-16 20:40 ` [PATCH 2/4] powerpc: get_hugepte() don't put_page() the wrong page Andrea Arcangeli
2011-10-16 20:40 ` [PATCH 3/4] powerpc: gup_hugepte() avoid to free the head page too many times Andrea Arcangeli
2011-10-16 20:40 ` [PATCH 4/4] powerpc: gup_hugepte() support THP based tail recounting Andrea Arcangeli
2011-10-17 14:41 ` thp: gup_fast s390/sparc tail refcounting [was Re: [PATCH] thp: tail page refcounting fix #6] Andrea Arcangeli
2011-10-17 14:41 ` [PATCH 1/3] s390: gup_huge_pmd() support THP tail recounting Andrea Arcangeli
2011-10-17 14:41 ` [PATCH 2/3] sparc: gup_pte_range() support THP based " Andrea Arcangeli
2011-10-17 22:44 ` David Miller
2011-10-17 14:41 ` [PATCH 3/3] thp: share get_huge_page_tail() Andrea Arcangeli
2011-10-17 21:32 ` fix two more s390/sparc gup_fast bugs Andrea Arcangeli
2011-10-17 21:32 ` [PATCH 1/2] s390: gup_huge_pmd() return 0 if pte changes Andrea Arcangeli
2011-10-17 21:32 ` [PATCH 2/2] powerpc: " Andrea Arcangeli
2011-08-29 22:40 ` [PATCH] thp: tail page refcounting fix #4 Michel Lespinasse
2011-08-29 23:30 ` Andrea Arcangeli
2011-08-26 19:28 ` [PATCH] thp: tail page refcounting fix #2 Andrea Arcangeli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1313740111-27446-10-git-send-email-walken@google.com \
--to=walken@google.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=jweiner@redhat.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=minchan.kim@gmail.com \
--cc=riel@redhat.com \
--cc=shaohua.li@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).