All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] Virtual memory question
@ 2010-08-08 20:33 Dennis
  2010-08-09  5:01 ` C K Kashyap
  2010-08-09  6:15 ` Mulyadi Santosa
  0 siblings, 2 replies; 9+ messages in thread
From: Dennis @ 2010-08-08 20:33 UTC (permalink / raw)
  To: qemu-devel

Hi,

I've been looking at the qemu source code but couldn't find anything
that would suit my needs.
Basically I'm looking for a way to use a file on disk as physical
memory inside Qemu.

Before I attempt to reinvent the wheel, has someone ever hacked in
similar functionality and if so is there a diff patch available
anywhere?

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

* Re: [Qemu-devel] Virtual memory question
  2010-08-08 20:33 [Qemu-devel] Virtual memory question Dennis
@ 2010-08-09  5:01 ` C K Kashyap
  2010-08-09 18:49   ` Dennis
  2010-08-09  6:15 ` Mulyadi Santosa
  1 sibling, 1 reply; 9+ messages in thread
From: C K Kashyap @ 2010-08-09  5:01 UTC (permalink / raw)
  To: Dennis; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 491 bytes --]

I am curious to know why you'd want to do it?

On Mon, Aug 9, 2010 at 2:03 AM, Dennis <dennis@satanclaus.com> wrote:

> Hi,
>
> I've been looking at the qemu source code but couldn't find anything
> that would suit my needs.
> Basically I'm looking for a way to use a file on disk as physical
> memory inside Qemu.
>
> Before I attempt to reinvent the wheel, has someone ever hacked in
> similar functionality and if so is there a diff patch available
> anywhere?
>
>


-- 
Regards,
Kashyap

[-- Attachment #2: Type: text/html, Size: 816 bytes --]

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

* Re: [Qemu-devel] Virtual memory question
  2010-08-08 20:33 [Qemu-devel] Virtual memory question Dennis
  2010-08-09  5:01 ` C K Kashyap
@ 2010-08-09  6:15 ` Mulyadi Santosa
  2010-08-09  8:17   ` Stefan Hajnoczi
  1 sibling, 1 reply; 9+ messages in thread
From: Mulyadi Santosa @ 2010-08-09  6:15 UTC (permalink / raw)
  To: Dennis; +Cc: qemu-devel

Hi..

On Mon, Aug 9, 2010 at 03:33, Dennis <dennis@satanclaus.com> wrote:
> Hi,
>
> I've been looking at the qemu source code but couldn't find anything
> that would suit my needs.
> Basically I'm looking for a way to use a file on disk as physical
> memory inside Qemu.

Once when I did code adventure in Qemu, I conclude Qemu create
temporary file (possibly using mktemp()) and mmap it, thus creating
"illusion" file as RAM for guest.

So, I think it's already done. It's just not configurable through
command parameter

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

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

* Re: [Qemu-devel] Virtual memory question
  2010-08-09  6:15 ` Mulyadi Santosa
@ 2010-08-09  8:17   ` Stefan Hajnoczi
  2010-08-09 16:46     ` Michael Roth
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Hajnoczi @ 2010-08-09  8:17 UTC (permalink / raw)
  To: Mulyadi Santosa; +Cc: Dennis, qemu-devel

On Mon, Aug 9, 2010 at 7:15 AM, Mulyadi Santosa
<mulyadi.santosa@gmail.com> wrote:
> On Mon, Aug 9, 2010 at 03:33, Dennis <dennis@satanclaus.com> wrote:
>> Hi,
>>
>> I've been looking at the qemu source code but couldn't find anything
>> that would suit my needs.
>> Basically I'm looking for a way to use a file on disk as physical
>> memory inside Qemu.
>
> Once when I did code adventure in Qemu, I conclude Qemu create
> temporary file (possibly using mktemp()) and mmap it, thus creating
> "illusion" file as RAM for guest.
>
> So, I think it's already done. It's just not configurable through
> command parameter

Use -mem-path /path/to/directory.  It's used for hugetlbfs support on
Linux but it should work on a normal filesystem too.

Stefan

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

* Re: [Qemu-devel] Virtual memory question
  2010-08-09  8:17   ` Stefan Hajnoczi
@ 2010-08-09 16:46     ` Michael Roth
  2010-08-09 18:49       ` Michael Roth
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Roth @ 2010-08-09 16:46 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

On 08/09/2010 03:17 AM, Stefan Hajnoczi wrote:
>
> Use -mem-path /path/to/directory.  It's used for hugetlbfs support on
> Linux but it should work on a normal filesystem too.
>
> Stefan
>

It *almost* works, except for some minor obstacles:

1) Normally the pages get mmap()'d with MAP_PRIVATE so they COW'd rather 
than written to the backing file:

#ifdef MAP_POPULATE
     /* NB: MAP_POPULATE won't exhaustively alloc all phys pages in the case
      * MAP_PRIVATE is requested.  For mem_prealloc we mmap as MAP_SHARED
      * to sidestep this quirk.
      */
     flags = mem_prealloc ? MAP_POPULATE | MAP_SHARED : MAP_PRIVATE;
     area = mmap(0, memory, PROT_READ | PROT_WRITE, flags, fd, 0);
#else
     area = mmap(0, memory, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
#endif

You can force a MAP_SHARED mapping without any changes to qemu by using 
the -mem_prealloc option, but you'll get MAP_POPULATE as well, which may 
not be desirable. A small patch would do the job though.

2) exec.c:file_ram_alloc() assumes you're allocating off a hugetlbfs and 
makes some system calls to get the block/hugepage size. A quick hack 
might be to comment out the following in exec.c:gethugepagesize():

if (fs.f_type != HUGETLBFS_MAGIC)
             fprintf(stderr, "Warning: path not on HugeTLBFS: %s\n", path);

You may also want to replace the mkstemp() with a mkostemp() and set 
O_SYNC on the file

But beyond hacks, I think generalizing -mempath might have some other 
useful applications (using it as a way to expose tmpfs-backed/numactl'd 
files as numa nodes to guests came up in an earlier discussion, and 
memory compression via zram/compcache is another).

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

* Re: [Qemu-devel] Virtual memory question
  2010-08-09 16:46     ` Michael Roth
@ 2010-08-09 18:49       ` Michael Roth
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Roth @ 2010-08-09 18:49 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel

On 08/09/2010 11:46 AM, Michael Roth wrote:
>
> 2) exec.c:file_ram_alloc() assumes you're allocating off a hugetlbfs and
> makes some system calls to get the block/hugepage size. A quick hack
> might be to comment out the following in exec.c:gethugepagesize():
>
> if (fs.f_type != HUGETLBFS_MAGIC)
> fprintf(stderr, "Warning: path not on HugeTLBFS: %s\n", path);
>
> You may also want to replace the mkstemp() with a mkostemp() and set
> O_SYNC on the file
>
> But beyond hacks, I think generalizing -mempath might have some other
> useful applications (using it as a way to expose tmpfs-backed/numactl'd
> files as numa nodes to guests came up in an earlier discussion, and
> memory compression via zram/compcache is another).
>

Actually I guess 2) isn't really an issue, thought was an error path but 
I was mistaken.

-Mike

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

* Re: [Qemu-devel] Virtual memory question
  2010-08-09  5:01 ` C K Kashyap
@ 2010-08-09 18:49   ` Dennis
  2010-08-09 19:41     ` Stefan Hajnoczi
  0 siblings, 1 reply; 9+ messages in thread
From: Dennis @ 2010-08-09 18:49 UTC (permalink / raw)
  To: qemu-devel

On Mon, Aug 9, 2010 at 2:03 AM, Dennis <dennis@satanclaus.com> wrote:
>>
>> Hi,
>>
>> I've been looking at the qemu source code but couldn't find anything
>> that would suit my needs.
>> Basically I'm looking for a way to use a file on disk as physical
>> memory inside Qemu.
>>
>> Before I attempt to reinvent the wheel, has someone ever hacked in
>> similar functionality and if so is there a diff patch available
>> anywhere?
On Mon, Aug 9, 2010 at 7:01 AM, C K Kashyap <ckkashyap@gmail.com> wrote:

> I am curious to know why you'd want to do it?

I have an application that takes up over 2 GB of memory but is
otherwise demanding virtually no other resources at all.
Running multiple instances of the application using physical memory
isn't an option. Would it be hard to change Qemu's
physical memory mapping to a file on disk ? (Not Qemu-KVM, just stock Qemu).

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

* Re: [Qemu-devel] Virtual memory question
  2010-08-09 18:49   ` Dennis
@ 2010-08-09 19:41     ` Stefan Hajnoczi
  2010-08-09 19:54       ` Dennis
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Hajnoczi @ 2010-08-09 19:41 UTC (permalink / raw)
  To: Dennis; +Cc: qemu-devel

On Mon, Aug 9, 2010 at 7:49 PM, Dennis <dennis@satanclaus.com> wrote:
> I have an application that takes up over 2 GB of memory but is
> otherwise demanding virtually no other resources at all.
> Running multiple instances of the application using physical memory
> isn't an option. Would it be hard to change Qemu's
> physical memory mapping to a file on disk ? (Not Qemu-KVM, just stock Qemu).

It's not 100% clear what you are trying to do, but are you aware that
guest "physical" memory can be swapped on the host?  If you put two
VMs on one host which use more memory than available host RAM, some of
their pages will get pushed out to swap, like any normal userspace
process.  Two things to consider in a memory overcommit scenario are
reduced performance due to swapping and allocating enough swap so the
out-of-memory killer does not terminate the QEMU process.

Also, have you looked at Kernel Samepage Merging (KSM)?  KSM detects
guest physical pages that contain the same contents and merge them
into a single page, saving memory.  This is appropriate if you run
multiple VMs based off the same disk image and expect they will be
executing the same code.  For more info, see
http://kernelnewbies.org/Linux_2_6_32#head-d3f32e41df508090810388a57efce73f52660ccb.

Stefan

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

* Re: [Qemu-devel] Virtual memory question
  2010-08-09 19:41     ` Stefan Hajnoczi
@ 2010-08-09 19:54       ` Dennis
  0 siblings, 0 replies; 9+ messages in thread
From: Dennis @ 2010-08-09 19:54 UTC (permalink / raw)
  To: qemu-devel

On Mon, Aug 9, 2010 at 9:41 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Mon, Aug 9, 2010 at 7:49 PM, Dennis <dennis@satanclaus.com> wrote:
>> I have an application that takes up over 2 GB of memory but is
>> otherwise demanding virtually no other resources at all.
>> Running multiple instances of the application using physical memory
>> isn't an option. Would it be hard to change Qemu's
>> physical memory mapping to a file on disk ? (Not Qemu-KVM, just stock Qemu).
>
> It's not 100% clear what you are trying to do, but are you aware that
> guest "physical" memory can be swapped on the host?

I know, but the host machine would have to run out of memory before it swaps.
That's not very desirable ;-)

> Also, have you looked at Kernel Samepage Merging (KSM)?  KSM detects
> guest physical pages that contain the same contents and merge them
> into a single page, saving memory.  This is appropriate if you run
> multiple VMs based off the same disk image and expect they will be
> executing the same code.  For more info, see
> http://kernelnewbies.org/Linux_2_6_32#head-d3f32e41df508090810388a57efce73f52660ccb.

I havn't yet. One "problem" is I _have_ to run Qemu on FreeBSD. I
doubt it's possible.

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

end of thread, other threads:[~2010-08-09 19:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-08 20:33 [Qemu-devel] Virtual memory question Dennis
2010-08-09  5:01 ` C K Kashyap
2010-08-09 18:49   ` Dennis
2010-08-09 19:41     ` Stefan Hajnoczi
2010-08-09 19:54       ` Dennis
2010-08-09  6:15 ` Mulyadi Santosa
2010-08-09  8:17   ` Stefan Hajnoczi
2010-08-09 16:46     ` Michael Roth
2010-08-09 18:49       ` Michael Roth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.