ia64/xen-unstable

changeset 2779:0f8ac790fa96

bitkeeper revision 1.1159.1.308 (41827d63Yz9YEpPsVNVsC73Y2b_CzA)

Cunning trick suggested by Keir reduces the amount of conditional
compilation for different Linux versions.
author mwilli2@equilibrium.research
date Fri Oct 29 17:26:59 2004 +0000 (2004-10-29)
parents 611b907c8330
children 9b7a35c0e304
files linux-2.6.9-xen-sparse/drivers/xen/balloon/balloon.c
line diff
     1.1 --- a/linux-2.6.9-xen-sparse/drivers/xen/balloon/balloon.c	Fri Oct 29 11:15:56 2004 +0000
     1.2 +++ b/linux-2.6.9-xen-sparse/drivers/xen/balloon/balloon.c	Fri Oct 29 17:26:59 2004 +0000
     1.3 @@ -77,51 +77,40 @@ unsigned long credit;
     1.4  static unsigned long current_pages, most_seen_pages;
     1.5  
     1.6  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
     1.7 -
     1.8 -/* Head of the list of ballooned pages */
     1.9 -struct page *ball_pg_hd = NULL;
    1.10 -
    1.11 -void add_ballooned_page(unsigned long pfn)
    1.12 -{
    1.13 -    struct page *p = mem_map + pfn;
    1.14 -    
    1.15 -    p->private = (unsigned long)ball_pg_hd;
    1.16 -    ball_pg_hd = p;
    1.17 -}
    1.18 +/* Use the private and mapping fields of struct page as a list. */
    1.19 +#define PAGE_TO_LIST(p) ( (struct list_head *)&p->private )
    1.20 +#define LIST_TO_PAGE(l) ( list_entry( ((unsigned long *)l),   \
    1.21 +				      struct page, private ) )
    1.22 +#define UNLIST_PAGE(p)  do { list_del(PAGE_TO_LIST(p));       \
    1.23 +                             p->mapping = NULL;               \
    1.24 +                             p->private = 0; } while(0)
    1.25 +#else
    1.26 +/* There's a dedicated list field in struct page we can use.    */
    1.27 +#define PAGE_TO_LIST(p) ( &p->list )
    1.28 +#define LIST_TO_PAGE(l) ( list_entry(l, struct page, list) )
    1.29 +#define UNLIST_PAGE(p)  ( list_del(&p->list) )
    1.30 +#endif
    1.31  
    1.32 -struct page *rem_ballooned_page(void)
    1.33 -{
    1.34 -    if ( ball_pg_hd != NULL )
    1.35 -    {
    1.36 -        struct page *ret = ball_pg_hd;
    1.37 -        ball_pg_hd = (struct page *)ball_pg_hd->private;
    1.38 -        return ret;
    1.39 -    }
    1.40 -    else
    1.41 -        return NULL;
    1.42 -}   
    1.43 -
    1.44 -#else
    1.45  /* List of ballooned pages, threaded through the mem_map array. */
    1.46  LIST_HEAD(ballooned_pages);
    1.47  
    1.48 +/** add_ballooned_page - remember we've ballooned a pfn */
    1.49  void add_ballooned_page(unsigned long pfn)
    1.50  {
    1.51      struct page *p = mem_map + pfn;
    1.52  
    1.53 -    list_add(&p->list, &ballooned_pages);
    1.54 +    list_add(PAGE_TO_LIST(p), &ballooned_pages);
    1.55  }
    1.56  
    1.57 +/* rem_ballooned_page - recall a ballooned page and remove from list. */
    1.58  struct page *rem_ballooned_page(void)
    1.59  {
    1.60      if(!list_empty(&ballooned_pages))
    1.61      {
    1.62 -        struct list_head *next;
    1.63          struct page *ret;
    1.64  
    1.65 -        next = ballooned_pages.next;
    1.66 -        ret = list_entry(next, struct page, list);
    1.67 -        list_del(next);
    1.68 +        ret = LIST_TO_PAGE(ballooned_pages.next);
    1.69 +	UNLIST_PAGE(ret);
    1.70  
    1.71          return ret;
    1.72      }
    1.73 @@ -129,8 +118,6 @@ struct page *rem_ballooned_page(void)
    1.74          return NULL;
    1.75  }
    1.76  
    1.77 -#endif
    1.78 -
    1.79  static inline pte_t *get_ptep(unsigned long addr)
    1.80  {
    1.81      pgd_t *pgd; pmd_t *pmd; pte_t *ptep;