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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 06D6391764 for ; Thu, 2 Feb 2023 12:03:58 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E6283B0CD for ; Thu, 2 Feb 2023 12:03:57 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 2 Feb 2023 12:03:56 +0100 (CET) Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12]) by bastionodiso.odiso.net (Postfix) with ESMTP id 063ED8105; Thu, 2 Feb 2023 12:03:50 +0100 (CET) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id EA02322A61B; Thu, 2 Feb 2023 12:03:49 +0100 (CET) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Thu, 2 Feb 2023 12:03:32 +0100 Message-Id: <20230202110344.840195-2-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.028 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 01/13] memory: extract some code to their own sub for mocking 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:03:58 -0000 Signed-off-by: Alexandre Derumier --- PVE/QemuServer/Memory.pm | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm index 3eb1c7c..5a7c1b7 100644 --- a/PVE/QemuServer/Memory.pm +++ b/PVE/QemuServer/Memory.pm @@ -348,7 +348,7 @@ sub config { my $numa_memory = ($static_memory / $sockets); for (my $i = 0; $i < $sockets; $i++) { - die "host NUMA node$i doesn't exist\n" if ! -d "/sys/devices/system/node/node$i/" && $conf->{hugepages}; + die "host NUMA node$i doesn't exist\n" if !host_numanode_exist($i) && $conf->{hugepages}; my $mem_object = print_mem_object($conf, "ram-node$i", $numa_memory); push @$cmd, '-object', $mem_object; @@ -391,6 +391,12 @@ sub print_mem_object { } +sub host_numanode_exist { + my ($id) = @_; + + return -d "/sys/devices/system/node/node$id/"; +} + sub print_numa_hostnodes { my ($hostnodelists) = @_; @@ -402,7 +408,7 @@ sub print_numa_hostnodes { $hostnodes .= "-$end" if defined($end); $end //= $start; for (my $i = $start; $i <= $end; ++$i ) { - die "host NUMA node$i doesn't exist\n" if ! -d "/sys/devices/system/node/node$i/"; + die "host NUMA node$i doesn't exist\n" if !host_numanode_exist($i); } } return $hostnodes; @@ -445,21 +451,26 @@ sub hugepages_nr { return $size / $hugepages_size; } +my sub page_chunk { + my ($size) = @_; + + return -d "/sys/kernel/mm/hugepages/hugepages-". ($size * 1024) ."kB"; +} + sub hugepages_size { my ($conf, $size) = @_; die "hugepages option is not enabled" if !$conf->{hugepages}; die "memory size '$size' is not a positive even integer; cannot use for hugepages\n" if $size <= 0 || $size & 1; - my $page_chunk = sub { -d "/sys/kernel/mm/hugepages/hugepages-". ($_[0] * 1024) ."kB" }; - die "your system doesn't support hugepages\n" if !$page_chunk->(2) && !$page_chunk->(1024); + die "your system doesn't support hugepages\n" if !page_chunk(2) && !page_chunk(1024); if ($conf->{hugepages} eq 'any') { # try to use 1GB if available && memory size is matching - if ($page_chunk->(1024) && ($size & 1023) == 0) { + if (page_chunk(1024) && ($size & 1023) == 0) { return 1024; - } elsif ($page_chunk->(2)) { + } elsif (page_chunk(2)) { return 2; } else { die "host only supports 1024 GB hugepages, but requested size '$size' is not a multiple of 1024 MB\n" @@ -468,7 +479,7 @@ sub hugepages_size { my $hugepagesize = $conf->{hugepages}; - if (!$page_chunk->($hugepagesize)) { + if (!page_chunk($hugepagesize)) { die "your system doesn't support hugepages of $hugepagesize MB\n"; } elsif (($size % $hugepagesize) != 0) { die "Memory size $size is not a multiple of the requested hugepages size $hugepagesize\n"; -- 2.30.2