[pve-devel] applied: [PATCH v2 qemu-server] Use nr_hugepages from /proc/cmdline

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Feb 18 10:46:07 CET 2019


applied, thanks

On Sun, Feb 17, 2019 at 01:39:37PM +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 change makes deallocation to prefer defaults set by /proc/cmdline,
> by parsing the cmdline and respecting hugepages= and hugepagesz=.
> 
> Signed-off-by: Kamil Trzciński <ayufan at ayufan.eu>
> ---
>  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.17.1




More information about the pve-devel mailing list