From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: When is the page table built for migration destination ? Date: Mon, 09 Sep 2013 10:14:02 +0200 Message-ID: <522D834A.2050309@redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: "kvm@vger.kernel.org" To: qna Return-path: Received: from mail-ee0-f53.google.com ([74.125.83.53]:37388 "EHLO mail-ee0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750977Ab3IIIN6 (ORCPT ); Mon, 9 Sep 2013 04:13:58 -0400 Received: by mail-ee0-f53.google.com with SMTP id b15so2990867eek.12 for ; Mon, 09 Sep 2013 01:13:56 -0700 (PDT) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: Il 09/09/2013 07:27, qna ha scritto: > Hello List, > > I am trying to understand kvm memory management code related to VM > migration. From the code, it looks like during guest VM migration, all the > memory of the guest is transferred from source to destination, but does it > copy the source page tables to destination ? > > A certain GFN(guest frame/physical number) X can be mapped to to PFN Y in > source but it is not necessary to map that GFN to PFN Y at destination. > Thus it should not make sense to copy page tables. But then, KVM should > build page tables when entire memory is copied(because current > implementation is precopy). > > I added prinks in code and looks like at destination it fault, there are no > page tables created. But the memory is. Is this understanding correct ? Can > anyone explain which part of code is doing this page table building ? The guest's page tables that do the gva->gfn (guest virtual address->guest frame number) translation are in guest memory, so they are obviously migrated together with the memory. As the guest runs, KVM builds page tables that do either gfn->pfn translation (if nested page tables are in use) or a combined gva->pfn translation (these are called "shadow page tables"). These page tables are internal to KVM and they are built lazily as the guest runs. To do this, KVM intercepts page faults, then: * if the entry for the GFN doesn't exist in the KVM page tables, it builds the entry and retries * if the entry for the GFN exists, it passes the page fault to the guest. Paolo