debuggers.hg

changeset 20641:3122518646d3

Track free pages live rather than count pages in all nodes/zones

Trying to fix a livelock condition in tmem that occurs
only when the system is totally out of memory requires
the ability to easily determine if all zones in all
nodes are empty, and this must be checked at a fairly
high frequency. So to avoid walking all the zones in
all the nodes each time, I'd like a fast way to determine
if "free_pages" is zero. This patch tracks the sum
of the free pages in all nodes/zones. Since I think
the value is modified only when heap_lock is held,
it need not be atomic.

I don't know this for sure, but suspect this will be
useful in other future memory utilization code, e.g.
page sharing.

This has had limited testing, though I did drive free
memory down to zero and up and down a few times with
debug on and no asserts were triggered.

Signed-off-by: Dan Magenheimer <dan.magenheimer@oracle.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Dec 08 07:55:21 2009 +0000 (2009-12-08)
parents 66ff18dd3858
children 2d92ad3ef517
files xen/common/page_alloc.c xen/include/xen/mm.h
line diff
     1.1 --- a/xen/common/page_alloc.c	Tue Dec 08 07:51:30 2009 +0000
     1.2 +++ b/xen/common/page_alloc.c	Tue Dec 08 07:55:21 2009 +0000
     1.3 @@ -222,6 +222,7 @@ static heap_by_zone_and_order_t *_heap[M
     1.4  #define heap(node, zone, order) ((*_heap[node])[zone][order])
     1.5  
     1.6  static unsigned long *avail[MAX_NUMNODES];
     1.7 +static long total_avail_pages;
     1.8  
     1.9  static DEFINE_SPINLOCK(heap_lock);
    1.10  
    1.11 @@ -350,6 +351,8 @@ static struct page_info *alloc_heap_page
    1.12  
    1.13      ASSERT(avail[node][zone] >= request);
    1.14      avail[node][zone] -= request;
    1.15 +    total_avail_pages -= request;
    1.16 +    ASSERT(total_avail_pages >= 0);
    1.17  
    1.18      spin_unlock(&heap_lock);
    1.19  
    1.20 @@ -445,6 +448,8 @@ static int reserve_offlined_page(struct 
    1.21              continue;
    1.22  
    1.23          avail[node][zone]--;
    1.24 +        total_avail_pages--;
    1.25 +        ASSERT(total_avail_pages >= 0);
    1.26  
    1.27          page_list_add_tail(cur_head,
    1.28                             test_bit(_PGC_broken, &cur_head->count_info) ?
    1.29 @@ -497,6 +502,7 @@ static void free_heap_pages(
    1.30      spin_lock(&heap_lock);
    1.31  
    1.32      avail[node][zone] += 1 << order;
    1.33 +    total_avail_pages += 1 << order;
    1.34  
    1.35      /* Merge chunks as far as possible. */
    1.36      while ( order < MAX_ORDER )
    1.37 @@ -834,6 +840,11 @@ static unsigned long avail_heap_pages(
    1.38      return free_pages;
    1.39  }
    1.40  
    1.41 +unsigned long total_free_pages(void)
    1.42 +{
    1.43 +    return total_avail_pages;
    1.44 +}
    1.45 +
    1.46  void __init end_boot_allocator(void)
    1.47  {
    1.48      unsigned int i;
     2.1 --- a/xen/include/xen/mm.h	Tue Dec 08 07:51:30 2009 +0000
     2.2 +++ b/xen/include/xen/mm.h	Tue Dec 08 07:55:21 2009 +0000
     2.3 @@ -62,6 +62,7 @@ unsigned long avail_domheap_pages(void);
     2.4  unsigned int online_page(unsigned long mfn, uint32_t *status);
     2.5  int offline_page(unsigned long mfn, int broken, uint32_t *status);
     2.6  int query_page_offline(unsigned long mfn, uint32_t *status);
     2.7 +unsigned long total_free_pages(void);
     2.8  
     2.9  void scrub_heap_pages(void);
    2.10