Skip to contentSkip to conversation

Frontend/Backend model

DISCUSSION David Shwatrz 4 participants 12 messages Mar 17, 2007 – Mar 21, 2007 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hello,
A question about frontend/backend model:

I had looked in the code of netfront (and blockfront) and I wonder : do these modules operate in soft_irq or interrupt context? For exmaple, methods like network_start_xmit() (for trasmitting frames in nerfront ) or network_tx_buf_gc() (for receiving frames in netfront) ? I see that the netif_int() calls network_tx_buf_gc(). But is domU network_tx_buf_gc() method called from a regular interrupt context (like in the ususal case, when we deal with ordinary
drivers) ? Am I permitted to call a method that may sleep in these methods ? As I understood, interrrupt handling in Xen is different, because interrupts are
handled by domain 0, and as I understood there are events channels and pending
events, and the interrupts are in fact handled first by domain 0, which activates
some event channel messages.
I want to verify this point for better understanding the frontend/backend model.

Regards,
*D **Shwatrz*

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 1 line · David Shwatrz

Hello,

hi.

Quoted 13 lines

A question about frontend/backend model:

I had looked in the code of netfront (and blockfront) and I wonder : do these modules operate in soft_irq or interrupt context? For exmaple, methods like network_start_xmit() (for trasmitting frames
in nerfront ) or network_tx_buf_gc() (for receiving frames in netfront) ?
I see that the netif_int() calls network_tx_buf_gc(). But is domU network_tx_buf_gc() method called from a regular interrupt context (like in the ususal case, when we deal with ordinary drivers) ? Am I permitted to call a method that may sleep in these methods ?

no.

frontend drivers are regular netdevs and therefore have to adhere to the context the protocol stack calls the methods. xen linux doesn't change much about that.

Quoted 7 lines

As I understood, interrrupt handling in Xen is different, because interrupts are
handled by domain 0, and as I understood there are events channels and pending
events, and the interrupts are in fact handled first by domain 0, which activates
some event channel messages.

while hardware interrupts are caught by xen and dom0, there are still interrupts involved here, though 'virtual' ones. indeed, these are managed by event channels, but the resulting execution model in the guest doesn't differ much a hardware irq. xen builds a custom interrupt frame on the guest kernel stack (grep the xen code for 'trap_bounce') and transfers guest control to the registered handler.

yes, the virtual cpu where this is happening becomes a preemptible resource. but that's fully transparent for the guest system and doesn't change much about the kernel works. interrupt handlers won't turn into threads. cannot.

Quoted 2 lines

I want to verify this point for better understanding the frontend/backend model.

hope that helped.

regards,
daniel

Signature · 5 lines
Daniel Stodden
LRR     -      Lehrstuhl für Rechnertechnik und Rechnerorganisation
Institut für Informatik der TU München             D-85748 Garching
http://www.lrr.in.tum.de/~stodden         mailto:[email protected]
PGP Fingerprint: F5A4 1575 4C56 E26A 0B33  3D80 457E 82AE B0D8 735B
#2 lore raw

question about running vm change its mem maxsize

In reply to David Shwatrz

hi
I read the code of xc_linux_build() and xc_domain_setmaxmem(),and I am confused about how does "xm mem-max" change the max size of mem for a running VM

In xc_domain_setmaxmem() ,the XEN_DOMCTL_max_mem has been called ,and just does "d->max_pages = new_max;"
while in the xc_linux_build(), before the vm boots up,the maxsize pfn is alloced in an array with fixsize, page_array = malloc(nr_pages * sizeof(unsigned long)) then how does a running vm changes its mem maxsize ,especially for expanding its mem maxsize?

I am confused about it

could you help me
Thanks in advance

#3 lore raw

Re: question about running vm change its mem maxsize

Quoted 7 lines · tgh

hi
I read the code of xc_linux_build() and xc_domain_setmaxmem(),and I am
confused about how does "xm mem-max" change the max size of mem for a running VM

In xc_domain_setmaxmem() ,the XEN_DOMCTL_max_mem has been called ,and
just does "d->max_pages = new_max;"

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.

Quoted 3 lines

while in the xc_linux_build(), before the vm boots up,the maxsize pfn is alloced in an array with fixsize, page_array = malloc(nr_pages * sizeof(unsigned long))

i suppose you misunderstood what that call really does. it's not changing the maximum vm size, but allocating the initial number of pages required to load the guest operating system image into. that's typically much less than d->max_pages.

Quoted 2 lines

then how does a running vm changes its mem maxsize ,especially for expanding its mem maxsize?

for an unprivileged guest os, there is no such call. similar in the way 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.

what the guest system does in order to get 'more memory' is, from the guest system point of view, more or less equivalent to what the guest operating system on a physical host would do: manage physical memory, find a free page frame, map it in one or more page tables, then start using it. xen detects that process of mapping this page frame, and performs the allocation. but, how this is done in detail largely depends on the type of VM (hardware-based, paravirtual, etc), and even then there are different variants.

hth.

regards,
daniel

Signature · 5 lines
Daniel Stodden
LRR     -      Lehrstuhl für Rechnertechnik und Rechnerorganisation
Institut für Informatik der TU München             D-85748 Garching
http://www.lrr.in.tum.de/~stodden         mailto:[email protected]
PGP Fingerprint: F5A4 1575 4C56 E26A 0B33  3D80 457E 82AE B0D8 735B
#4 lore raw

Re: question about running vm change its mem maxsize

Thank you for your reply

Quoted 10 lines · Daniel Stodden
Quoted 7 lines · tgh

hi
I read the code of xc_linux_build() and xc_domain_setmaxmem(),and I am
confused about how does "xm mem-max" change the max size of mem for a running VM

In xc_domain_setmaxmem() ,the XEN_DOMCTL_max_mem has been called ,and
just does "d->max_pages = new_max;"

Quoted 9 lines

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.

I see

Quoted 9 lines
Quoted 2 lines

while in the xc_linux_build(), before the vm boots up,the maxsize pfn is alloced in an array with fixsize, page_array = malloc(nr_pages * sizeof(unsigned long))

i suppose you misunderstood what that call really does. it's not changing the maximum vm size, but allocating the initial number of pages required to load the guest operating system image into. that's typically much less than d->max_pages.

"page_array = malloc(nr_pages *sizeof(unsigned long))" in xc_linux_build() is not to allocate the physical memory to the VM,then which code or function allocate the phy-mem to the VM?

I am confused about it

Quoted 11 lines
Quoted 2 lines

then how does a running vm changes its mem maxsize ,especially for expanding its mem maxsize?

for an unprivileged guest os, there is no such call. similar in the way 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.

I see it is domain0 who has the control interface to set and change the max-size of the VM memory

when VM is running, we can "xm mem-set " or "xm mem-max "in the domain0'console to change the vm memory

I have used it , and want to know what happen in the xen ,espacially in a paravirtVM

could you help me
Thanks in advance

Quoted 15 lines

what the guest system does in order to get 'more memory' is, from the guest system point of view, more or less equivalent to what the guest operating system on a physical host would do: manage physical memory, find a free page frame, map it in one or more page tables, then start using it. xen detects that process of mapping this page frame, and performs the allocation. but, how this is done in detail largely depends on the type of VM (hardware-based, paravirtual, etc), and even then there are different variants.

hth.

regards,
daniel

#5 lore raw

Re: question about running vm change its mem maxsize

Quoted 36 lines · tgh

Thank you for your reply

Quoted 11 lines · Daniel Stodden
Quoted 8 lines · tgh

hi
I read the code of xc_linux_build() and xc_domain_setmaxmem(),and I am
confused about how does "xm mem-max" change the max size of mem for a running VM

In xc_domain_setmaxmem() ,the XEN_DOMCTL_max_mem has been called ,and
just does "d->max_pages = new_max;"

Quoted 9 lines

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.

I see

Quoted 11 lines
Quoted 4 lines

while in the xc_linux_build(), before the vm boots up,the maxsize pfn is alloced in an array with fixsize, page_array = malloc(nr_pages * sizeof(unsigned long))

i suppose you misunderstood what that call really does. it's not changing the maximum vm size, but allocating the initial number of pages required to load the guest operating system image into. that's typically much less than d->max_pages.

Quoted 3 lines

"page_array = malloc(nr_pages *sizeof(unsigned long))" in xc_linux_build() is not to allocate the physical memory to the VM,then which code or function allocate the phy-mem to the VM?

I am confused about it

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.

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 the kernel is loaded. lets say that's 4MB or something. as soon as the guest 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 which 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 requesting 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.

Quoted 12 lines
Quoted 4 lines
Quoted 3 lines

then how does a running vm changes its mem maxsize ,especially for expanding its mem maxsize?

Quoted 8 lines

for an unprivileged guest os, there is no such call. similar in the way 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.

Quoted 8 lines

I see it is domain0 who has the control interface to set and change the max-size of the VM memory

when VM is running, we can "xm mem-set " or "xm mem-max "in the
domain0'console to change the vm memory

I have used it , and want to know what happen in the xen ,espacially
in a paravirtVM

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 the 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

Signature · 5 lines
Daniel Stodden
LRR     -      Lehrstuhl für Rechnertechnik und Rechnerorganisation
Institut für Informatik der TU München             D-85748 Garching
http://www.lrr.in.tum.de/~stodden         mailto:[email protected]
PGP Fingerprint: F5A4 1575 4C56 E26A 0B33  3D80 457E 82AE B0D8 735B

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: question about running vm change its mem maxsize

Thank you for your reply

Quoted 47 lines · Daniel Stodden
Quoted 37 lines · tgh

Thank you for your reply

Quoted 11 lines · Daniel Stodden
Quoted 8 lines · tgh

hi
I read the code of xc_linux_build() and xc_domain_setmaxmem(),and I am
confused about how does "xm mem-max" change the max size of mem for a running VM

In xc_domain_setmaxmem() ,the XEN_DOMCTL_max_mem has been called ,and
just does "d->max_pages = new_max;"

Quoted 10 lines

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.

I see

Quoted 10 lines
Quoted 3 lines

while in the xc_linux_build(), before the vm boots up,the maxsize pfn is alloced in an array with fixsize, page_array = malloc(nr_pages * sizeof(unsigned long))

i suppose you misunderstood what that call really does. it's not changing the maximum vm size, but allocating the initial number of pages required to load the guest operating system image into. that's typically much less than d->max_pages.

Quoted 4 lines

"page_array = malloc(nr_pages *sizeof(unsigned long))" in xc_linux_build() is not to allocate the physical memory to the VM,then which code or function allocate the phy-mem to the VM?

I am confused about it

is see, i'm not sure anymore whether i understand your problem correctly.

Quoted 7 lines

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.

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 setup and control its own memory ,is it right? of course,any memory-map will incur xen to related map or so.
but in the rational linux, it will know how many physical memory it owns 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 doesnot know that all the physical memory it owns is there,for some of them is not to allocate,is it right? that is during guest-linux running,it will request some memory which it will get ,for the guest ,its memory (both its physical memory and its virtual memory)is dynamical allocated,while raditional linux has its physical memory when it boot up ,while gets virtual memory dynamically,is it right?

could you help me
thanks in advance

Quoted 76 lines

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 the kernel is loaded. lets say that's 4MB or something. as soon as the guest 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 which 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 requesting 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.

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines

then how does a running vm changes its mem maxsize ,especially for expanding its mem maxsize?

for an unprivileged guest os, there is no such call. similar in the way 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.

Quoted 6 lines

I see it is domain0 who has the control interface to set and change the max-size of the VM memory

when VM is running, we can "xm mem-set " or "xm mem-max "in the domain0'console to change the vm memory

I have used it , and want to know what happen in the xen ,espacially in a paravirtVM

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 the 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

#8 lore raw

Re: question about running vm change its mem maxsize

Quoted 65 lines · tgh

Thank you for your reply

Quoted 50 lines · Daniel Stodden
Quoted 40 lines · tgh

Thank you for your reply

Quoted 12 lines · Daniel Stodden
Quoted 9 lines · tgh

hi
I read the code of xc_linux_build() and xc_domain_setmaxmem(),and I am
confused about how does "xm mem-max" change the max size of mem for a running VM

In xc_domain_setmaxmem() ,the XEN_DOMCTL_max_mem has been called ,and
just does "d->max_pages = new_max;"

Quoted 10 lines

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.

I see

Quoted 5 lines
Quoted 5 lines

while in the xc_linux_build(), before the vm boots up,the maxsize pfn is alloced in an array with fixsize, page_array = malloc(nr_pages * sizeof(unsigned long))

Quoted 7 lines

i suppose you misunderstood what that call really does. it's not changing the maximum vm size, but allocating the initial number of pages required to load the guest operating system image into. that's typically much less than d->max_pages.

Quoted 4 lines

"page_array = malloc(nr_pages *sizeof(unsigned long))" in xc_linux_build() is not to allocate the physical memory to the VM,then which code or function allocate the phy-mem to the VM?

I am confused about it

is see, i'm not sure anymore whether i understand your problem correctly.

Quoted 7 lines

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.

I search the code ,it seems that
set_vram_mapping()->set_mm_mapping()->xc_domain_memory_populate_physmap()

Quoted 5 lines

and domain builder acts as bootloader ,and then guestos-linux will setup and control its own memory ,is it right? of course,any memory-map will incur xen to related map or so.
but in the rational linux, it will know how many physical memory it owns and linux know that all the physical memory it owns is there

naturally.

Quoted 3 lines

In the xen ,guest-linux know how many physical memory it owns but doesnot know that all the physical memory it owns is there,for some of them is not to allocate,is it right?

this is correct -- for a paravirtual guest. for a hvm guest, it needs to work a little different, of course.

Quoted 5 lines

that is during guest-linux
running,it will request some memory which it will get ,for the guest ,its memory (both its physical memory and its virtual memory)is dynamical allocated,while raditional linux has its physical memory when it boot up ,while gets virtual memory dynamically,is it right?

yes. see the xen interface manual on this topic, namely the chapters on memory management and the hypercall reference for page table and physical memory management. not sure if this gets entirely clear, though, i sometimes tend to get confused myself. especially guest side vm tends to be complex, but that's quite natural.

Quoted 2 lines

could you help me
thanks in advance

hth,
dns

Signature · 5 lines
Daniel Stodden
LRR     -      Lehrstuhl für Rechnertechnik und Rechnerorganisation
Institut für Informatik der TU München             D-85748 Garching
http://www.lrr.in.tum.de/~stodden         mailto:[email protected]
PGP Fingerprint: F5A4 1575 4C56 E26A 0B33  3D80 457E 82AE B0D8 735B
#9 lore raw

Re: question about running vm change its mem maxsize

Thank you for your reply

Quoted 5 lines
Quoted 4 lines

and domain builder acts as bootloader ,and then guestos-linux will setup and control its own memory ,is it right? of course,any memory-map will incur xen to related map or so. but in the rational linux, it will know how many physical memory it owns and linux know that all the physical memory it owns is there

Quoted 10 lines

naturally.

Quoted 2 lines

In the xen ,guest-linux know how many physical memory it owns but doesnot know that all the physical memory it owns is there,for some of them is not to allocate,is it right?

this is correct -- for a paravirtual guest. for a hvm guest, it needs to work a little different, of course.

how does hvm guest deal with its physical memory?
when it boots up, is its physical memory allocated and its virtual memory not all allocated or what does its do?

could you help me
Thanks in advance

Quoted 19 lines
Quoted 3 lines

that is during guest-linux
running,it will request some memory which it will get ,for the guest ,its memory (both its physical memory and its virtual memory)is dynamical allocated,while raditional linux has its physical memory when it boot up ,while gets virtual memory dynamically,is it right?

yes. see the xen interface manual on this topic, namely the chapters on memory management and the hypercall reference for page table and physical memory management. not sure if this gets entirely clear, though, i sometimes tend to get confused myself. especially guest side vm tends to be complex, but that's quite natural.

Quoted 3 lines

could you help me
thanks in advance

hth,
dns

#10 lore raw

Re: question about running vm change its mem maxsize

Quoted 4 lines

how does hvm guest deal with its physical memory?
when it boots up, is its physical memory allocated and its virtual memory not all allocated or what does its do?

An HVM guest sees a memory model that looks like a normal PC:

The HVM guest's BIOS runs, starts the bootloader. The bootloader starts the OS kernel. The kernel comes up in real mode, does some setup and switches to protected mode[1], then it builds some pagetables and switches to paged mode, etc.

[1] sometimes (e.g. using grub and an OS supporting the multiboot standard) the bootloader may do the real->protected mode switch, but the sequence of events is otherwise pretty similar.

Hope that helps.
Cheers,
Mark

Quoted 25 lines

could you help me
Thanks in advance

Quoted 12 lines
Quoted 5 lines

that is during guest-linux
running,it will request some memory which it will get ,for the guest ,its memory (both its physical memory and its virtual memory)is dynamical allocated,while raditional linux has its physical memory when it boot up ,while gets virtual memory dynamically,is it right?

yes. see the xen interface manual on this topic, namely the chapters on memory management and the hypercall reference for page table and physical memory management. not sure if this gets entirely clear, though, i sometimes tend to get confused myself. especially guest side vm tends to be complex, but that's quite natural.

Quoted 5 lines
Quoted 2 lines

could you help me
thanks in advance

hth,
dns

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat?  And no pedals!
Mark: To answer a question with a question: What use is a skateboard?
Dave: Skateboards have wheels.
Mark: My wheel has a wheel!
#11 lore raw

question about xm mem-max and xm mem-set without rebooting VM

In reply to tgh

hi
I use xen-3.0.3,and boot up a VM with its config file "mem=256"
and during VM running, I try to" xm mem-max it 512 "and "xm mem-set it 512"
then without rebooting VM, I run an application to allocate and wirte/read memory(say size >240M),but it fails and cat /proc/meminfo in the VMshell, VM does not have 512M memory

but if rebooting VM after xm mem-max 512 and xm mem-set 512, the application will work well

does the"xm mem-max and xm mem-set" have to be followed by a rebooting VM to make it work ,or how to make it work without rebooting VM?

nowadays ,does xen support the "xm mem-max" without rebooting VM ,or not ?

or does future version support it or does anyone work to achieve it ?

could you help me
Thanks in advance

#12 lore raw

Re: question about running vm change its mem maxsize

In reply to tgh

Thank you for your reply

Quoted 39 lines · Daniel Stodden
Quoted 32 lines · tgh

Thank you for your reply

Quoted 9 lines · Daniel Stodden
Quoted 7 lines · tgh

hi
I read the code of xc_linux_build() and xc_domain_setmaxmem(),and
I am confused about how does "xm mem-max" change the max size of mem for a running VM

In xc_domain_setmaxmem() ,the XEN_DOMCTL_max_mem has been called
,and just does "d->max_pages = new_max;"

Quoted 9 lines

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.

I see

Quoted 8 lines
Quoted 2 lines

while in the xc_linux_build(), before the vm boots up,the maxsize pfn is alloced in an array with fixsize, page_array = malloc(nr_pages * sizeof(unsigned long))

i suppose you misunderstood what that call really does. it's not changing the maximum vm size, but allocating the initial number of pages required to load the guest operating system image into. that's typically much less than d->max_pages.

Quoted 4 lines

"page_array = malloc(nr_pages *sizeof(unsigned long))" in xc_linux_build() is not to allocate the physical memory to the VM,then which code or function allocate the phy-mem to the VM?

I am confused about it

Quoted 9 lines

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.

I search the code ,it seems that
set_vram_mapping()->set_mm_mapping()->xc_domain_memory_populate_physmap() ,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 could use (say 512M for maxsize,or something)when vm boot up,instead,xen dynamically allocate some memory(both virtual and physical )to VM,when VM requests, while raditional linux manage its physical memory using mem_map or so when it boot up ,while allocates virtual memory dynamically,is it right?

I am confused about it

could you help me
thanks in advance

Quoted 72 lines

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 the kernel is loaded. lets say that's 4MB or something. as soon as the guest 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 which 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 requesting 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.

Quoted 10 lines
Quoted 10 lines
Quoted 2 lines

then how does a running vm changes its mem maxsize ,especially for expanding its mem maxsize?

for an unprivileged guest os, there is no such call. similar in the way 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.

Quoted 6 lines

I see it is domain0 who has the control interface to set and change the max-size of the VM memory

when VM is running, we can "xm mem-set " or "xm mem-max "in the domain0'console to change the vm memory

I have used it , and want to know what happen in the xen ,espacially in a paravirtVM

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 the 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