From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: qemu/kvm memory allocation Date: Fri, 04 Jul 2014 18:17:27 +0200 Message-ID: <53B6D397.7030205@redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit To: Alexei Fedotov , kvm@vger.kernel.org Return-path: Received: from mail-qa0-f50.google.com ([209.85.216.50]:42275 "EHLO mail-qa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750836AbaGDQRc (ORCPT ); Fri, 4 Jul 2014 12:17:32 -0400 Received: by mail-qa0-f50.google.com with SMTP id m5so1472789qaj.37 for ; Fri, 04 Jul 2014 09:17:32 -0700 (PDT) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: Il 04/07/2014 16:49, Alexei Fedotov ha scritto: > Hi engineers, > > Could anyone direct me where memory allocation [1] for a new virtual > machine takes place in the code? I want to understand why the memory > is initialized with zeroes when I call malloc in a virtual machine. Nowhere in KVM. Memory allocation happens in userspace, which usually (but not necessarily) means QEMU. Quoting from the wiki page you mentioned: > The qemu/kvm process runs mostly like a normal Linux program. It > allocates its memory with normal malloc() or mmap() calls. If a guest is > going to have 1GB of physical memory, qemu/kvm will effectively do a > malloc(1<<30), allocating 1GB of host virtual space. However, just like > a normal program doing a malloc(), there is no actual physical memory > allocated at the time of the malloc(). It will not be actually allocated > until the first time it is touched. Paolo