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 4FC1590686 for ; Fri, 3 Feb 2023 14:44:34 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 33E365164 for ; Fri, 3 Feb 2023 14:44:04 +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 ; Fri, 3 Feb 2023 14:44:02 +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 97769452CD; Fri, 3 Feb 2023 14:44:02 +0100 (CET) Message-ID: Date: Fri, 3 Feb 2023 14:44:01 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 From: Fiona Ebner To: pve-devel@lists.proxmox.com, "aderumier@odiso.com" References: <20230202110344.840195-1-aderumier@odiso.com> <20230202110344.840195-2-aderumier@odiso.com> Content-Language: en-US In-Reply-To: <20230202110344.840195-2-aderumier@odiso.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.043 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 -0.09 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 Subject: Re: [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: Fri, 03 Feb 2023 13:44:34 -0000 Am 02.02.23 um 12:03 schrieb Alexandre Derumier: > 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 { Nit: host_numanode_exists sounds more grammatically correct and the function could be moved above its first usage > + 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 { This needs a more descriptive name. How about 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 !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";