[pve-devel] [PATCH qemu-server 1/1] Use nr_hugepages from /proc/cmdline

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Feb 13 09:39:26 CET 2019


Looks good to me. Could you please also include a Signed-off-by line (I
think back when you sent your first patches we didn't list that in the
developer documentation as requirement, but now we do (though we
sometimes forget apparently ;-) */me stares at Thomas*))?

On Tue, Feb 12, 2019 at 12:49:14PM +0100, Kamil TrzciƄski wrote:
> Currently Proxmox VE always deallocates HugePagesTLB
> when starting a new machine and it makes it impossible
> to preconfigure kernel /proc/cmdline with persistent allocation.
> 
> This changes makes deallocation to prefer defaults set by /proc/cmdline,
> by parsing the cmdline and respecting hugepages= and hugepagesz=.
> ---
>  PVE/QemuServer/Memory.pm | 27 +++++++++++++++++++++++++--
>  1 file changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm
> index 0e4c830..aac4cf4 100644
> --- a/PVE/QemuServer/Memory.pm
> +++ b/PVE/QemuServer/Memory.pm
> @@ -538,6 +538,29 @@ sub hugepages_allocate {
>  
>  }
>  
> +sub hugepages_default_nr_hugepages {
> +    my ($size) = @_;
> +
> +    my $cmdline = PVE::Tools::file_read_firstline("/proc/cmdline");
> +    my $args = PVE::Tools::split_args($cmdline);
> +
> +    my $parsed_size = 2; # default is 2M
> +
> +    foreach my $arg (@$args) {
> +	if ($arg eq "hugepagesz=2M") {
> +	    $parsed_size = 2;
> +	} elsif ($arg eq "hugepagesz=1G") {
> +	    $parsed_size = 1024;
> +	} elsif ($arg =~ m/^hugepages=(\d+)?$/) {
> +	    if ($parsed_size == $size) {
> +		return $1;
> +	    }
> +	}
> +    }
> +
> +    return 0;
> +}
> +
>  sub hugepages_pre_deallocate {
>      my ($hugepages_topology) = @_;
>  
> @@ -545,8 +568,8 @@ sub hugepages_pre_deallocate {
>  
>  	my $hugepages_size = $size * 1024;
>  	my $path = "/sys/kernel/mm/hugepages/hugepages-${hugepages_size}kB/";
> -	my $hugepages_nr = PVE::Tools::file_read_firstline($path."nr_hugepages");
> -	PVE::ProcFSTools::write_proc_entry($path."nr_hugepages", 0);
> +	my $hugepages_nr = hugepages_default_nr_hugepages($size);
> +	PVE::ProcFSTools::write_proc_entry($path."nr_hugepages", $hugepages_nr);
>      }
>  }
>  
> -- 
> 2.11.0



More information about the pve-devel mailing list