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 53AA592613 for ; Mon, 13 Feb 2023 13:01:01 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 28D4D223FA for ; Mon, 13 Feb 2023 13:00:31 +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 ; Mon, 13 Feb 2023 13:00:29 +0100 (CET) Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12]) by bastionodiso.odiso.net (Postfix) with ESMTP id 42DDB80C8; Mon, 13 Feb 2023 13:00:23 +0100 (CET) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id 278D6179F2A; Mon, 13 Feb 2023 13:00:23 +0100 (CET) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Mon, 13 Feb 2023 13:00:06 +0100 Message-Id: <20230213120021.3783742-2-aderumier@odiso.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230213120021.3783742-1-aderumier@odiso.com> References: <20230213120021.3783742-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.026 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 Subject: [pve-devel] [PATCH v4 qemu-server 01/16] 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: Mon, 13 Feb 2023 12:01:01 -0000 Signed-off-by: Alexandre Derumier --- PVE/QemuServer/Memory.pm | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm index 6fac468..e10c0b7 100644 --- a/PVE/QemuServer/Memory.pm +++ b/PVE/QemuServer/Memory.pm @@ -13,7 +13,7 @@ my $MAX_NUMA = 8; my $STATICMEM = 1024; my $_host_bits; -my sub get_host_phys_address_bits { +sub get_host_phys_address_bits { return $_host_bits if defined($_host_bits); my $fh = IO::File->new ('/proc/cpuinfo', "r") or return; @@ -76,6 +76,12 @@ sub get_numa_node_list { return (0..($sockets-1)); } +sub host_numanode_exists { + my ($id) = @_; + + return -d "/sys/devices/system/node/node$id/"; +} + # only valid when numa nodes map to a single host node sub get_numa_guest_to_host_map { my ($conf) = @_; @@ -348,7 +354,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_exists($i) && $conf->{hugepages}; my $mem_object = print_mem_object($conf, "ram-node$i", $numa_memory); push @$cmd, '-object', $mem_object; @@ -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_exists($i); } } return $hostnodes; @@ -445,21 +451,26 @@ sub hugepages_nr { return $size / $hugepages_size; } +sub hugepages_chunk_size_supported { + 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 !hugepages_chunk_size_supported(2) && !hugepages_chunk_size_supported(1024); if ($conf->{hugepages} eq 'any') { # try to use 1GB if available && memory size is matching - if ($page_chunk->(1024) && ($size & 1023) == 0) { + if (hugepages_chunk_size_supported(1024) && ($size & 1023) == 0) { return 1024; - } elsif ($page_chunk->(2)) { + } elsif (hugepages_chunk_size_supported(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 (!hugepages_chunk_size_supported($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