From: tgh Subject: Re: question about running vm change its mem maxsize Date: Tue, 20 Mar 2007 14:44:09 +0800 Message-ID: <45FF82B9.2020600@ncic.ac.cn> References: <31436f4a0703171215m3f18a72an583b5633b6a8b66a@mail.gmail.com> <45FDE561.5060504@ncic.ac.cn> <1174298445.4337.26.camel@lapbode42.lrr.in.tum.de> <45FE8052.7080805@ncic.ac.cn> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <45FE8052.7080805@ncic.ac.cn> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Daniel Stodden Cc: Xen Developers List-Id: xen-devel@lists.xenproject.org Thank you for your reply Daniel Stodden =E5=86=99=E9=81=93: > On Mon, 2007-03-19 at 20:21 +0800, tgh wrote: > =20 >> Thank you for your reply >> >> Daniel Stodden =E5=86=99=E9=81=93: >> =20 >>> On Mon, 2007-03-19 at 09:20 +0800, tgh wrote: >>> =20 >>>> hi >>>> I read the code of xc_linux_build() and xc_domain_setmaxmem(),and=20 >>>> I am confused about how does "xm mem-max" change the max size of=20 >>>> mem for a running VM >>>> >>>> In xc_domain_setmaxmem() ,the XEN_DOMCTL_max_mem has been called=20 >>>> ,and just does "d->max_pages =3D new_max;" >>>> =20 >>> that variable determines the maximum size. the code verifies that the >>> new size won't be below the previous one, and therefore just needs to >>> readjust it. >>> >>> it doesn't actually have to allocate memory. this is done on demand, >>> i.e. as soon as the domain references a new page frame within it's >>> virtual machine address space. >>> >>> =20 >> I see >> =20 >>>> while in the xc_linux_build(), before the vm boots up,the maxsize=20 >>>> pfn is alloced in an array with fixsize, page_array =3D=20 >>>> malloc(nr_pages * sizeof(unsigned long)) >>>> =20 >>> i suppose you misunderstood what that call really does. it's not >>> changing the maximum vm size, but allocating the initial number of=20 >>> pages >>> required to load the guest operating system image into. that's=20 >>> typically >>> much less than d->max_pages. >>> >>> =20 >> "page_array =3D malloc(nr_pages *sizeof(unsigned long))" in=20 >> xc_linux_build() is not to allocate the physical memory to the=20 >> VM,then which code or function allocate the phy-mem to the VM? >> >> I am confused about it >> =20 > > is see, i'm not sure anymore whether i understand your problem > correctly. > so lets try going through that more slowly. > > not the malloc() above, but the call to > xc_domain_memory_populate_physmap() allocates memory. domain memory is > organized in pages. those pages are allocated upon demand by the > software using it. > =20 I search the code ,it seems that set_vram_mapping()->set_mm_mapping()->xc_domain_memory_populate_physmap()= =20 ,are there any other call path in the xen code? I only find this one in the paravirt case,VM does not manage the whole physical memory it=20 could use (say 512M for maxsize,or something)when vm boot up,instead,xen=20 dynamically allocate some memory(both virtual and physical )to VM,when=20 VM requests, while raditional linux manage its physical memory using=20 mem_map or so when it boot up ,while allocates virtual memory=20 dynamically,is it right? I am confused about it could you help me thanks in advance > lets say you build a domain of size 256MB. that domain initially won't > need the whole 256MB to run. what it initially needs is memory where th= e > kernel is loaded. lets say that's 4MB or something. as soon as the gues= t > kernel is running, it will allocate any additionally needed memory by > itself and some magic mentioned in my previous replay. > it won't get more than those 256MB, unless root on dom0 is willing to > say so. it will learn about it, in a similar fashion to which a native > operating system gathers information about installed hardware from the > bios. that's the max_pages variable above. > > before, domain0 will perform as a the boot loader, responsible for > loading the kernel image into main memory of the virtual machine, setup > a virtual cpu to aim at the kernels entry point, prepare virtual I/O > devices and whatever else it sees fit, and then fire up the domain. > > in order to install the kernel, some of the guest vm memory must be > available. max_pages just says how much it could be, presently it's > still zero. the domain builder needs in our case the lets-say-4MB > mentioned above, at specific positions in the guest memory map, to copy > the kernel image into it (e.g. linux is typically mapped at adresses > above 1M). that is what xc_domain_memory_populate_physmap() is doing. > > while xen allocates the memory, it won't load the kernel image. that's > way better done in user space. for that purpose, and about a ton of > others, dom0 is privileged to mmap() the page frames of arbitrary other > domains. if you follow the code, you will see calls to > xc_map_foreign_range(). e.g. xc_load_elf.c:loadelfimage(). > > but, in order to map these pages, the domain builder needs to know whic= h > pages xen actually allocated. pages are numbered by the upper bits of > their location in physical memory. physical memory (as opposed to > per-domain 'pseudo-physical' memory, is identified by machine frame > numbers (mfn). the page_table argument to populate_physmap is requestin= g > exactly these. > > one mfn is an unsigned long. for a domain with size nr_pages, you need > nr_pages * sizeof(unsigned long) bytes to hold the mfn table for the > domain. > =20 >>>> then how does a running vm changes its mem maxsize ,especially=20 >>>> for expanding its mem maxsize? >>>> =20 >>> for an unprivileged guest os, there is no such call. similar in the w= ay >>> your desktop machine (hopefully) won't call dell ordering more RAM >>> without your knowledge. >>> >>> changing machine size is an administrative operation. it is defined >>> during VM creating, and potential subject to refinement by the >>> administrator on dom0. >>> =20 >> I see it is domain0 who has the control interface to set and change=20 >> the max-size of the VM memory >> >> when VM is running, we can "xm mem-set " or "xm mem-max "in the=20 >> domain0'console to change the vm memory >> >> I have used it , and want to know what happen in the xen =20 >> ,espacially in a paravirtVM >> =20 > > when max_pages is set, there's not much happening initially, as said > before. the domain is allowed to allocate more memory. that memory > remains unallocated up to the point where the domain actually allocates > it. > > i'm not entirely sure about how this is currently mapped in xen to > physical memory. i believe max_pages may be potentially different to th= e > amount of phyiscal memory announced to the domain. alternatives might > include memory hotplugging apis in the guest operating system. maybe > someone else can comment. > > regards, > daniel > > > =20