From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <s.reiter@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 7DE6F60535
 for <pve-devel@lists.proxmox.com>; Wed,  2 Sep 2020 11:03:47 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 6EB14F58D
 for <pve-devel@lists.proxmox.com>; Wed,  2 Sep 2020 11:03:47 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [212.186.127.180])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 3ACEBF582
 for <pve-devel@lists.proxmox.com>; Wed,  2 Sep 2020 11:03:46 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id EA938449BE
 for <pve-devel@lists.proxmox.com>; Wed,  2 Sep 2020 11:03:45 +0200 (CEST)
From: Stefan Reiter <s.reiter@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed,  2 Sep 2020 11:03:37 +0200
Message-Id: <20200902090337.10970-1-s.reiter@proxmox.com>
X-Mailer: git-send-email 2.20.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.055 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_DNSWL_MED        -2.3 Sender listed at https://www.dnswl.org/,
 medium trust
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [qemuserver.pm]
Subject: [pve-devel] [PATCH v2 qemu-server] fix #2570: add 'keephugepages'
 config
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 02 Sep 2020 09:03:47 -0000

We already keep hugepages if they are created with the kernel
commandline (hugepagesz=x hugepages=y), but some setups (specifically
hugepages across multiple NUMA nodes) cannot be configured that way.
Since we always clear these hugepages at VM shutdown, rebooting a VM
that uses them might not work, since the requested count might not be
available anymore by the time we want to use them (also, we would then
no longer allocate them correctly on the NUMA nodes).

Add a 'keephugepages' parameter to skip cleanup and simply leave them
untouched.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
---

v2:
* rebase

 PVE/QemuServer.pm | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index a5ee8e2..d2a20b6 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -441,6 +441,14 @@ EODESC
 	description => "Enable/disable hugepages memory.",
 	enum => [qw(any 2 1024)],
     },
+    keephugepages => {
+	optional => 1,
+	type => 'boolean',
+	default => 0,
+	description => "Use together with hugepages. If enabled, hugepages will"
+		     . " not be deleted after VM shutdown and can be used for"
+		     . " subsequent starts.",
+    },
     vcpus => {
 	optional => 1,
 	type => 'integer',
@@ -5034,11 +5042,13 @@ sub vm_start_nolock {
 
 	    eval { $run_qemu->() };
 	    if (my $err = $@) {
-		PVE::QemuServer::Memory::hugepages_reset($hugepages_host_topology);
+		PVE::QemuServer::Memory::hugepages_reset($hugepages_host_topology)
+		    if !$conf->{keephugepages};
 		die $err;
 	    }
 
-	    PVE::QemuServer::Memory::hugepages_pre_deallocate($hugepages_topology);
+	    PVE::QemuServer::Memory::hugepages_pre_deallocate($hugepages_topology)
+		if !$conf->{keephugepages};
 	};
 	eval { PVE::QemuServer::Memory::hugepages_update_locked($code); };
 
-- 
2.20.1