cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From 38dcbd1ff68da81b9172d8036622e41fe591c5c0 Mon Sep 17 00:00:00 2001
0a122b
From: Andrea Arcangeli <aarcange@redhat.com>
0a122b
Date: Fri, 7 Feb 2014 11:02:33 +0100
0a122b
Subject: [PATCH 10/28] exec: always use MADV_DONTFORK
0a122b
0a122b
RH-Author: Andrea Arcangeli <aarcange@redhat.com>
0a122b
Message-id: <1391770953-20138-2-git-send-email-aarcange@redhat.com>
0a122b
Patchwork-id: 57131
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH] exec: always use MADV_DONTFORK
0a122b
Bugzilla: 1004197
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Andrew Jones <drjones@redhat.com>
0a122b
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
0a122b
0a122b
MADV_DONTFORK prevents fork to fail with -ENOMEM if the default
0a122b
overcommit heuristics decides there's too much anonymous virtual
0a122b
memory allocated. If the KVM secondary MMU is synchronized with MMU
0a122b
notifiers or not, doesn't make a difference in that regard.
0a122b
0a122b
Secondly it's always more efficient to avoid copying the guest
0a122b
physical address space in the fork child (so we avoid to mark all the
0a122b
guest memory readonly in the parent and so we skip the establishment
0a122b
and teardown of lots of pagetables in the child).
0a122b
0a122b
In the common case we can ignore the error if MADV_DONTFORK is not
0a122b
available. Leave a second invocation that errors out in the KVM path
0a122b
if MMU notifiers are missing and KVM is enabled, to abort in such
0a122b
case.
0a122b
0a122b
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
0a122b
Tested-By: Benoit Canet <benoit@irqsave.net>
0a122b
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
Signed-off-by: Gleb Natapov <gleb@redhat.com>
0a122b
(cherry picked from upstream commit 3e469dbfe413c25d48321c3a19ddfae0727dc6e5)
0a122b
---
0a122b
 exec.c | 1 +
0a122b
 1 file changed, 1 insertion(+)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 exec.c |    1 +
0a122b
 1 files changed, 1 insertions(+), 0 deletions(-)
0a122b
0a122b
diff --git a/exec.c b/exec.c
0a122b
index ce9310c..6fe2fe7 100644
0a122b
--- a/exec.c
0a122b
+++ b/exec.c
0a122b
@@ -1194,6 +1194,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
0a122b
 
0a122b
     qemu_ram_setup_dump(new_block->host, size);
0a122b
     qemu_madvise(new_block->host, size, QEMU_MADV_HUGEPAGE);
0a122b
+    qemu_madvise(new_block->host, size, QEMU_MADV_DONTFORK);
0a122b
 
0a122b
     if (kvm_enabled())
0a122b
         kvm_setup_guest_memory(new_block->host, size);
0a122b
-- 
0a122b
1.7.1
0a122b