[PATCH 2/7] mm: Make use of the anon_vma ref count

Previous thread: [PATCH 7/7] mm: Optimize page_lock_anon_vma by Peter Zijlstra on Friday, April 2, 2010 - 7:16 am. (1 message)

Next thread: [PATCH 3/7] mm: Preemptible mmu_gather by Peter Zijlstra on Friday, April 2, 2010 - 7:16 am. (1 message)
From: Peter Zijlstra
Date: Friday, April 2, 2010 - 7:16 am

This patch changes the anon_vma refcount to be 0 when the object is
free. It does this by adding 1 ref to being in use in the anon_vma
structure (iow. the anon_vma->head list is not empty).

This allows a simpler release scheme without having to check both the
refcount and the list as well as avoids taking a ref for each entry
on the list.

We then use this new refcount in the migration code to avoid a long
RCU read side section and convert page_lock_anon_vma() over to use
refcounts.

This later is done for each of convertion of anon_vma from spinlock
to mutex.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 include/linux/rmap.h |    7 +++++++
 mm/ksm.c             |    9 +--------
 mm/migrate.c         |   17 ++++++-----------
 mm/rmap.c            |   43 +++++++++++++++++++++++++++++--------------
 4 files changed, 43 insertions(+), 33 deletions(-)

Index: linux-2.6/include/linux/rmap.h
===================================================================
--- linux-2.6.orig/include/linux/rmap.h
+++ linux-2.6/include/linux/rmap.h
@@ -100,6 +100,13 @@ static inline void anon_vma_merge(struct
 	unlink_anon_vmas(next);
 }
 
+struct anon_vma *anon_vma_get(struct page *page);
+static inline void anon_vma_put(struct anon_vma *anon_vma)
+{
+	if (atomic_dec_and_test(&anon_vma->ref))
+		anon_vma_free(anon_vma);
+}
+
 /*
  * rmap interfaces called when adding or removing pte of page
  */
Index: linux-2.6/mm/ksm.c
===================================================================
--- linux-2.6.orig/mm/ksm.c
+++ linux-2.6/mm/ksm.c
@@ -323,14 +323,7 @@ static void hold_anon_vma(struct rmap_it
 
 static void drop_anon_vma(struct rmap_item *rmap_item)
 {
-	struct anon_vma *anon_vma = rmap_item->anon_vma;
-
-	if (atomic_dec_and_lock(&anon_vma->ref, &anon_vma->lock)) {
-		int empty = list_empty(&anon_vma->head);
-		spin_unlock(&anon_vma->lock);
-		if (empty)
-			anon_vma_free(anon_vma);
-	}
+	anon_vma_put(rmap_item->anon_vma);
 }
 
 /*
Index: ...
Previous thread: [PATCH 7/7] mm: Optimize page_lock_anon_vma by Peter Zijlstra on Friday, April 2, 2010 - 7:16 am. (1 message)

Next thread: [PATCH 3/7] mm: Preemptible mmu_gather by Peter Zijlstra on Friday, April 2, 2010 - 7:16 am. (1 message)