ia64/xen-unstable

changeset 2687:ba107a7380bc

bitkeeper revision 1.1159.1.256 (4177c0d1UGMpvmL5oNGHJwtGskSRXA)

Merge ssh://srg//auto/groups/xeno/BK/xeno-unstable.bk
into equilibrium.research:/export/scratch/xeno-balloon.bk
author mwilli2@equilibrium.research
date Thu Oct 21 13:59:45 2004 +0000 (2004-10-21)
parents d92269f82bbe c6c0f98bf7d3
children 02bd62ad47a6
files .bk-to-hg .hg-to-bk .rootkeys docs/user.tex linux-2.6.8.1-xen-sparse/drivers/xen/balloon/balloon.c
line diff
     1.1 --- a/.bk-to-hg	Thu Oct 21 13:51:45 2004 +0000
     1.2 +++ b/.bk-to-hg	Thu Oct 21 13:59:45 2004 +0000
     1.3 @@ -1,2 +1,6 @@
     1.4 -#!/bin/sh
     1.5 +#!/bin/sh -x
     1.6 +set -e
     1.7 +test -L linux-2.4.27-xen-sparse/arch/xen/drivers/balloon/balloon.c
     1.8 +rm      linux-2.4.27-xen-sparse/arch/xen/drivers/balloon/balloon.c
     1.9 +(find -depth -type d -print | xargs -r rmdir 2>/dev/null) || true
    1.10  exit 0
     2.1 --- a/.hg-to-bk	Thu Oct 21 13:51:45 2004 +0000
     2.2 +++ b/.hg-to-bk	Thu Oct 21 13:59:45 2004 +0000
     2.3 @@ -1,2 +1,10 @@
     2.4 -#!/bin/sh
     2.5 +#!/bin/sh -x
     2.6 +set -e
     2.7 +mkdir -p linux-2.4.27-xen-sparse
     2.8 +mkdir -p linux-2.4.27-xen-sparse/arch
     2.9 +mkdir -p linux-2.4.27-xen-sparse/arch/xen
    2.10 +mkdir -p linux-2.4.27-xen-sparse/arch/xen/drivers
    2.11 +mkdir -p linux-2.4.27-xen-sparse/arch/xen/drivers/balloon
    2.12 +ln -s ../../../../../linux-2.6.8.1-xen-sparse/drivers/xen/balloon/balloon.c linux-2.4.27-xen-sparse/arch/xen/drivers/balloon/balloon.c
    2.13 +(find -depth -type d -print | xargs -r rmdir 2>/dev/null) || true
    2.14  exit 0
     3.1 --- a/.rootkeys	Thu Oct 21 13:51:45 2004 +0000
     3.2 +++ b/.rootkeys	Thu Oct 21 13:59:45 2004 +0000
     3.3 @@ -50,7 +50,7 @@ 3e5a4e65OV_j_DBtjzt5vej771AJsA linux-2.4
     3.4  40648526SxcA4lGIHB_k7ID8VlRSzw linux-2.4.27-xen-sparse/arch/xen/defconfig-xen0
     3.5  40c73c77QesbL7eIvG-fJGAtVwhGRg linux-2.4.27-xen-sparse/arch/xen/defconfig-xenU
     3.6  3e6377f5xwPfYZkPHPrDbEq1PRN7uQ linux-2.4.27-xen-sparse/arch/xen/drivers/balloon/Makefile
     3.7 -3e6377f8Me8IqtvEhb70XFgOvqQH7A linux-2.4.27-xen-sparse/arch/xen/drivers/balloon/balloon.c
     3.8 +4177c0c3ju-Bo3TJaQHh4fOsy06UgQ linux-2.4.27-xen-sparse/arch/xen/drivers/balloon/balloon.c
     3.9  4083dc16z0jvZEH4PiVDbDRreaNp6w linux-2.4.27-xen-sparse/arch/xen/drivers/blkif/Makefile
    3.10  4083dc16KQus88a4U3uCV6qVCA6_8Q linux-2.4.27-xen-sparse/arch/xen/drivers/blkif/backend/Makefile
    3.11  4075806dI5kfeMD5RV-DA0PYoThx_w linux-2.4.27-xen-sparse/arch/xen/drivers/blkif/frontend/Makefile
     4.1 --- a/docs/user.tex	Thu Oct 21 13:51:45 2004 +0000
     4.2 +++ b/docs/user.tex	Thu Oct 21 13:59:45 2004 +0000
     4.3 @@ -696,6 +696,31 @@ The {\tt xm list} command also supports 
     4.4  {\tt -l} switch is used.  This outputs the fulls details of the
     4.5  running domains in Xend's SXP configuration format.
     4.6  
     4.7 +For example, suppose the system is running the ttylinux domain as
     4.8 +described earlier.  The list command should produce output somewhat
     4.9 +like the following:
    4.10 +\begin{verbatim}
    4.11 +# xm list
    4.12 +Name              Id  Mem(MB)  CPU  State  Time(s)  Console
    4.13 +Domain-0           0      251    0  r----    172.2        
    4.14 +ttylinux           5       63    0  -b---      3.0    9605
    4.15 +\end{verbatim}
    4.16 +
    4.17 +Here we can see the details for the ttylinux domain, as well as for
    4.18 +domain 0 (which of course is always running).  Note that the console
    4.19 +port for the ttylinux domain is 9605.  This can be connected to by TCP
    4.20 +using a terminal program (e.g. {\tt telnet} or, better, {\tt
    4.21 +xencons}).  The simplest way to connect is to use the {\tt xm console}
    4.22 +command, specifying the domain name or ID.  To connect to the console
    4.23 +of the ttylinux domain, we could use:
    4.24 +\begin{verbatim}
    4.25 +# xm console ttylinux
    4.26 +\end{verbatim}
    4.27 +or:
    4.28 +\begin{verbatim}
    4.29 +# xm console 5
    4.30 +\end{verbatim}
    4.31 +
    4.32  \chapter{Other kinds of storage}
    4.33  
    4.34  It is possible to use any Linux block device to store virtual machine
    4.35 @@ -854,6 +879,7 @@ custom variables (for instance, the \pat
    4.36  The available commands are as follows:
    4.37  
    4.38  \begin{description}
    4.39 +\item[balloon] Request a domain to adjust its memory footprint.
    4.40  \item[create] Create a new domain.
    4.41  \item[destroy] Kill a domain immediately.
    4.42  \item[list] List running domains.
    4.43 @@ -976,8 +1002,6 @@ The available commands are as follows:
    4.44  
    4.45  \part{Advanced Topics}
    4.46  
    4.47 -XXX More to add here, including config file format
    4.48 -
    4.49  \chapter{Advanced Network Configuration}
    4.50  
    4.51  For simple systems with a single ethernet interface with a simple
     5.1 --- a/linux-2.6.8.1-xen-sparse/drivers/xen/balloon/balloon.c	Thu Oct 21 13:51:45 2004 +0000
     5.2 +++ b/linux-2.6.8.1-xen-sparse/drivers/xen/balloon/balloon.c	Thu Oct 21 13:59:45 2004 +0000
     5.3 @@ -11,7 +11,12 @@
     5.4  #include <linux/kernel.h>
     5.5  #include <linux/sched.h>
     5.6  #include <linux/errno.h>
     5.7 +
     5.8 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
     5.9  #include <asm-xen/xen_proc.h>
    5.10 +#else
    5.11 +#include <asm/xen_proc.h>
    5.12 +#endif
    5.13  
    5.14  #include <linux/mm.h>
    5.15  #include <linux/mman.h>
    5.16 @@ -21,8 +26,14 @@
    5.17  #include <linux/highmem.h>
    5.18  #include <linux/vmalloc.h>
    5.19  
    5.20 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    5.21  #include <asm-xen/hypervisor.h>
    5.22  #include <asm-xen/ctrl_if.h>
    5.23 +#else
    5.24 +#include <asm/hypervisor.h>
    5.25 +#include <asm/ctrl_if.h>
    5.26 +#endif
    5.27 +
    5.28  #include <asm/pgalloc.h>
    5.29  #include <asm/pgtable.h>
    5.30  #include <asm/uaccess.h>
    5.31 @@ -58,7 +69,11 @@ static inline pte_t *get_ptep(unsigned l
    5.32      pmd = pmd_offset(pgd, addr);
    5.33      if ( pmd_none(*pmd) || pmd_bad(*pmd) ) BUG();
    5.34  
    5.35 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    5.36      ptep = pte_offset_kernel(pmd, addr);
    5.37 +#else
    5.38 +    ptep = pte_offset(pmd, addr);
    5.39 +#endif
    5.40  
    5.41      return ptep;
    5.42  }
    5.43 @@ -258,7 +273,11 @@ static void pagetable_extend (int cur_lo
    5.44      end = (unsigned long)__va(low_pfn*PAGE_SIZE);
    5.45  
    5.46      pgd_base = init_mm.pgd;
    5.47 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    5.48      i = pgd_index(PAGE_OFFSET);
    5.49 +#else
    5.50 +    i = __pgd_offset(PAGE_OFFSET);
    5.51 +#endif
    5.52      pgd = pgd_base + i;
    5.53  
    5.54      for (; i < PTRS_PER_PGD; pgd++, i++) {
    5.55 @@ -281,11 +300,19 @@ static void pagetable_extend (int cur_lo
    5.56                  vaddr = i*PGDIR_SIZE + j*PMD_SIZE + k*PAGE_SIZE;
    5.57                  if (end && (vaddr >= end))
    5.58                      break;
    5.59 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    5.60                  *pte = mk_pte(virt_to_page(vaddr), PAGE_KERNEL);
    5.61 +#else
    5.62 +		*pte = mk_pte_phys(__pa(vaddr), PAGE_KERNEL);
    5.63 +#endif
    5.64              }
    5.65              kpgd = pgd_offset_k((unsigned long)pte_base);
    5.66              kpmd = pmd_offset(kpgd, (unsigned long)pte_base);
    5.67 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    5.68              kpte = pte_offset_kernel(kpmd, (unsigned long)pte_base);
    5.69 +#else
    5.70 +	    kpte = pte_offset(kpmd, (unsigned long)pte_base);
    5.71 +#endif
    5.72              queue_l1_entry_update(kpte,
    5.73                                    (*(unsigned long *)kpte)&~_PAGE_RW);
    5.74              set_pmd(pmd, __pmd(_KERNPG_TABLE + __pa(pte_base)));
    5.75 @@ -453,6 +480,7 @@ static void balloon_ctrlif_rx(ctrl_msg_t
    5.76  }
    5.77  
    5.78  
    5.79 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    5.80  static int balloon_write(struct file *file, const char *buffer,
    5.81                           size_t count, loff_t *offp)
    5.82  {
    5.83 @@ -492,7 +520,6 @@ static int balloon_write(struct file *fi
    5.84      return len;
    5.85  }
    5.86  
    5.87 -
    5.88  static int balloon_read(struct file *filp, char *buffer,
    5.89                          size_t count, loff_t *offp)
    5.90  {
    5.91 @@ -516,6 +543,98 @@ static struct file_operations balloon_fo
    5.92      .read  = balloon_read,
    5.93      .write = balloon_write
    5.94  };
    5.95 +#else
    5.96 +
    5.97 +
    5.98 +static int balloon_write(struct file *file, const char *buffer,
    5.99 +                         u_long count, void *data)
   5.100 +{
   5.101 +    char memstring[64], *endchar;
   5.102 +    int len, i;
   5.103 +    unsigned long target;
   5.104 +    unsigned long long targetbytes;
   5.105 +
   5.106 +    /* Only admin can play with the balloon :) */
   5.107 +    if ( !capable(CAP_SYS_ADMIN) )
   5.108 +        return -EPERM;
   5.109 +
   5.110 +    if ( count > sizeof(memstring) )
   5.111 +        return -EFBIG;
   5.112 +
   5.113 +    len = strnlen_user(buffer, count);
   5.114 +    if ( len == 0 ) return -EBADMSG;
   5.115 +    if ( len == 1 ) return 1; /* input starts with a NUL char */
   5.116 +    if ( strncpy_from_user(memstring, buffer, len) < 0 )
   5.117 +        return -EFAULT;
   5.118 +
   5.119 +    endchar = memstring;
   5.120 +    for ( i = 0; i < len; ++i, ++endchar )
   5.121 +        if ( (memstring[i] < '0') || (memstring[i] > '9') )
   5.122 +            break;
   5.123 +    if ( i == 0 )
   5.124 +        return -EBADMSG;
   5.125 +
   5.126 +    targetbytes = memparse(memstring,&endchar);
   5.127 +    target = targetbytes >> PAGE_SHIFT;
   5.128 +
   5.129 +    if ( target < current_pages )
   5.130 +    {
   5.131 +        int change = inflate_balloon(current_pages-target);
   5.132 +        if ( change <= 0 )
   5.133 +            return change;
   5.134 +
   5.135 +        current_pages -= change;
   5.136 +        printk(KERN_INFO "Relinquish %dMB to xen. Domain now has %luMB\n",
   5.137 +            change>>PAGE_TO_MB_SHIFT, current_pages>>PAGE_TO_MB_SHIFT);
   5.138 +    }
   5.139 +    else if ( target > current_pages )
   5.140 +    {
   5.141 +        int change, reclaim = min(target,most_seen_pages) - current_pages;
   5.142 +
   5.143 +        if ( reclaim )
   5.144 +        {
   5.145 +            change = deflate_balloon( reclaim);
   5.146 +            if ( change <= 0 )
   5.147 +                return change;
   5.148 +            current_pages += change;
   5.149 +            printk(KERN_INFO "Reclaim %dMB from xen. Domain now has %luMB\n",
   5.150 +                change>>PAGE_TO_MB_SHIFT, current_pages>>PAGE_TO_MB_SHIFT);
   5.151 +        }
   5.152 +
   5.153 +        if ( most_seen_pages < target )
   5.154 +        {
   5.155 +            int growth = claim_new_pages(target-most_seen_pages);
   5.156 +            if ( growth <= 0 )
   5.157 +                return growth;
   5.158 +            most_seen_pages += growth;
   5.159 +            current_pages += growth;
   5.160 +            printk(KERN_INFO "Granted %dMB new mem. Dom now has %luMB\n",
   5.161 +                growth>>PAGE_TO_MB_SHIFT, current_pages>>PAGE_TO_MB_SHIFT);
   5.162 +        }
   5.163 +    }
   5.164 +
   5.165 +
   5.166 +    return len;
   5.167 +}
   5.168 +
   5.169 +static int balloon_read(char *page, char **start, off_t off,
   5.170 +			int count, int *eof, void *data)
   5.171 +{
   5.172 +  int len;
   5.173 +  len = sprintf(page,"%lu\n",current_pages<<PAGE_SHIFT);
   5.174 +  
   5.175 +  if (len <= off+count) *eof = 1;
   5.176 +  *start = page + off;
   5.177 +  len -= off;
   5.178 +  if (len>count) len = count;
   5.179 +  if (len<0) len = 0;
   5.180 +  return len;
   5.181 +}
   5.182 +
   5.183 +
   5.184 +
   5.185 +#endif
   5.186 +
   5.187  
   5.188  static int __init balloon_init(void)
   5.189  {
   5.190 @@ -528,9 +647,14 @@ static int __init balloon_init(void)
   5.191          return -1;
   5.192      }
   5.193  
   5.194 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
   5.195      balloon_pde->owner     = THIS_MODULE;
   5.196      balloon_pde->nlink     = 1;
   5.197      balloon_pde->proc_fops = &balloon_fops;
   5.198 +#else
   5.199 +    balloon_pde->write_proc = balloon_write;
   5.200 +    balloon_pde->read_proc  = balloon_read;
   5.201 +#endif
   5.202  
   5.203      (void)ctrl_if_register_receiver(CMSG_MEM_REQUEST, balloon_ctrlif_rx,
   5.204                                      CALLBACK_IN_BLOCKING_CONTEXT);