From patchwork Tue Aug 22 11:44:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13360531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6CB9EE4996 for ; Tue, 22 Aug 2023 11:49:09 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYPpr-0003xc-G9; Tue, 22 Aug 2023 07:46:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYPpP-0003hM-6r for qemu-devel@nongnu.org; Tue, 22 Aug 2023 07:45:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYPpM-0006o7-Hf for qemu-devel@nongnu.org; Tue, 22 Aug 2023 07:45:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692704739; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5geHhbE4MutI03r2OAElxDRwY2xkiopLerPizWqXowo=; b=H+MOXsr5rRmyhAajopwDItfs91d5UXtVEtegaQB8iP94s8pZTAUBfjqyXKLgBOh3TPtyHd JNRppuexxommwhzQiefMIw0xiu+U16APd3Cxy3cGmK0MdSk5mmsxtAOtudck+CXXFAKBi/ z1qmmsB8R3bgw+IM/jg5sYP80OMaEok= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-447-wr-JtGezOdaVqHVIaOxUpg-1; Tue, 22 Aug 2023 07:45:36 -0400 X-MC-Unique: wr-JtGezOdaVqHVIaOxUpg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5DB91101B429; Tue, 22 Aug 2023 11:45:36 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79489492C13; Tue, 22 Aug 2023 11:45:33 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, David Hildenbrand , Paolo Bonzini , Peter Xu , Igor Mammedov , Thiner Logoer , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Dani?= =?utf-8?q?el_P_=2E_Berrang=C3=A9?= , Stefan Hajnoczi , Elena Ufimtseva , Jagannathan Raman , "Michael S. Tsirkin" , Ani Sinha , Xiao Guangrong , Daniel Henrique Barboza , Greg Kurz , Eric Blake , Markus Armbruster , Eduardo Habkost Subject: [PATCH v2 9/9] docs: Start documenting VM templating Date: Tue, 22 Aug 2023 13:44:57 +0200 Message-ID: <20230822114504.239505-10-david@redhat.com> In-Reply-To: <20230822114504.239505-1-david@redhat.com> References: <20230822114504.239505-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Received-SPF: pass client-ip=170.10.129.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Let's add some details about VM templating, focusing on the VM memory configuration only. There is much more to VM templating (VM state? block devices?), but I leave that as future work. Signed-off-by: David Hildenbrand --- docs/vm-templating.txt | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 docs/vm-templating.txt diff --git a/docs/vm-templating.txt b/docs/vm-templating.txt new file mode 100644 index 0000000000..419362c1ea --- /dev/null +++ b/docs/vm-templating.txt @@ -0,0 +1,109 @@ +QEMU VM templating +================== + +This document explains how to use VM templating in QEMU. + +For now, the focus is on VM memory aspects, and not about how to save and +restore other VM state (i.e., migrate-to-file with 'x-ignore-shared'). + +Overview +-------- + +With VM templating, a single template VM serves as the starting point for +new VMs. This allows for fast and efficient replication of VMs, resulting +in fast startup times and reduced memory consumption. + +Conceptually, the VM state is frozen, to then be used as a basis for new +VMs. The Copy-On-Write mechanism in the operating systems makes +sure that new VMs are able to read template VM memory; however, any +modifications stay private and don't modify the original template VM or any +other created VM. + +Memory configuration +-------------------- + +In order to create the template VM, we have to make sure that VM memory +ends up in a file, from where it can be reused for the new VMs: + +Supply VM RAM via memory-backend-file, with 'share=on' (modifications go +to the file) and 'readonly=off' (open the file writable). Note that +'readonly=off' is implicit. + +In the following command-line example, a 2GB VM is created, whereby VM RAM +is to be stored in the 'template' file. + + qemu [...] -m 2g \ + -object memory-backend-file,id=pc.ram,mem-path=template,size=2g,share=on,... \ + -machine q35,memory-backend=pc.ram', + +If multiple memory backends are used (vNUMA, DIMMs), configure all +memory backends accordingly. + +Once the VM is in the desired state, stop the VM and save other VM state, +leaving the current state of VM RAM reside in the file. + +In order to have a new VM be based on a template VM, we have to +configure VM RAM to be based on a template VM RAM file; however, the VM +should not be able to modify file content. + +Supply VM RAM via memory-backend-file, with 'share=off' (modifications stay +private), 'readonly=on' (open the file readonly) and 'rom=off' (don't make +the memory readonly for the VM). Note that 'share=off' is implicit and +that other VM state has to be restored separately. + +In the following command-line example, a 2GB VM is created based on the +existing 2GB file 'template'. + + qemu [...] -m 2g \ + -object memory-backend-file,id=pc.ram,mem-path=template,size=2g,readonly=on,rom=off,... \ + -machine q35,memory-backend=pc.ram', + +If multiple memory backends are used (vNUMA, DIMMs), configure all +memory backends accordingly. + +Note that '-mem-path' cannot be used for VM templating when creating the +template VM or when starting new VMs based on a template VM. + +Incompatible features +--------------------- + +Some features are incompatible with VM templating, as the underlying file +cannot be modified to discard VM RAM, or to actually share memory with +another process. + +vhost-user and multi-process QEMU +''''''''''''''''''''''''''''''''' + +vhost-user and multi-process QEMU are incompatible with VM templating. +These technologies rely on shared memory, however, the template VMs +don't actually share memory ('share=off'), even though they are file-based. + +virtio-balloon +'''''''''''''' + +virtio-balloon inflation and "free page reporting" cannot discard VM RAM +and will repeatedly report errors. While virtio-balloon can be used +for template VMs (e.g., report VM RAM stats), "free page reporting" +should be disabled and the balloon should not be inflated. + +virtio-mem +'''''''''' + +virtio-mem cannot discard VM RAM that is managed by the virtio-mem +device. virtio-mem will fail early when realizing the device. To use +VM templating with virtio-mem, either hotplug virtio-mem devices to the new +VM, or don't supply any memory to the template VM using virtio-mem +(requested-size=0), not using a template VM file as memory backend for the +virtio-mem device. + +VM migration +'''''''''''' + +For VM migration, "x-release-ram" similarly relies on discarding of VM +RAM on the migration source to free up migrated RAM, and will +repeatedly report errors. + +Postcopy live migration fails discarding VM RAM on the migration +destination early and refuses to activate postcopy live migration. Note +that postcopy live migration usually only works on selected filesystems +(shmem/tmpfs, hugetlbfs) either way.