Convert page_lock_anon_vma() over to use refcounts. This is done for each of convertion of anon_vma from spinlock to mutex. Signed-off-by: Peter Zijlstra --- mm/rmap.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) Index: linux-2.6/mm/rmap.c =================================================================== --- linux-2.6.orig/mm/rmap.c +++ linux-2.6/mm/rmap.c @@ -332,9 +332,9 @@ void __init anon_vma_init(void) * that the anon_vma pointer from page->mapping is valid if there is a * mapcount, we can dereference the anon_vma after observing those. */ -struct anon_vma *page_lock_anon_vma(struct page *page) +struct anon_vma *page_get_anon_vma(struct page *page) { - struct anon_vma *anon_vma, *root_anon_vma; + struct anon_vma *anon_vma = NULL; unsigned long anon_mapping; rcu_read_lock(); @@ -345,8 +345,10 @@ struct anon_vma *page_lock_anon_vma(stru goto out; anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON); - root_anon_vma = ACCESS_ONCE(anon_vma->root); - spin_lock(&root_anon_vma->lock); + if (!atomic_inc_not_zero(&anon_vma->refcount)) { + anon_vma = NULL; + goto out; + } /* * If this page is still mapped, then its anon_vma cannot have been @@ -356,19 +358,31 @@ struct anon_vma *page_lock_anon_vma(stru * corrupt): with anon_vma_prepare() or anon_vma_fork() redirecting * anon_vma->root before page_unlock_anon_vma() is called to unlock. */ - if (page_mapped(page)) - return anon_vma; - - spin_unlock(&root_anon_vma->lock); + if (!page_mapped(page)) { + put_anon_vma(anon_vma); + anon_vma = NULL; + goto out; + } out: rcu_read_unlock(); - return NULL; + + return anon_vma; +} + +struct anon_vma *page_lock_anon_vma(struct page *page) +{ + struct anon_vma *anon_vma = page_get_anon_vma(page); + + if (anon_vma) + anon_vma_lock(anon_vma); + + return anon_vma; } void page_unlock_anon_vma(struct anon_vma *anon_vma) { anon_vma_unlock(anon_vma); - rcu_read_unlock(); + put_anon_vma(anon_vma); } /* -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/