xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen: centralize accounting for domain tot_pages
@ 2012-11-28 21:50 Dan Magenheimer
  2012-12-06 17:24 ` Dan Magenheimer
  2012-12-07 15:13 ` Keir Fraser
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Magenheimer @ 2012-11-28 21:50 UTC (permalink / raw)
  To: Keir Fraser, Jan Beulich; +Cc: Konrad Wilk, Zhigang Wang, xen-devel

[-- Attachment #1: Type: text/plain, Size: 5053 bytes --]

xen: centralize accounting for domain tot_pages

Provide and use a common function for all adjustments to a
domain's tot_pages counter in anticipation of future and/or
out-of-tree patches that must adjust related counters
atomically.

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>

 arch/x86/mm.c             |    4 ++--
 arch/x86/mm/mem_sharing.c |    4 ++--
 common/grant_table.c      |    2 +-
 common/memory.c           |    2 +-
 common/page_alloc.c       |   10 ++++++++--
 include/xen/mm.h          |    2 ++
 6 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index ab94b02..3887ca6 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -3842,7 +3842,7 @@ int donate_page(
     {
         if ( d->tot_pages >= d->max_pages )
             goto fail;
-        d->tot_pages++;
+        domain_adjust_tot_pages(d, 1);
     }
 
     page->count_info = PGC_allocated | 1;
@@ -3892,7 +3892,7 @@ int steal_page(
     } while ( (y = cmpxchg(&page->count_info, x, x | 1)) != x );
 
     /* Unlink from original owner. */
-    if ( !(memflags & MEMF_no_refcount) && !--d->tot_pages )
+    if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) )
         drop_dom_ref = 1;
     page_list_del(page, &d->page_list);
 
diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
index 5103285..e91aac5 100644
--- a/xen/arch/x86/mm/mem_sharing.c
+++ b/xen/arch/x86/mm/mem_sharing.c
@@ -639,7 +639,7 @@ static int page_make_sharable(struct domain *d,
     }
 
     page_set_owner(page, dom_cow);
-    d->tot_pages--;
+    domain_adjust_tot_pages(d, -1);
     drop_dom_ref = (d->tot_pages == 0);
     page_list_del(page, &d->page_list);
     spin_unlock(&d->page_alloc_lock);
@@ -680,7 +680,7 @@ static int page_make_private(struct domain *d, struct page_info *page)
     ASSERT(page_get_owner(page) == dom_cow);
     page_set_owner(page, d);
 
-    if ( d->tot_pages++ == 0 )
+    if ( domain_adjust_tot_pages(d, 1) == 1 )
         get_domain(d);
     page_list_add_tail(page, &d->page_list);
     spin_unlock(&d->page_alloc_lock);
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 7912769..ca8d861 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -1656,7 +1656,7 @@ gnttab_transfer(
         }
 
         /* Okay, add the page to 'e'. */
-        if ( unlikely(e->tot_pages++ == 0) )
+        if ( unlikely(domain_adjust_tot_pages(e, 1) == 1) )
             get_knownalive_domain(e);
         page_list_add_tail(page, &e->page_list);
         page_set_owner(page, e);
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 83e2666..9842ea9 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -454,7 +454,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
                              (j * (1UL << exch.out.extent_order)));
 
                 spin_lock(&d->page_alloc_lock);
-                d->tot_pages -= dec_count;
+                domain_adjust_tot_pages(d, -dec_count);
                 drop_dom_ref = (dec_count && !d->tot_pages);
                 spin_unlock(&d->page_alloc_lock);
 
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 15ebc66..e273bb7 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -239,6 +239,12 @@ static long midsize_alloc_zone_pages;
 
 static DEFINE_SPINLOCK(heap_lock);
 
+unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
+{
+    ASSERT(spin_is_locked(&d->page_alloc_lock));
+    return d->tot_pages += pages;
+}
+
 static unsigned long init_node_heap(int node, unsigned long mfn,
                                     unsigned long nr, bool_t *use_tail)
 {
@@ -1291,7 +1297,7 @@ int assign_pages(
         if ( unlikely(d->tot_pages == 0) )
             get_knownalive_domain(d);
 
-        d->tot_pages += 1 << order;
+        domain_adjust_tot_pages(d, 1 << order);
     }
 
     for ( i = 0; i < (1 << order); i++ )
@@ -1375,7 +1381,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)
             page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
         }
 
-        d->tot_pages -= 1 << order;
+        domain_adjust_tot_pages(d, -(1 << order));
         drop_dom_ref = (d->tot_pages == 0);
 
         spin_unlock_recursive(&d->page_alloc_lock);
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 64a0cc1..00b1915 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -48,6 +48,8 @@ void free_xenheap_pages(void *v, unsigned int order);
 #define alloc_xenheap_page() (alloc_xenheap_pages(0,0))
 #define free_xenheap_page(v) (free_xenheap_pages(v,0))
 
+unsigned long domain_adjust_tot_pages(struct domain *d, long pages);
+
 /* Domain suballocator. These functions are *not* interrupt-safe.*/
 void init_domheap_pages(paddr_t ps, paddr_t pe);
 struct page_info *alloc_domheap_pages(

[-- Attachment #2: adjusttot-121128.patch --]
[-- Type: application/octet-stream, Size: 4336 bytes --]

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index ab94b02..3887ca6 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -3842,7 +3842,7 @@ int donate_page(
     {
         if ( d->tot_pages >= d->max_pages )
             goto fail;
-        d->tot_pages++;
+        domain_adjust_tot_pages(d, 1);
     }
 
     page->count_info = PGC_allocated | 1;
@@ -3892,7 +3892,7 @@ int steal_page(
     } while ( (y = cmpxchg(&page->count_info, x, x | 1)) != x );
 
     /* Unlink from original owner. */
-    if ( !(memflags & MEMF_no_refcount) && !--d->tot_pages )
+    if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) )
         drop_dom_ref = 1;
     page_list_del(page, &d->page_list);
 
diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
index 5103285..e91aac5 100644
--- a/xen/arch/x86/mm/mem_sharing.c
+++ b/xen/arch/x86/mm/mem_sharing.c
@@ -639,7 +639,7 @@ static int page_make_sharable(struct domain *d,
     }
 
     page_set_owner(page, dom_cow);
-    d->tot_pages--;
+    domain_adjust_tot_pages(d, -1);
     drop_dom_ref = (d->tot_pages == 0);
     page_list_del(page, &d->page_list);
     spin_unlock(&d->page_alloc_lock);
@@ -680,7 +680,7 @@ static int page_make_private(struct domain *d, struct page_info *page)
     ASSERT(page_get_owner(page) == dom_cow);
     page_set_owner(page, d);
 
-    if ( d->tot_pages++ == 0 )
+    if ( domain_adjust_tot_pages(d, 1) == 1 )
         get_domain(d);
     page_list_add_tail(page, &d->page_list);
     spin_unlock(&d->page_alloc_lock);
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 7912769..ca8d861 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -1656,7 +1656,7 @@ gnttab_transfer(
         }
 
         /* Okay, add the page to 'e'. */
-        if ( unlikely(e->tot_pages++ == 0) )
+        if ( unlikely(domain_adjust_tot_pages(e, 1) == 1) )
             get_knownalive_domain(e);
         page_list_add_tail(page, &e->page_list);
         page_set_owner(page, e);
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 83e2666..9842ea9 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -454,7 +454,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
                              (j * (1UL << exch.out.extent_order)));
 
                 spin_lock(&d->page_alloc_lock);
-                d->tot_pages -= dec_count;
+                domain_adjust_tot_pages(d, -dec_count);
                 drop_dom_ref = (dec_count && !d->tot_pages);
                 spin_unlock(&d->page_alloc_lock);
 
diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 15ebc66..e273bb7 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -239,6 +239,12 @@ static long midsize_alloc_zone_pages;
 
 static DEFINE_SPINLOCK(heap_lock);
 
+unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
+{
+    ASSERT(spin_is_locked(&d->page_alloc_lock));
+    return d->tot_pages += pages;
+}
+
 static unsigned long init_node_heap(int node, unsigned long mfn,
                                     unsigned long nr, bool_t *use_tail)
 {
@@ -1291,7 +1297,7 @@ int assign_pages(
         if ( unlikely(d->tot_pages == 0) )
             get_knownalive_domain(d);
 
-        d->tot_pages += 1 << order;
+        domain_adjust_tot_pages(d, 1 << order);
     }
 
     for ( i = 0; i < (1 << order); i++ )
@@ -1375,7 +1381,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)
             page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
         }
 
-        d->tot_pages -= 1 << order;
+        domain_adjust_tot_pages(d, -(1 << order));
         drop_dom_ref = (d->tot_pages == 0);
 
         spin_unlock_recursive(&d->page_alloc_lock);
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 64a0cc1..00b1915 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -48,6 +48,8 @@ void free_xenheap_pages(void *v, unsigned int order);
 #define alloc_xenheap_page() (alloc_xenheap_pages(0,0))
 #define free_xenheap_page(v) (free_xenheap_pages(v,0))
 
+unsigned long domain_adjust_tot_pages(struct domain *d, long pages);
+
 /* Domain suballocator. These functions are *not* interrupt-safe.*/
 void init_domheap_pages(paddr_t ps, paddr_t pe);
 struct page_info *alloc_domheap_pages(

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] xen: centralize accounting for domain tot_pages
  2012-11-28 21:50 [PATCH] xen: centralize accounting for domain tot_pages Dan Magenheimer
@ 2012-12-06 17:24 ` Dan Magenheimer
  2012-12-06 18:27   ` Keir Fraser
  2012-12-07 15:13 ` Keir Fraser
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Magenheimer @ 2012-12-06 17:24 UTC (permalink / raw)
  To: Keir Fraser, Jan Beulich; +Cc: Konrad Wilk, Zhigang Wang, xen-devel

ping?

> -----Original Message-----
> From: Dan Magenheimer
> Sent: Wednesday, November 28, 2012 2:50 PM
> To: Keir Fraser; Jan Beulich
> Cc: xen-devel@lists.xen.org; Konrad Wilk; Zhigang Wang
> Subject: [PATCH] xen: centralize accounting for domain tot_pages
> 
> xen: centralize accounting for domain tot_pages
> 
> Provide and use a common function for all adjustments to a
> domain's tot_pages counter in anticipation of future and/or
> out-of-tree patches that must adjust related counters
> atomically.
> 
> Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
> 
>  arch/x86/mm.c             |    4 ++--
>  arch/x86/mm/mem_sharing.c |    4 ++--
>  common/grant_table.c      |    2 +-
>  common/memory.c           |    2 +-
>  common/page_alloc.c       |   10 ++++++++--
>  include/xen/mm.h          |    2 ++
>  6 files changed, 16 insertions(+), 8 deletions(-)
> 
> diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
> index ab94b02..3887ca6 100644
> --- a/xen/arch/x86/mm.c
> +++ b/xen/arch/x86/mm.c
> @@ -3842,7 +3842,7 @@ int donate_page(
>      {
>          if ( d->tot_pages >= d->max_pages )
>              goto fail;
> -        d->tot_pages++;
> +        domain_adjust_tot_pages(d, 1);
>      }
> 
>      page->count_info = PGC_allocated | 1;
> @@ -3892,7 +3892,7 @@ int steal_page(
>      } while ( (y = cmpxchg(&page->count_info, x, x | 1)) != x );
> 
>      /* Unlink from original owner. */
> -    if ( !(memflags & MEMF_no_refcount) && !--d->tot_pages )
> +    if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) )
>          drop_dom_ref = 1;
>      page_list_del(page, &d->page_list);
> 
> diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
> index 5103285..e91aac5 100644
> --- a/xen/arch/x86/mm/mem_sharing.c
> +++ b/xen/arch/x86/mm/mem_sharing.c
> @@ -639,7 +639,7 @@ static int page_make_sharable(struct domain *d,
>      }
> 
>      page_set_owner(page, dom_cow);
> -    d->tot_pages--;
> +    domain_adjust_tot_pages(d, -1);
>      drop_dom_ref = (d->tot_pages == 0);
>      page_list_del(page, &d->page_list);
>      spin_unlock(&d->page_alloc_lock);
> @@ -680,7 +680,7 @@ static int page_make_private(struct domain *d, struct page_info *page)
>      ASSERT(page_get_owner(page) == dom_cow);
>      page_set_owner(page, d);
> 
> -    if ( d->tot_pages++ == 0 )
> +    if ( domain_adjust_tot_pages(d, 1) == 1 )
>          get_domain(d);
>      page_list_add_tail(page, &d->page_list);
>      spin_unlock(&d->page_alloc_lock);
> diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
> index 7912769..ca8d861 100644
> --- a/xen/common/grant_table.c
> +++ b/xen/common/grant_table.c
> @@ -1656,7 +1656,7 @@ gnttab_transfer(
>          }
> 
>          /* Okay, add the page to 'e'. */
> -        if ( unlikely(e->tot_pages++ == 0) )
> +        if ( unlikely(domain_adjust_tot_pages(e, 1) == 1) )
>              get_knownalive_domain(e);
>          page_list_add_tail(page, &e->page_list);
>          page_set_owner(page, e);
> diff --git a/xen/common/memory.c b/xen/common/memory.c
> index 83e2666..9842ea9 100644
> --- a/xen/common/memory.c
> +++ b/xen/common/memory.c
> @@ -454,7 +454,7 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
>                               (j * (1UL << exch.out.extent_order)));
> 
>                  spin_lock(&d->page_alloc_lock);
> -                d->tot_pages -= dec_count;
> +                domain_adjust_tot_pages(d, -dec_count);
>                  drop_dom_ref = (dec_count && !d->tot_pages);
>                  spin_unlock(&d->page_alloc_lock);
> 
> diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
> index 15ebc66..e273bb7 100644
> --- a/xen/common/page_alloc.c
> +++ b/xen/common/page_alloc.c
> @@ -239,6 +239,12 @@ static long midsize_alloc_zone_pages;
> 
>  static DEFINE_SPINLOCK(heap_lock);
> 
> +unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
> +{
> +    ASSERT(spin_is_locked(&d->page_alloc_lock));
> +    return d->tot_pages += pages;
> +}
> +
>  static unsigned long init_node_heap(int node, unsigned long mfn,
>                                      unsigned long nr, bool_t *use_tail)
>  {
> @@ -1291,7 +1297,7 @@ int assign_pages(
>          if ( unlikely(d->tot_pages == 0) )
>              get_knownalive_domain(d);
> 
> -        d->tot_pages += 1 << order;
> +        domain_adjust_tot_pages(d, 1 << order);
>      }
> 
>      for ( i = 0; i < (1 << order); i++ )
> @@ -1375,7 +1381,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order)
>              page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
>          }
> 
> -        d->tot_pages -= 1 << order;
> +        domain_adjust_tot_pages(d, -(1 << order));
>          drop_dom_ref = (d->tot_pages == 0);
> 
>          spin_unlock_recursive(&d->page_alloc_lock);
> diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
> index 64a0cc1..00b1915 100644
> --- a/xen/include/xen/mm.h
> +++ b/xen/include/xen/mm.h
> @@ -48,6 +48,8 @@ void free_xenheap_pages(void *v, unsigned int order);
>  #define alloc_xenheap_page() (alloc_xenheap_pages(0,0))
>  #define free_xenheap_page(v) (free_xenheap_pages(v,0))
> 
> +unsigned long domain_adjust_tot_pages(struct domain *d, long pages);
> +
>  /* Domain suballocator. These functions are *not* interrupt-safe.*/
>  void init_domheap_pages(paddr_t ps, paddr_t pe);
>  struct page_info *alloc_domheap_pages(

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xen: centralize accounting for domain tot_pages
  2012-12-06 17:24 ` Dan Magenheimer
@ 2012-12-06 18:27   ` Keir Fraser
  0 siblings, 0 replies; 4+ messages in thread
From: Keir Fraser @ 2012-12-06 18:27 UTC (permalink / raw)
  To: Dan Magenheimer, Jan Beulich
  Cc: Konrad Rzeszutek Wilk, Zhigang Wang, xen-devel

I will check these two patches in.

 -- Keir

On 06/12/2012 17:24, "Dan Magenheimer" <dan.magenheimer@oracle.com> wrote:

> ping?
> 
>> -----Original Message-----
>> From: Dan Magenheimer
>> Sent: Wednesday, November 28, 2012 2:50 PM
>> To: Keir Fraser; Jan Beulich
>> Cc: xen-devel@lists.xen.org; Konrad Wilk; Zhigang Wang
>> Subject: [PATCH] xen: centralize accounting for domain tot_pages
>> 
>> xen: centralize accounting for domain tot_pages
>> 
>> Provide and use a common function for all adjustments to a
>> domain's tot_pages counter in anticipation of future and/or
>> out-of-tree patches that must adjust related counters
>> atomically.
>> 
>> Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
>> 
>>  arch/x86/mm.c             |    4 ++--
>>  arch/x86/mm/mem_sharing.c |    4 ++--
>>  common/grant_table.c      |    2 +-
>>  common/memory.c           |    2 +-
>>  common/page_alloc.c       |   10 ++++++++--
>>  include/xen/mm.h          |    2 ++
>>  6 files changed, 16 insertions(+), 8 deletions(-)
>> 
>> diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
>> index ab94b02..3887ca6 100644
>> --- a/xen/arch/x86/mm.c
>> +++ b/xen/arch/x86/mm.c
>> @@ -3842,7 +3842,7 @@ int donate_page(
>>      {
>>          if ( d->tot_pages >= d->max_pages )
>>              goto fail;
>> -        d->tot_pages++;
>> +        domain_adjust_tot_pages(d, 1);
>>      }
>> 
>>      page->count_info = PGC_allocated | 1;
>> @@ -3892,7 +3892,7 @@ int steal_page(
>>      } while ( (y = cmpxchg(&page->count_info, x, x | 1)) != x );
>> 
>>      /* Unlink from original owner. */
>> -    if ( !(memflags & MEMF_no_refcount) && !--d->tot_pages )
>> +    if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) )
>>          drop_dom_ref = 1;
>>      page_list_del(page, &d->page_list);
>> 
>> diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
>> index 5103285..e91aac5 100644
>> --- a/xen/arch/x86/mm/mem_sharing.c
>> +++ b/xen/arch/x86/mm/mem_sharing.c
>> @@ -639,7 +639,7 @@ static int page_make_sharable(struct domain *d,
>>      }
>> 
>>      page_set_owner(page, dom_cow);
>> -    d->tot_pages--;
>> +    domain_adjust_tot_pages(d, -1);
>>      drop_dom_ref = (d->tot_pages == 0);
>>      page_list_del(page, &d->page_list);
>>      spin_unlock(&d->page_alloc_lock);
>> @@ -680,7 +680,7 @@ static int page_make_private(struct domain *d, struct
>> page_info *page)
>>      ASSERT(page_get_owner(page) == dom_cow);
>>      page_set_owner(page, d);
>> 
>> -    if ( d->tot_pages++ == 0 )
>> +    if ( domain_adjust_tot_pages(d, 1) == 1 )
>>          get_domain(d);
>>      page_list_add_tail(page, &d->page_list);
>>      spin_unlock(&d->page_alloc_lock);
>> diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
>> index 7912769..ca8d861 100644
>> --- a/xen/common/grant_table.c
>> +++ b/xen/common/grant_table.c
>> @@ -1656,7 +1656,7 @@ gnttab_transfer(
>>          }
>> 
>>          /* Okay, add the page to 'e'. */
>> -        if ( unlikely(e->tot_pages++ == 0) )
>> +        if ( unlikely(domain_adjust_tot_pages(e, 1) == 1) )
>>              get_knownalive_domain(e);
>>          page_list_add_tail(page, &e->page_list);
>>          page_set_owner(page, e);
>> diff --git a/xen/common/memory.c b/xen/common/memory.c
>> index 83e2666..9842ea9 100644
>> --- a/xen/common/memory.c
>> +++ b/xen/common/memory.c
>> @@ -454,7 +454,7 @@ static long
>> memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
>>                               (j * (1UL << exch.out.extent_order)));
>> 
>>                  spin_lock(&d->page_alloc_lock);
>> -                d->tot_pages -= dec_count;
>> +                domain_adjust_tot_pages(d, -dec_count);
>>                  drop_dom_ref = (dec_count && !d->tot_pages);
>>                  spin_unlock(&d->page_alloc_lock);
>> 
>> diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
>> index 15ebc66..e273bb7 100644
>> --- a/xen/common/page_alloc.c
>> +++ b/xen/common/page_alloc.c
>> @@ -239,6 +239,12 @@ static long midsize_alloc_zone_pages;
>> 
>>  static DEFINE_SPINLOCK(heap_lock);
>> 
>> +unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
>> +{
>> +    ASSERT(spin_is_locked(&d->page_alloc_lock));
>> +    return d->tot_pages += pages;
>> +}
>> +
>>  static unsigned long init_node_heap(int node, unsigned long mfn,
>>                                      unsigned long nr, bool_t *use_tail)
>>  {
>> @@ -1291,7 +1297,7 @@ int assign_pages(
>>          if ( unlikely(d->tot_pages == 0) )
>>              get_knownalive_domain(d);
>> 
>> -        d->tot_pages += 1 << order;
>> +        domain_adjust_tot_pages(d, 1 << order);
>>      }
>> 
>>      for ( i = 0; i < (1 << order); i++ )
>> @@ -1375,7 +1381,7 @@ void free_domheap_pages(struct page_info *pg, unsigned
>> int order)
>>              page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
>>          }
>> 
>> -        d->tot_pages -= 1 << order;
>> +        domain_adjust_tot_pages(d, -(1 << order));
>>          drop_dom_ref = (d->tot_pages == 0);
>> 
>>          spin_unlock_recursive(&d->page_alloc_lock);
>> diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
>> index 64a0cc1..00b1915 100644
>> --- a/xen/include/xen/mm.h
>> +++ b/xen/include/xen/mm.h
>> @@ -48,6 +48,8 @@ void free_xenheap_pages(void *v, unsigned int order);
>>  #define alloc_xenheap_page() (alloc_xenheap_pages(0,0))
>>  #define free_xenheap_page(v) (free_xenheap_pages(v,0))
>> 
>> +unsigned long domain_adjust_tot_pages(struct domain *d, long pages);
>> +
>>  /* Domain suballocator. These functions are *not* interrupt-safe.*/
>>  void init_domheap_pages(paddr_t ps, paddr_t pe);
>>  struct page_info *alloc_domheap_pages(

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xen: centralize accounting for domain tot_pages
  2012-11-28 21:50 [PATCH] xen: centralize accounting for domain tot_pages Dan Magenheimer
  2012-12-06 17:24 ` Dan Magenheimer
@ 2012-12-07 15:13 ` Keir Fraser
  1 sibling, 0 replies; 4+ messages in thread
From: Keir Fraser @ 2012-12-07 15:13 UTC (permalink / raw)
  To: Dan Magenheimer, Jan Beulich
  Cc: Konrad Rzeszutek Wilk, Zhigang Wang, xen-devel

On 28/11/2012 21:50, "Dan Magenheimer" <dan.magenheimer@oracle.com> wrote:

> xen: centralize accounting for domain tot_pages
> 
> Provide and use a common function for all adjustments to a
> domain's tot_pages counter in anticipation of future and/or
> out-of-tree patches that must adjust related counters
> atomically.
> 
> Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>

Applied.

 -- Keir

>  arch/x86/mm.c             |    4 ++--
>  arch/x86/mm/mem_sharing.c |    4 ++--
>  common/grant_table.c      |    2 +-
>  common/memory.c           |    2 +-
>  common/page_alloc.c       |   10 ++++++++--
>  include/xen/mm.h          |    2 ++
>  6 files changed, 16 insertions(+), 8 deletions(-)
> 
> diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
> index ab94b02..3887ca6 100644
> --- a/xen/arch/x86/mm.c
> +++ b/xen/arch/x86/mm.c
> @@ -3842,7 +3842,7 @@ int donate_page(
>      {
>          if ( d->tot_pages >= d->max_pages )
>              goto fail;
> -        d->tot_pages++;
> +        domain_adjust_tot_pages(d, 1);
>      }
>  
>      page->count_info = PGC_allocated | 1;
> @@ -3892,7 +3892,7 @@ int steal_page(
>      } while ( (y = cmpxchg(&page->count_info, x, x | 1)) != x );
>  
>      /* Unlink from original owner. */
> -    if ( !(memflags & MEMF_no_refcount) && !--d->tot_pages )
> +    if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) )
>          drop_dom_ref = 1;
>      page_list_del(page, &d->page_list);
>  
> diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c
> index 5103285..e91aac5 100644
> --- a/xen/arch/x86/mm/mem_sharing.c
> +++ b/xen/arch/x86/mm/mem_sharing.c
> @@ -639,7 +639,7 @@ static int page_make_sharable(struct domain *d,
>      }
>  
>      page_set_owner(page, dom_cow);
> -    d->tot_pages--;
> +    domain_adjust_tot_pages(d, -1);
>      drop_dom_ref = (d->tot_pages == 0);
>      page_list_del(page, &d->page_list);
>      spin_unlock(&d->page_alloc_lock);
> @@ -680,7 +680,7 @@ static int page_make_private(struct domain *d, struct
> page_info *page)
>      ASSERT(page_get_owner(page) == dom_cow);
>      page_set_owner(page, d);
>  
> -    if ( d->tot_pages++ == 0 )
> +    if ( domain_adjust_tot_pages(d, 1) == 1 )
>          get_domain(d);
>      page_list_add_tail(page, &d->page_list);
>      spin_unlock(&d->page_alloc_lock);
> diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
> index 7912769..ca8d861 100644
> --- a/xen/common/grant_table.c
> +++ b/xen/common/grant_table.c
> @@ -1656,7 +1656,7 @@ gnttab_transfer(
>          }
>  
>          /* Okay, add the page to 'e'. */
> -        if ( unlikely(e->tot_pages++ == 0) )
> +        if ( unlikely(domain_adjust_tot_pages(e, 1) == 1) )
>              get_knownalive_domain(e);
>          page_list_add_tail(page, &e->page_list);
>          page_set_owner(page, e);
> diff --git a/xen/common/memory.c b/xen/common/memory.c
> index 83e2666..9842ea9 100644
> --- a/xen/common/memory.c
> +++ b/xen/common/memory.c
> @@ -454,7 +454,7 @@ static long
> memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg)
>                               (j * (1UL << exch.out.extent_order)));
>  
>                  spin_lock(&d->page_alloc_lock);
> -                d->tot_pages -= dec_count;
> +                domain_adjust_tot_pages(d, -dec_count);
>                  drop_dom_ref = (dec_count && !d->tot_pages);
>                  spin_unlock(&d->page_alloc_lock);
>  
> diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
> index 15ebc66..e273bb7 100644
> --- a/xen/common/page_alloc.c
> +++ b/xen/common/page_alloc.c
> @@ -239,6 +239,12 @@ static long midsize_alloc_zone_pages;
>  
>  static DEFINE_SPINLOCK(heap_lock);
>  
> +unsigned long domain_adjust_tot_pages(struct domain *d, long pages)
> +{
> +    ASSERT(spin_is_locked(&d->page_alloc_lock));
> +    return d->tot_pages += pages;
> +}
> +
>  static unsigned long init_node_heap(int node, unsigned long mfn,
>                                      unsigned long nr, bool_t *use_tail)
>  {
> @@ -1291,7 +1297,7 @@ int assign_pages(
>          if ( unlikely(d->tot_pages == 0) )
>              get_knownalive_domain(d);
>  
> -        d->tot_pages += 1 << order;
> +        domain_adjust_tot_pages(d, 1 << order);
>      }
>  
>      for ( i = 0; i < (1 << order); i++ )
> @@ -1375,7 +1381,7 @@ void free_domheap_pages(struct page_info *pg, unsigned
> int order)
>              page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
>          }
>  
> -        d->tot_pages -= 1 << order;
> +        domain_adjust_tot_pages(d, -(1 << order));
>          drop_dom_ref = (d->tot_pages == 0);
>  
>          spin_unlock_recursive(&d->page_alloc_lock);
> diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
> index 64a0cc1..00b1915 100644
> --- a/xen/include/xen/mm.h
> +++ b/xen/include/xen/mm.h
> @@ -48,6 +48,8 @@ void free_xenheap_pages(void *v, unsigned int order);
>  #define alloc_xenheap_page() (alloc_xenheap_pages(0,0))
>  #define free_xenheap_page(v) (free_xenheap_pages(v,0))
>  
> +unsigned long domain_adjust_tot_pages(struct domain *d, long pages);
> +
>  /* Domain suballocator. These functions are *not* interrupt-safe.*/
>  void init_domheap_pages(paddr_t ps, paddr_t pe);
>  struct page_info *alloc_domheap_pages(

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-07 15:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-28 21:50 [PATCH] xen: centralize accounting for domain tot_pages Dan Magenheimer
2012-12-06 17:24 ` Dan Magenheimer
2012-12-06 18:27   ` Keir Fraser
2012-12-07 15:13 ` Keir Fraser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).