diff mbox

add MADV_DONTFORK to guest physical memory

Message ID 20100915170824.GL5981@random.random
State New
Headers show

Commit Message

Andrea Arcangeli Sept. 15, 2010, 5:08 p.m. UTC
From: Andrea Arcangeli <aarcange@redhat.com>

All allocated guest physical memory shall be marked MADV_DONTFORK, otherwise
fork will fail because of accounting issues preventing migration or netdev_add
when the guest allocated more than half of host physical memory.

Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---

Comments

Alexander Graf Sept. 15, 2010, 5:34 p.m. UTC | #1
On 15.09.2010, at 19:08, Andrea Arcangeli wrote:

> From: Andrea Arcangeli <aarcange@redhat.com>
> 
> All allocated guest physical memory shall be marked MADV_DONTFORK, otherwise
> fork will fail because of accounting issues preventing migration or netdev_add
> when the guest allocated more than half of host physical memory.
> 
> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>

The madvise logic is just about to get changed now. Please look at Andreas' patches and coordinate with him there.


Alex
Andreas Färber Sept. 15, 2010, 5:37 p.m. UTC | #2
Am 15.09.2010 um 19:08 schrieb Andrea Arcangeli:

> From: Andrea Arcangeli <aarcange@redhat.com>
>
> All allocated guest physical memory shall be marked MADV_DONTFORK,  
> otherwise
> fork will fail because of accounting issues preventing migration or  
> netdev_add
> when the guest allocated more than half of host physical memory.
>
> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
> ---
>
> diff --git a/exec.c b/exec.c
> index 380dab5..e2bdf19 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2861,6 +2861,9 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState  
> *dev, const char *name,
> #ifdef MADV_MERGEABLE
>             madvise(new_block->host, size, MADV_MERGEABLE);
> #endif
> +#ifdef MADV_DONTFORK
> +            madvise(new_block->host, size, MADV_DONTFORK);
> +#endif

There is a pending patch which introduces qemu_madvise() and will  
eliminate the need for these #ifdefs, which was demanded by Blue. I'll  
cc you on v6.

Regards,

Andreas
Michael S. Tsirkin Sept. 15, 2010, 9:03 p.m. UTC | #3
On Wed, Sep 15, 2010 at 07:08:24PM +0200, Andrea Arcangeli wrote:
> From: Andrea Arcangeli <aarcange@redhat.com>
> 
> All allocated guest physical memory shall be marked MADV_DONTFORK, otherwise
> fork will fail because of accounting issues preventing migration or netdev_add
> when the guest allocated more than half of host physical memory.
> 
> Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
> ---
> 
> diff --git a/exec.c b/exec.c
> index 380dab5..e2bdf19 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -2861,6 +2861,9 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
>  #ifdef MADV_MERGEABLE
>              madvise(new_block->host, size, MADV_MERGEABLE);
>  #endif
> +#ifdef MADV_DONTFORK
> +            madvise(new_block->host, size, MADV_DONTFORK);
> +#endif
>          }
>      }

Is this always a number of full host pages? If not, we'd get trouble
when trying to call helpers.
Gleb Natapov Sept. 16, 2010, 6:51 a.m. UTC | #4
On Wed, Sep 15, 2010 at 11:03:14PM +0200, Michael S. Tsirkin wrote:
> On Wed, Sep 15, 2010 at 07:08:24PM +0200, Andrea Arcangeli wrote:
> > From: Andrea Arcangeli <aarcange@redhat.com>
> > 
> > All allocated guest physical memory shall be marked MADV_DONTFORK, otherwise
> > fork will fail because of accounting issues preventing migration or netdev_add
> > when the guest allocated more than half of host physical memory.
> > 
> > Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
> > ---
> > 
> > diff --git a/exec.c b/exec.c
> > index 380dab5..e2bdf19 100644
> > --- a/exec.c
> > +++ b/exec.c
> > @@ -2861,6 +2861,9 @@ ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
> >  #ifdef MADV_MERGEABLE
> >              madvise(new_block->host, size, MADV_MERGEABLE);
> >  #endif
> > +#ifdef MADV_DONTFORK
> > +            madvise(new_block->host, size, MADV_DONTFORK);
> > +#endif
> >          }
> >      }
> 
> Is this always a number of full host pages? If not, we'd get trouble
> when trying to call helpers.
> 
How it can be not a number of full host pages? This is guest memory.

--
			Gleb.
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 380dab5..e2bdf19 100644
--- a/exec.c
+++ b/exec.c
@@ -2861,6 +2861,9 @@  ram_addr_t qemu_ram_alloc_from_ptr(DeviceState *dev, const char *name,
 #ifdef MADV_MERGEABLE
             madvise(new_block->host, size, MADV_MERGEABLE);
 #endif
+#ifdef MADV_DONTFORK
+            madvise(new_block->host, size, MADV_DONTFORK);
+#endif
         }
     }