kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Allocating Extra Memory To Guest
@ 2009-05-06  9:24 Kumar, Venkat
  2009-05-06 11:12 ` Avi Kivity
  0 siblings, 1 reply; 4+ messages in thread
From: Kumar, Venkat @ 2009-05-06  9:24 UTC (permalink / raw)
  To: kvm@vger.kernel.org

Hi,

1. How should we allocate extra memory to guest other than memory allocated through "qemu_alloc_physram"??
2. How to register the extra allocated memory with KVM?

I have tried to allocate an extra one page to Guest but couldn't succeed; probably somebody had already done this exercise.

1. In Qemu/vl.c, I allocate a page for guest
	a. virt_addr = mmap(NULL, size, PROT_READ | PROT_WRITE,MAP_PRIVATE | 		MAP_ANON, -1, 0);

2. In "machine->init"
	a. ram_addr = qemu_ram_alloc(PAGE_SIZE);
	b.cpu_register_physical_memory(below_4g_mem_size,PAGE_SIZE,ram_addr+of	fset); (offset is the difference between the qemu's virtual address 	got from mmap and qemu's last virtual address allocated through 	"qemu_alloc_physram"

3. Increase "phys_ram_size" and "ram_size" by one page.

Did I miss something here?

Thx,

Venkat



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Allocating Extra Memory To Guest
  2009-05-06  9:24 Allocating Extra Memory To Guest Kumar, Venkat
@ 2009-05-06 11:12 ` Avi Kivity
  2009-05-06 12:09   ` Kumar, Venkat
  0 siblings, 1 reply; 4+ messages in thread
From: Avi Kivity @ 2009-05-06 11:12 UTC (permalink / raw)
  To: Kumar, Venkat; +Cc: kvm@vger.kernel.org

Kumar, Venkat wrote:
> Hi,
>
> 1. How should we allocate extra memory to guest other than memory allocated through "qemu_alloc_physram"??
>   

qemu_alloc_physram() is obsolete.  I've just removed it to avoid 
confusion (and a warning).

I presume you want to give kvm memory which is not real RAM - from a 
host device?
hw/device-assignment.c does that.

Please clarify what you want to do.


> 2. How to register the extra allocated memory with KVM?
>   

cpu_register_physical_memory(), but that has to come from qemu_ram_alloc().

As a hack, you can call qemu_ram_alloc(), and then 
mmap(qemu_ram_ptr(ram_offset), ... ) to replace the RAM with device memory.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Allocating Extra Memory To Guest
  2009-05-06 11:12 ` Avi Kivity
@ 2009-05-06 12:09   ` Kumar, Venkat
  2009-05-06 12:24     ` Avi Kivity
  0 siblings, 1 reply; 4+ messages in thread
From: Kumar, Venkat @ 2009-05-06 12:09 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm@vger.kernel.org

Please find my responses & questions in line.
Thx,

Venkat


-----Original Message-----
From: Avi Kivity [mailto:avi@redhat.com] 
Sent: Wednesday, May 06, 2009 4:42 PM
To: Kumar, Venkat
Cc: kvm@vger.kernel.org
Subject: Re: Allocating Extra Memory To Guest

Kumar, Venkat wrote:
> Hi,
>
> 1. How should we allocate extra memory to guest other than memory allocated through "qemu_alloc_physram"??
>   

qemu_alloc_physram() is obsolete.  I've just removed it to avoid 
confusion (and a warning).

==> 
If kvm-85 is the latest version, I still see "qemu_alloc_physram" invoked to allocate memory. This piece of code is in qemu/vl.c.
===================================================================
phys_ram_base = qemu_alloc_physram(phys_ram_size);
    if (!phys_ram_base) {
        fprintf(stderr, "Could not allocate physical memory\n");
        exit(1);
    }
====================================================================

I presume you want to give kvm memory which is not real RAM - from a 
host device?
hw/device-assignment.c does that.

Please clarify what you want to do.

==> 
I want to allocate extra RAM for the guest apart from memory allocated through "qemu_alloc_physram". Let's assume that I have allocated some RAM for guest through "qemu_alloc_physram" call and some more memory through "malloc or mmap", how will I register these two virtually discontinuous memory regions with KVM?

> 2. How to register the extra allocated memory with KVM?
>   

cpu_register_physical_memory(), but that has to come from qemu_ram_alloc().

As a hack, you can call qemu_ram_alloc(), and then 
mmap(qemu_ram_ptr(ram_offset), ... ) to replace the RAM with device memory.

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Allocating Extra Memory To Guest
  2009-05-06 12:09   ` Kumar, Venkat
@ 2009-05-06 12:24     ` Avi Kivity
  0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2009-05-06 12:24 UTC (permalink / raw)
  To: Kumar, Venkat; +Cc: kvm@vger.kernel.org

Kumar, Venkat wrote:
> Kumar, Venkat wrote:
>   
>> Hi,
>>
>> 1. How should we allocate extra memory to guest other than memory allocated through "qemu_alloc_physram"??
>>   
>>     
>
> qemu_alloc_physram() is obsolete.  I've just removed it to avoid 
> confusion (and a warning).
>
> ==> 
> If kvm-85 is the latest version, I still see "qemu_alloc_physram" invoked to allocate memory. This piece of code is in qemu/vl.c.
>   

The really latest version is in git.  See 
http://www.linux-kvm.org/page/Code.


> I presume you want to give kvm memory which is not real RAM - from a 
> host device?
> hw/device-assignment.c does that.
>
> Please clarify what you want to do.
>
> ==> 
> I want to allocate extra RAM for the guest apart from memory allocated through "qemu_alloc_physram". Let's assume that I have allocated some RAM for guest through "qemu_alloc_physram" call and some more memory through "malloc or mmap", how will I register these two virtually discontinuous memory regions with KVM?
>   

You can use qemu_ram_alloc() and cpu_register_physical_memory().

-- 
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-05-06 12:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-06  9:24 Allocating Extra Memory To Guest Kumar, Venkat
2009-05-06 11:12 ` Avi Kivity
2009-05-06 12:09   ` Kumar, Venkat
2009-05-06 12:24     ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).