From patchwork Thu Jul 25 10:11:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Arcangeli X-Patchwork-Id: 261663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E22582C00A1 for ; Thu, 25 Jul 2013 20:11:42 +1000 (EST) Received: from localhost ([::1]:43928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2IWK-00068S-Ve for incoming@patchwork.ozlabs.org; Thu, 25 Jul 2013 06:11:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2IW4-00068B-3f for qemu-devel@nongnu.org; Thu, 25 Jul 2013 06:11:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2IW1-0001b0-6N for qemu-devel@nongnu.org; Thu, 25 Jul 2013 06:11:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14632) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2IW0-0001au-VU; Thu, 25 Jul 2013 06:11:21 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6PABGpZ017558 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Jul 2013 06:11:17 -0400 Received: from mail.random (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6PABFKh014328; Thu, 25 Jul 2013 06:11:16 -0400 From: Andrea Arcangeli To: qemu-devel@nongnu.org, qemu-stable@nongnu.org Date: Thu, 25 Jul 2013 12:11:15 +0200 Message-Id: <1374747075-7172-1-git-send-email-aarcange@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , Gleb Natapov Subject: [Qemu-devel] [PATCH] KVM: always use MADV_DONTFORK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org MADV_DONTFORK prevents fork to fail with -ENOMEM if the default overcommit heuristics decides there's too much anonymous virtual memory allocated. If the KVM secondary MMU is synchronized with MMU notifiers or not, doesn't make a difference in that regard. Secondly it's always more efficient to avoid copying the guest physical address space in the fork child (so we avoid to mark all the guest memory readonly in the parent and so we skip the establishment and teardown of lots of pagetables in the child). In the common case we can ignore the error if MADV_DONTFORK is not available. Leave a second invocation that errors out in the KVM path if MMU notifiers are missing and KVM is enabled, to abort in such case. Signed-off-by: Andrea Arcangeli Tested-By: Benoit Canet Acked-by: Paolo Bonzini --- exec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/exec.c b/exec.c index c99a883..d3bb58d 100644 --- a/exec.c +++ b/exec.c @@ -1162,6 +1162,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, qemu_ram_setup_dump(new_block->host, size); qemu_madvise(new_block->host, size, QEMU_MADV_HUGEPAGE); + qemu_madvise(new_block->host, size, QEMU_MADV_DONTFORK); if (kvm_enabled()) kvm_setup_guest_memory(new_block->host, size);