From 547dc035291531ac91c522a019323e878d5f6d9b Mon Sep 17 00:00:00 2001 From: Hugh Dickins Date: Sat, 28 May 2011 13:20:21 -0700 Subject: [PATCH] --- yaml --- r: 252737 b: refs/heads/master c: eee0f252c6537da2e883f75d22cff1427515eaf3 h: refs/heads/master i: 252735: c72970212ecfaeafc6a1f3c824dea4f471a53a92 v: v3 --- [refs] | 2 +- trunk/mm/rmap.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/[refs] b/[refs] index d9766a92f41c..573da0f8abad 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 5dbe0af47f8a8f968bac2991c3ec974c6e3eaabc +refs/heads/master: eee0f252c6537da2e883f75d22cff1427515eaf3 diff --git a/trunk/mm/rmap.c b/trunk/mm/rmap.c index ba58ca36fc90..6bada99cd61c 100644 --- a/trunk/mm/rmap.c +++ b/trunk/mm/rmap.c @@ -405,6 +405,7 @@ struct anon_vma *page_get_anon_vma(struct page *page) struct anon_vma *page_lock_anon_vma(struct page *page) { struct anon_vma *anon_vma = NULL; + struct anon_vma *root_anon_vma; unsigned long anon_mapping; rcu_read_lock(); @@ -415,13 +416,15 @@ struct anon_vma *page_lock_anon_vma(struct page *page) goto out; anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON); - if (mutex_trylock(&anon_vma->root->mutex)) { + root_anon_vma = ACCESS_ONCE(anon_vma->root); + if (mutex_trylock(&root_anon_vma->mutex)) { /* - * If we observe a !0 refcount, then holding the lock ensures - * the anon_vma will not go away, see __put_anon_vma(). + * If the page is still mapped, then this anon_vma is still + * its anon_vma, and holding the mutex ensures that it will + * not go away, see __put_anon_vma(). */ - if (!atomic_read(&anon_vma->refcount)) { - anon_vma_unlock(anon_vma); + if (!page_mapped(page)) { + mutex_unlock(&root_anon_vma->mutex); anon_vma = NULL; } goto out;