ia64/xen-unstable

changeset 1643:f8e2d7656250

bitkeeper revision 1.1041.1.2 (40e2d27cSDbzz7ouOaH0-BDTWnwndA)

Balloon driver fixes from David Becker.
author kaf24@scramble.cl.cam.ac.uk
date Wed Jun 30 14:47:24 2004 +0000 (2004-06-30)
parents c58d41206122
children 399e13281a75 9836ac52e77a
files linux-2.4.26-xen-sparse/arch/xen/drivers/balloon/balloon.c
line diff
     1.1 --- a/linux-2.4.26-xen-sparse/arch/xen/drivers/balloon/balloon.c	Wed Jun 30 14:00:44 2004 +0000
     1.2 +++ b/linux-2.4.26-xen-sparse/arch/xen/drivers/balloon/balloon.c	Wed Jun 30 14:47:24 2004 +0000
     1.3 @@ -17,6 +17,7 @@
     1.4  #include <linux/mman.h>
     1.5  #include <linux/smp_lock.h>
     1.6  #include <linux/pagemap.h>
     1.7 +#include <linux/vmalloc.h>
     1.8  
     1.9  #include <asm/hypervisor.h>
    1.10  #include <asm/pgalloc.h>
    1.11 @@ -33,7 +34,7 @@ typedef struct user_balloon_op {
    1.12  } user_balloon_op_t;
    1.13  /* END OF USER DEFINE */
    1.14  
    1.15 -/* Dead entry written into ballon-owned entries in the PMT. */
    1.16 +/* Dead entry written into balloon-owned entries in the PMT. */
    1.17  #define DEAD 0xdeadbeef
    1.18  
    1.19  static struct proc_dir_entry *balloon_pde;
    1.20 @@ -54,7 +55,7 @@ static inline pte_t *get_ptep(unsigned l
    1.21      return ptep;
    1.22  }
    1.23  
    1.24 -/* main function for relinquishing bit of memory */
    1.25 +/* Main function for relinquishing memory. */
    1.26  static unsigned long inflate_balloon(unsigned long num_pages)
    1.27  {
    1.28      unsigned long *parray;
    1.29 @@ -64,14 +65,19 @@ static unsigned long inflate_balloon(uns
    1.30      unsigned long vaddr;
    1.31      unsigned long i, j;
    1.32  
    1.33 -    parray = (unsigned long *)kmalloc(num_pages * sizeof(unsigned long),
    1.34 -                                      GFP_KERNEL);
    1.35 +    parray = (unsigned long *)vmalloc(num_pages * sizeof(unsigned long));
    1.36 +    if ( parray == NULL )
    1.37 +    {
    1.38 +        printk("inflate_balloon: Unable to vmalloc parray\n");
    1.39 +        return 0;
    1.40 +    }
    1.41 +
    1.42      currp = parray;
    1.43  
    1.44      for ( i = 0; i < num_pages; i++ )
    1.45      {
    1.46 -        /* Try to obtain a free page (has to be done with GFP_ATOMIC). */
    1.47 -        vaddr = __get_free_page(GFP_ATOMIC);
    1.48 +        /* NB. Should be GFP_ATOMIC for a less aggressive inflation. */
    1.49 +        vaddr = __get_free_page(GFP_KERNEL);
    1.50  
    1.51          /* If allocation fails then free all reserved pages. */
    1.52          if ( vaddr == 0 )
    1.53 @@ -113,12 +119,13 @@ static unsigned long inflate_balloon(uns
    1.54      ret = num_pages;
    1.55  
    1.56   cleanup:
    1.57 -    kfree(parray);
    1.58 +    vfree(parray);
    1.59  
    1.60      return ret;
    1.61  }
    1.62  
    1.63 -/* install new mem pages obtained by deflate_balloon. function walks 
    1.64 +/*
    1.65 + * Install new mem pages obtained by deflate_balloon. function walks 
    1.66   * phys->machine mapping table looking for DEAD entries and populates
    1.67   * them.
    1.68   */
    1.69 @@ -143,8 +150,7 @@ static unsigned long process_new_pages(u
    1.70          if ( phys_to_machine_mapping[i] == DEAD )
    1.71          {
    1.72              phys_to_machine_mapping[i] = *curr;
    1.73 -            queue_l1_entry_update(
    1.74 -                (pte_t *)((i << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE), i);
    1.75 +            queue_machphys_update(*curr, i);
    1.76              queue_l1_entry_update(
    1.77                  get_ptep((unsigned long)__va(i << PAGE_SHIFT)),
    1.78                  ((*curr) << PAGE_SHIFT) | pgprot_val(PAGE_KERNEL));
    1.79 @@ -155,11 +161,12 @@ static unsigned long process_new_pages(u
    1.80          }
    1.81      }
    1.82  
    1.83 -    /* now, this is tricky (and will also change for machine addrs that 
    1.84 -      * are mapped to not previously released addresses). we free pages
    1.85 -      * that were allocated by get_free_page (the mappings are different 
    1.86 -      * now, of course).
    1.87 -      */
    1.88 +    /*
    1.89 +     * This is tricky (and will also change for machine addrs that 
    1.90 +     * are mapped to not previously released addresses). We free pages
    1.91 +     * that were allocated by get_free_page (the mappings are different 
    1.92 +     * now, of course).
    1.93 +     */
    1.94      curr = parray;
    1.95      for ( i = 0; i < num_installed; i++ )
    1.96      {
    1.97 @@ -181,8 +188,14 @@ unsigned long deflate_balloon(unsigned l
    1.98          return -EAGAIN;
    1.99      }
   1.100  
   1.101 -    parray = (unsigned long *)kmalloc(num_pages * sizeof(unsigned long), 
   1.102 -                                      GFP_KERNEL);
   1.103 +    parray = (unsigned long *)vmalloc(num_pages * sizeof(unsigned long));
   1.104 +    if ( parray == NULL )
   1.105 +    {
   1.106 +        printk("inflate_balloon: Unable to vmalloc parray\n");
   1.107 +        return 0;
   1.108 +    }
   1.109 +
   1.110 +    XEN_flush_page_update_queue();
   1.111  
   1.112      ret = HYPERVISOR_dom_mem_op(MEMOP_increase_reservation, 
   1.113                                  parray, num_pages);
   1.114 @@ -203,7 +216,7 @@ unsigned long deflate_balloon(unsigned l
   1.115      credit -= num_pages;
   1.116  
   1.117   cleanup:
   1.118 -    kfree(parray);
   1.119 +    vfree(parray);
   1.120  
   1.121      return ret;
   1.122  }
   1.123 @@ -239,9 +252,6 @@ static int balloon_write(struct file *fi
   1.124      return sizeof(bop);
   1.125  }
   1.126  
   1.127 -/*
   1.128 - * main balloon driver initialization function.
   1.129 - */
   1.130  static int __init init_module(void)
   1.131  {
   1.132      printk(KERN_ALERT "Starting Xen Balloon driver\n");
   1.133 @@ -270,5 +280,3 @@ static void __exit cleanup_module(void)
   1.134  
   1.135  module_init(init_module);
   1.136  module_exit(cleanup_module);
   1.137 -
   1.138 -