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 77254963F9 for ; Tue, 24 Jan 2023 14:04:30 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5BBE73B62 for ; Tue, 24 Jan 2023 14:04:30 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 ; Tue, 24 Jan 2023 14:04:29 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2B1CA45E98; Tue, 24 Jan 2023 14:04:29 +0100 (CET) Message-ID: <08805109-d3d9-ff98-5664-57e6fe7ed4ef@proxmox.com> Date: Tue, 24 Jan 2023 14:04:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 From: Fiona Ebner To: pve-devel@lists.proxmox.com, "aderumier@odiso.com" References: <20230104064303.2898194-1-aderumier@odiso.com> <20230104064303.2898194-2-aderumier@odiso.com> Content-Language: en-US In-Reply-To: <20230104064303.2898194-2-aderumier@odiso.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.594 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -1.148 Looks like a legit reply (A) 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. [memory.pm] Subject: Re: [pve-devel] [PATCH v2 qemu-server 1/9] test: add memory tests 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: Tue, 24 Jan 2023 13:04:30 -0000 Am 04.01.23 um 07:42 schrieb Alexandre Derumier: > Signed-off-by: Alexandre Derumier > --- > PVE/QemuServer/Memory.pm | 11 +- > test/cfg2cmd/memory-hotplug-hugepages.conf | 12 ++ > .../cfg2cmd/memory-hotplug-hugepages.conf.cmd | 62 +++++++ > test/cfg2cmd/memory-hotplug.conf | 11 ++ > test/cfg2cmd/memory-hotplug.conf.cmd | 174 ++++++++++++++++++ > test/cfg2cmd/memory-hugepages-1g.conf | 11 ++ > test/cfg2cmd/memory-hugepages-1g.conf.cmd | 30 +++ > test/cfg2cmd/memory-hugepages-2m.conf | 11 ++ > test/cfg2cmd/memory-hugepages-2m.conf.cmd | 30 +++ > test/run_config2command_tests.pl | 21 +++ > 10 files changed, 371 insertions(+), 2 deletions(-) > create mode 100644 test/cfg2cmd/memory-hotplug-hugepages.conf > create mode 100644 test/cfg2cmd/memory-hotplug-hugepages.conf.cmd > create mode 100644 test/cfg2cmd/memory-hotplug.conf > create mode 100644 test/cfg2cmd/memory-hotplug.conf.cmd > create mode 100644 test/cfg2cmd/memory-hugepages-1g.conf > create mode 100644 test/cfg2cmd/memory-hugepages-1g.conf.cmd > create mode 100644 test/cfg2cmd/memory-hugepages-2m.conf > create mode 100644 test/cfg2cmd/memory-hugepages-2m.conf.cmd > > diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm > index f8fc534..6c1cd94 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,13 @@ sub print_mem_object { > > } > > +sub host_numanode_exist { > + my ($id) = @_; > + > + return if ! -d "/sys/devices/system/node/node$id/"; > + return 1; Style nit: could be one line return -d "/sys/devices/system/node/node$id/"; > +} > + > sub print_numa_hostnodes { > my ($hostnodelists) = @_; > > @@ -402,7 +409,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); > } Nit: Ideally, the above would be it's own patch (or combined with extracting the other sub suggested below) > } > return $hostnodes; (...) > diff --git a/test/run_config2command_tests.pl b/test/run_config2command_tests.pl > index f097811..9b49063 100755 > --- a/test/run_config2command_tests.pl > +++ b/test/run_config2command_tests.pl > @@ -178,6 +178,27 @@ $qemu_server_config->mock( > }, > ); > > +my $qemu_server_memory; > +$qemu_server_memory = Test::MockModule->new('PVE::QemuServer::Memory'); > +$qemu_server_memory->mock( > + hugepages_size => sub { Rather than mocking the whole thing, we could also extract the sub { -d "/sys/kernel/mm/hugepages/hugepages-". ($_[0] * 1024) ."kB" } from the original into a named sub and only mock that. Then we'd get all the extra logic for checks like ($size & 1023) == 0, etc. > + my ($conf, $size) = @_; > + > + if ($conf->{hugepages} eq 'any') { > + return 1024; > + } else { > + return $conf->{hugepages}; > + } > + }, > + host_numanode_exist => sub { > + my ($id) = @_; > + return 1; > + }, > + get_host_phys_address_bits => sub { > + return 46; > + } > +); > + > my $pve_common_tools; > $pve_common_tools = Test::MockModule->new('PVE::Tools'); > $pve_common_tools->mock(