From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 470AB917AC for ; Thu, 2 Feb 2023 12:04:31 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8509CB198 for ; Thu, 2 Feb 2023 12:04:00 +0100 (CET) Received: from bastionodiso.odiso.net (bastionodiso.odiso.net [IPv6:2a0a:1580:2000::2d]) (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 for ; Thu, 2 Feb 2023 12:03:58 +0100 (CET) Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12]) by bastionodiso.odiso.net (Postfix) with ESMTP id 1CF4282D0; Thu, 2 Feb 2023 12:03:50 +0100 (CET) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id 1BE8F22A2C1; Thu, 2 Feb 2023 12:03:50 +0100 (CET) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Thu, 2 Feb 2023 12:03:39 +0100 Message-Id: <20230202110344.840195-9-aderumier@odiso.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230202110344.840195-1-aderumier@odiso.com> References: <20230202110344.840195-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.027 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% HEADER_FROM_DIFFERENT_DOMAINS 0.25 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.001 Envelope sender has no MX or A DNS records SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an 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. [memory.pm] Subject: [pve-devel] [PATCH v3 qemu-server 08/13] memory: don't use foreach_reversedimm for unplug X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Feb 2023 11:04:31 -0000 simple use dimm_list() returned by qemu Signed-off-by: Alexandre Derumier --- PVE/QemuServer/Memory.pm | 73 ++++++++++++---------------------------- 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm index b5f1076..bcf5f95 100644 --- a/PVE/QemuServer/Memory.pm +++ b/PVE/QemuServer/Memory.pm @@ -210,38 +210,6 @@ sub foreach_dimm{ } } -sub foreach_reverse_dimm { - my ($conf, $vmid, $memory, $sockets, $func) = @_; - - my $dimm_id = 253; - my $current_size = 0; - my $dimm_size = 0; - - if($conf->{hugepages} && $conf->{hugepages} == 1024) { - $current_size = 8355840; - $dimm_size = 131072; - } else { - $current_size = 4177920; - $dimm_size = 65536; - } - - return if $current_size == $memory; - - my @numa_map = get_numa_node_list($conf); - - for (my $j = 0; $j < 8; $j++) { - for (my $i = 0; $i < 32; $i++) { - my $name = "dimm${dimm_id}"; - $dimm_id--; - my $numanode = $numa_map[(31-$i) % @numa_map]; - $current_size -= $dimm_size; - &$func($conf, $vmid, $name, $dimm_size, $numanode, $current_size, $memory); - return $current_size if $current_size <= $memory; - } - $dimm_size /= 2; - } -} - sub qemu_memory_hotplug { my ($vmid, $conf, $value) = @_; @@ -316,30 +284,33 @@ sub qemu_memory_hotplug { } else { - foreach_reverse_dimm($conf, $vmid, $value, $sockets, sub { - my ($conf, $vmid, $name, $dimm_size, $numanode, $current_size, $memory) = @_; + my $dimms = qemu_dimm_list($vmid); + my $current_size = $memory; + for my $name (sort { $dimms->{$b}{slot} <=> $dimms->{$a}{slot} } keys %$dimms) { - return if $current_size >= get_current_memory($conf->{memory}); + my $dimm_size = $dimms->{$name}->{size} / 1024 / 1024; - print "try to unplug memory dimm $name\n"; + last if $current_size <= $value || $current_size <= $static_memory; - my $retry = 0; - while (1) { - eval { PVE::QemuServer::qemu_devicedel($vmid, $name) }; - sleep 3; - my $dimm_list = qemu_dimm_list($vmid); - last if !$dimm_list->{$name}; - raise_param_exc({ $name => "error unplug memory module" }) if $retry > 5; - $retry++; - } + print "try to unplug memory dimm $name\n"; - #update conf after each succesful module unplug - $newmem->{current} = $current_size; - $conf->{memory} = print_memory($newmem); + my $retry = 0; + while (1) { + eval { PVE::QemuServer::qemu_devicedel($vmid, $name) }; + sleep 3; + my $dimm_list = qemu_dimm_list($vmid); + last if !$dimm_list->{$name}; + raise_param_exc({ $name => "error unplug memory module" }) if $retry > 5; + $retry++; + } + $current_size -= $dimm_size; + #update conf after each succesful module unplug + $newmem->{current} = $current_size; + $conf->{memory} = print_memory($newmem); - eval { PVE::QemuServer::qemu_objectdel($vmid, "mem-$name"); }; - PVE::QemuConfig->write_config($vmid, $conf); - }); + eval { PVE::QemuServer::qemu_objectdel($vmid, "mem-$name"); }; + PVE::QemuConfig->write_config($vmid, $conf); + } } return $conf->{memory}; } -- 2.30.2