x86/mm: Eliminate global lock in mem sharing code
PATCH 1/1 x86/mm: Eliminate global lock in mem sharing code
xen/arch/x86/mm.c | 16 +++- xen/arch/x86/mm/mem_sharing.c | 169 ++++++++++++++++++++++++++++++++++++----- xen/arch/x86/mm/mm-locks.h | 6 +- xen/include/asm-x86/mm.h | 2 +- 4 files changed, 163 insertions(+), 30 deletions(-)
With the removal of the hash table, all that is needed now is locking of individual shared pages, as new (gfn,domain) pairs are removed or added from the list of mappings.
The global lock remains for the benefit of the auditing code, and is thus enabled only as a compile-time option.
Signed-off-by Andres Lagar-Cavilla <[email protected]>
xen/arch/x86/mm.c +13 -3
@@ -4337,16 +4337,22 @@ int page_make_sharable(struct domain *d,return 0 ; } -int page_make_private (struct domain *d,struct page_info *page) +int page_make_private (struct domain *d,struct page_info *page, +int unlocked) { +unsigned long expected_type; +if ( !get_page (page, dom_cow) )return -EINVAL ;spin_lock (&d->page_alloc_lock);/* We can only change the type if count is one */ -if ( (page->u.inuse.type_info & (PGT_type_mask | PGT_count_mask)) - != (PGT_shared_page | PGT_validated |1 ) ) +/* If we are locking pages individually, then we need to drop +* the lock here, while the page is typed */ + expected_type = (unlocked) ? (PGT_shared_page | PGT_validated |1 ) + : (PGT_shared_page | PGT_validated | PGT_locked |2 ); +if ( page->u.inuse.type_info != expected_type ) {put_page (page);spin_unlock (&d->page_alloc_lock);
@@ -4356,6 +4362,10 @@ int page_make_private(struct domain *d,/* Drop the final typecount */ put_page_and_type (page); +if ( !unlocked ) +/* Now that we've dropped the type, we can unlock */ +page_unlock (page); +/* Change the owner */ ASSERT (page_get_owner (page) == dom_cow);page_set_owner (page, d);
xen/arch/x86/mm/mem_sharing.c +146 -23
342 lines not on this page · raw message
xen/arch/x86/mm/mm-locks.h +3 -3
@@ -147,9 +147,9 @@ static inline void mm_enforce_order_unlo* hash tables. */ declare_mm_lock(shr) -#define shr_lock () mm_lock(shr, &shr_lock) -#define shr_unlock () mm_unlock(&shr_lock) -#define shr_locked_by_me () mm_locked_by_me(&shr_lock) +#define _shr_lock () mm_lock(shr, &shr_lock) +#define _shr_unlock () mm_unlock(&shr_lock) +#define _shr_locked_by_me () mm_locked_by_me(&shr_lock)/* Nested P2M lock (per-domain) *
xen/include/asm-x86/mm.h +1 -1
@@ -594,7 +594,7 @@ int donate_page(int page_make_sharable (struct domain *d,struct page_info *page,int expected_refcnt); -int page_make_private (struct domain *d,struct page_info *page); +int page_make_private (struct domain *d,struct page_info *page,int unlocked);int map_ldt_shadow_page (unsigned int );