From 7f60c214fd3a360461f3286c6908084f7f8b1950 Mon Sep 17 00:00:00 2001 From: Mel Gorman Date: Mon, 24 May 2010 14:32:18 -0700 Subject: mm: migration: share the anon_vma ref counts between KSM and page migration For clarity of review, KSM and page migration have separate refcounts on the anon_vma. While clear, this is a waste of memory. This patch gets KSM and page migration to share their toys in a spirit of harmony. Signed-off-by: Mel Gorman Reviewed-by: Minchan Kim Reviewed-by: KOSAKI Motohiro Reviewed-by: Christoph Lameter Reviewed-by: KAMEZAWA Hiroyuki Cc: Rik van Riel Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- include/linux/rmap.h | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) (limited to 'include/linux/rmap.h') diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 567d43f..7721674 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -26,11 +26,17 @@ */ struct anon_vma { spinlock_t lock; /* Serialize access to vma list */ -#ifdef CONFIG_KSM - atomic_t ksm_refcount; -#endif -#ifdef CONFIG_MIGRATION - atomic_t migrate_refcount; +#if defined(CONFIG_KSM) || defined(CONFIG_MIGRATION) + + /* + * The external_refcount is taken by either KSM or page migration + * to take a reference to an anon_vma when there is no + * guarantee that the vma of page tables will exist for + * the duration of the operation. A caller that takes + * the reference is responsible for clearing up the + * anon_vma if they are the last user on release + */ + atomic_t external_refcount; #endif /* * NOTE: the LSB of the head.next is set by @@ -64,46 +70,26 @@ struct anon_vma_chain { }; #ifdef CONFIG_MMU -#ifdef CONFIG_KSM -static inline void ksm_refcount_init(struct anon_vma *anon_vma) +#if defined(CONFIG_KSM) || defined(CONFIG_MIGRATION) +static inline void anonvma_external_refcount_init(struct anon_vma *anon_vma) { - atomic_set(&anon_vma->ksm_refcount, 0); + atomic_set(&anon_vma->external_refcount, 0); } -static inline int ksm_refcount(struct anon_vma *anon_vma) +static inline int anonvma_external_refcount(struct anon_vma *anon_vma) { - return atomic_read(&anon_vma->ksm_refcount); + return atomic_read(&anon_vma->external_refcount); } #else -static inline void ksm_refcount_init(struct anon_vma *anon_vma) +static inline void anonvma_external_refcount_init(struct anon_vma *anon_vma) { } -static inline int ksm_refcount(struct anon_vma *anon_vma) +static inline int anonvma_external_refcount(struct anon_vma *anon_vma) { return 0; } #endif /* CONFIG_KSM */ -#ifdef CONFIG_MIGRATION -static inline void migrate_refcount_init(struct anon_vma *anon_vma) -{ - atomic_set(&anon_vma->migrate_refcount, 0); -} - -static inline int migrate_refcount(struct anon_vma *anon_vma) -{ - return atomic_read(&anon_vma->migrate_refcount); -} -#else -static inline void migrate_refcount_init(struct anon_vma *anon_vma) -{ -} - -static inline int migrate_refcount(struct anon_vma *anon_vma) -{ - return 0; -} -#endif /* CONFIG_MIGRATE */ static inline struct anon_vma *page_anon_vma(struct page *page) { -- cgit v1.1