qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC] support memory reserved feature and optimize mlock guest memory propose
@ 2014-03-05  8:01 Zhanghailiang
  2014-03-05  8:56 ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Zhanghailiang @ 2014-03-05  8:01 UTC (permalink / raw)
  To: pbonzini@redhat.com, quintela@redhat.com,
	edgar.iglesias@xilinx.com, Stefan Hajnoczi, kwolf@redhat.com,
	qemu-devel@nongnu.org, libvir-list@redhat.com
  Cc: Zhouxiangjiu, Huazhiqiang, Huangzhichao, Huangpeng (Peter)

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

Hi all:
Currently, we use cgroup(memory) to support memory QoS on KVM platform, and use "mlock" on qemu to support "memory reserved".
The "mlock" seems to be not appropriate.
Now qemu "mlock" memory in the main thread, which would lock iothread (qemu_mutex_lock_iothread), if the memory size is large, that will consume lots of time.
It means whenever we want to set a new 'mlock', the VM would be blocked for a while.
Here is my optimization:
  1. Add a global variable (lock_ram_size) to save the value of "memory reserved";
  2. Add a qmp commond "set_ram_minguarantee" to change lock_ram_size;
  3. Create a new thread to mlock(lock_ram_zie), while is waked up by the "set_ram_minguarantee" qmp command.
Flow chart:
           main funciton           qmp command "set_ram_minguarantee"
                 |                           |
                 |                           |
        create "mlock" thread           change value of lock_ram_size
                 |                           |
                 |                           |
    |------>thread wait<-------------wake up "mlock" thread
    |            |
    |            |
    |            |
    |-------mlock(lock_ram_zie)

We have tested this demo a few days, it seems to be worked well.
But we are not sure is there any other problems , if the main thread and mlock thread access one memory zone at one time without a mutex lock.
Is it workable?Or Is there any other idea to support "memory reserved" ?

Thanks
zhanghailiang

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

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

* Re: [Qemu-devel] [RFC] support memory reserved feature and optimize mlock guest memory propose
  2014-03-05  8:01 [Qemu-devel] [RFC] support memory reserved feature and optimize mlock guest memory propose Zhanghailiang
@ 2014-03-05  8:56 ` Paolo Bonzini
  2014-03-06  8:06   ` Zhanghailiang
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2014-03-05  8:56 UTC (permalink / raw)
  To: Zhanghailiang, quintela@redhat.com, edgar.iglesias@xilinx.com,
	Stefan Hajnoczi, kwolf@redhat.com, qemu-devel@nongnu.org,
	libvir-list@redhat.com
  Cc: Zhouxiangjiu, Huazhiqiang, Huangzhichao, Huangpeng (Peter)

Il 05/03/2014 09:01, Zhanghailiang ha scritto:
> Hi all:
> 
> Currently, we use cgroup(memory) to support memory QoS on KVM platform,
> and use "mlock" on qemu to support "memory reserved".
> 
> The "mlock" seems to be not appropriate.
> 
> Now qemu "mlock" memory in the main thread, which would lock iothread
> (qemu_mutex_lock_iothread), if the memory size is large, that will
> consume lots of time.
> 
> It means whenever we want to set a new 'mlock', the VM would be blocked
> for a while.

I'm not sure I understand how the mlock-ed memory is used.  Are you
using a custom malloc, for example with g_mem_set_vtable?

Paolo

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

* Re: [Qemu-devel] [RFC] support memory reserved feature and optimize mlock guest memory propose
  2014-03-05  8:56 ` Paolo Bonzini
@ 2014-03-06  8:06   ` Zhanghailiang
  2014-03-06  8:41     ` Paolo Bonzini
  0 siblings, 1 reply; 4+ messages in thread
From: Zhanghailiang @ 2014-03-06  8:06 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: edgar.iglesias@xilinx.com, kwolf@redhat.com, quintela@redhat.com,
	libvir-list@redhat.com, Stefan Hajnoczi, qemu-devel@nongnu.org,
	Huangpeng (Peter), Huangzhichao, Huazhiqiang


> Il 05/03/2014 09:01, Zhanghailiang ha scritto:
> > Hi all:
> >
> > Currently, we use cgroup(memory) to support memory QoS on KVM
> > platform, and use "mlock" on qemu to support "memory reserved".
> >
> > The "mlock" seems to be not appropriate.
> >
> > Now qemu "mlock" memory in the main thread, which would lock iothread
> > (qemu_mutex_lock_iothread), if the memory size is large, that will
> > consume lots of time.
> >
> > It means whenever we want to set a new 'mlock', the VM would be
> > blocked for a while.
> 
> I'm not sure I understand how the mlock-ed memory is used.  Are you using a
> custom malloc, for example with g_mem_set_vtable?
> 
> Paolo

Hi Paolo:

Thanks for your reply.
As you know qemu has an option "-mlock", I think it has some problems.
If we set "-realtime mlock=on", then qemu will mlockall vm's memory, It is a very time consuming action, and it will block the libvirt api until it finished.
so I think it is better to do 'mlock' asynchronously, the flow chart can be described like below. Is it ok? 
Flow chart:
           main funciton           qmp command "set_ram_minguarantee"
                 |                           |
                 |                           |
        create "mlock" thread           change value of lock_ram_size
                 |                           |
                 |                           |
    |------>thread wait<-------------wake up "mlock" thread
    |            |
    |            |
    |            |
    |-------mlock(lock_ram_zie)


zhanghailiang

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

* Re: [Qemu-devel] [RFC] support memory reserved feature and optimize mlock guest memory propose
  2014-03-06  8:06   ` Zhanghailiang
@ 2014-03-06  8:41     ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-03-06  8:41 UTC (permalink / raw)
  To: Zhanghailiang
  Cc: edgar.iglesias@xilinx.com, kwolf@redhat.com, quintela@redhat.com,
	libvir-list@redhat.com, Stefan Hajnoczi, qemu-devel@nongnu.org,
	Huangpeng (Peter), Huangzhichao, Huazhiqiang

Il 06/03/2014 09:06, Zhanghailiang ha scritto:
> 
>> Il 05/03/2014 09:01, Zhanghailiang ha scritto:
>>> Hi all:
>>>
>>> Currently, we use cgroup(memory) to support memory QoS on KVM
>>> platform, and use "mlock" on qemu to support "memory reserved".
>>>
>>> The "mlock" seems to be not appropriate.
>>>
>>> Now qemu "mlock" memory in the main thread, which would lock iothread
>>> (qemu_mutex_lock_iothread), if the memory size is large, that will
>>> consume lots of time.
>>>
>>> It means whenever we want to set a new 'mlock', the VM would be
>>> blocked for a while.
>>
>> I'm not sure I understand how the mlock-ed memory is used.  Are you using a
>> custom malloc, for example with g_mem_set_vtable?
>>
>> Paolo
> 
> Hi Paolo:
> 
> Thanks for your reply.
> As you know qemu has an option "-mlock", I think it has some problems.
> If we set "-realtime mlock=on", then qemu will mlockall vm's memory, It is a very time consuming action, and it will block the libvirt api until it finished.
> so I think it is better to do 'mlock' asynchronously, the flow chart can be described like below.

Is an asynchronous mlock valid for all workloads?  Until the mlock
finishes, there is no guarantee that the guest will have
"real-time--friendly" response to memory allocation.

> Is it ok? 
> Flow chart:
>            main funciton           qmp command "set_ram_minguarantee"
>                  |                           |
>                  |                           |
>         create "mlock" thread           change value of lock_ram_size
>                  |                           |
>                  |                           |
>     |------>thread wait<-------------wake up "mlock" thread
>     |            |
>     |            |
>     |            |
>     |-------mlock(lock_ram_zie)

Also, I'm not sure what the arguments to mlock are.  How do you find the
address range to pass to mlock?

Paolo

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

end of thread, other threads:[~2014-03-06  8:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-05  8:01 [Qemu-devel] [RFC] support memory reserved feature and optimize mlock guest memory propose Zhanghailiang
2014-03-05  8:56 ` Paolo Bonzini
2014-03-06  8:06   ` Zhanghailiang
2014-03-06  8:41     ` Paolo Bonzini

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).