From: tgh Subject: Re: question about running vm change its mem maxsize Date: Tue, 20 Mar 2007 12:12:53 +0800 Message-ID: <45FF5F45.2090805@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> <1174314969.4337.76.camel@lapbode42.lrr.in.tum.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <1174314969.4337.76.camel@lapbode42.lrr.in.tum.de> 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 , xen-devel 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 >>> =20 >>>> hi >>>> I read the code of xc_linux_build() and xc_domain_setmaxmem(),and = I am=20 >>>> confused about how does "xm mem-max" change the max size of mem = for =20 >>>> a running VM >>>> >>>> In xc_domain_setmaxmem() ,the XEN_DOMCTL_max_mem has been called ,a= nd =20 >>>> just does "d->max_pages =3D new_max;" >>>> =20 >>>> =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 >>> =20 >> I see >> =20 >>>> while in the xc_linux_build(), before the vm boots up,the maxsize p= fn=20 >>>> is alloced in an array with fixsize, page_array =3D malloc(nr_pages = *=20 >>>> sizeof(unsigned long)) >>>> =20 >>>> =20 >>> i suppose you misunderstood what that call really does. it's not >>> changing the maximum vm size, but allocating the initial number of pa= ges >>> required to load the guest operating system image into. that's typica= lly >>> much less than d->max_pages. >>> >>> =20 >>> =20 >> "page_array =3D malloc(nr_pages *sizeof(unsigned long))" in xc_linux_b= uild() is not to allocate the physical memory to the VM,then which code o= r 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.=20 > > 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(= ) and domain builder acts as bootloader ,and then guestos-linux will =20 setup and control its own memory ,is it right? of course,any memory-map=20 will incur xen to related map or so. but in the rational linux, it will know how many physical memory it owns=20 and linux know that all the physical memory it owns is there In the xen ,guest-linux know how many physical memory it owns but=20 doesnot know that all the physical memory it owns is there,for some of=20 them is not to allocate,is it right? that is during guest-linux=20 running,it will request some memory which it will get ,for the=20 guest ,its memory (both its physical memory and its virtual memory)is=20 dynamical allocated,while raditional linux has its physical memory when=20 it boot up ,while gets virtual memory dynamically,is it right? 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.=20 > > 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).=20 > 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 > > =20 >>>> then how does a running vm changes its mem maxsize ,especially for= =20 >>>> expanding its mem maxsize? >>>> =20 >>>> =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 >>> =20 >> I see it is domain0 who has the control interface to set and change th= e=20 >> 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 ,espacially= =20 >> 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