public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, "aderumier@odiso.com" <aderumier@odiso.com>
Subject: Re: [pve-devel] [PATCH v3 qemu-server 04/13] add memory parser
Date: Fri, 3 Feb 2023 14:44:20 +0100	[thread overview]
Message-ID: <d41ff642-c173-42ff-1467-2b6d5f744b92@proxmox.com> (raw)
In-Reply-To: <20230202110344.840195-5-aderumier@odiso.com>

Am 02.02.23 um 12:03 schrieb Alexandre Derumier:
> Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
> ---
>  PVE/API2/Qemu.pm          | 14 +++++--
>  PVE/QemuConfig.pm         |  4 +-
>  PVE/QemuMigrate.pm        |  6 ++-
>  PVE/QemuServer.pm         | 27 +++++++-------
>  PVE/QemuServer/Helpers.pm |  3 +-
>  PVE/QemuServer/Memory.pm  | 78 ++++++++++++++++++++++++++++++---------
>  6 files changed, 92 insertions(+), 40 deletions(-)
> 
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index 587bb22..6c08280 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -32,6 +32,7 @@ use PVE::QemuServer::Drive;
>  use PVE::QemuServer::ImportDisk;
>  use PVE::QemuServer::Monitor qw(mon_cmd);
>  use PVE::QemuServer::Machine;
> +use PVE::QemuServer::Memory qw(get_current_memory);
>  use PVE::QemuMigrate;
>  use PVE::RPCEnvironment;
>  use PVE::AccessControl;
> @@ -1489,8 +1490,6 @@ my $update_vm_api  = sub {
>  
>      my $storecfg = PVE::Storage::config();
>  
> -    my $defaults = PVE::QemuServer::load_defaults();
> -
>      &$resolve_cdrom_alias($param);
>  
>      # now try to verify all parameters
> @@ -1608,7 +1607,16 @@ my $update_vm_api  = sub {
>  	}
>  
>  	if ($param->{memory} || defined($param->{balloon})) {
> -	    my $maxmem = $param->{memory} || $conf->{pending}->{memory} || $conf->{memory} || $defaults->{memory};
> +
> +	    my $maxmem = undef;
> +	    if ($param->{memory}) {
> +	        $maxmem = get_current_memory($param->{memory});
> +	    } elsif ($conf->{pending}->{memory}) {
> +	        $maxmem = get_current_memory($conf->{pending}->{memory});
> +	    } else {
> +	        $maxmem = get_current_memory($conf->{memory});
> +	    }

Style nit: could be a one-liner
my $maxmem = get_current_memory($param->{memory} ||
$conf->{pending}->{memory} || $conf->{memory});

> +
>  	    my $balloon = defined($param->{balloon}) ? $param->{balloon} : $conf->{pending}->{balloon} || $conf->{balloon};
>  
>  	    die "balloon value too large (must be smaller than assigned memory)\n"

> diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm
> index 6bb931e..0704944 100644
> --- a/PVE/QemuServer/Memory.pm
> +++ b/PVE/QemuServer/Memory.pm
> @@ -8,10 +8,42 @@ use PVE::Exception qw(raise raise_param_exc);
>  
>  use PVE::QemuServer;
>  use PVE::QemuServer::Monitor qw(mon_cmd);
> +use base qw(Exporter);
> +
> +our @EXPORT_OK = qw(
> +get_current_memory
> +);
>  
>  my $MAX_NUMA = 8;
>  my $STATICMEM = 1024;
>  
> +our $memory_fmt = {
> +    current => {
> +	description => "Current amount of online RAM for the VM in MiB. This is the maximum available memory when"
> +	    ." you use the balloon device.",
> +	type => 'integer',
> +	default_key => 1,
> +	minimum => 16,
> +	default => 512,
> +    }

Style nit: missing comma

> +};
> +
> +sub print_memory {
> +    my $memory = shift;
> +
> +    return PVE::JSONSchema::print_property_string($memory, $memory_fmt);
> +}
> +
> +sub parse_memory {
> +    my ($value) = @_;
> +
> +    return { current => $memory_fmt->{current}->{default} } if !defined($value);
> +
> +    my $res = PVE::JSONSchema::parse_property_string($memory_fmt, $value)
> +	or die "Cannot parse memory properties: $value\n";

Nit: parse_property_string will only return something falsy if the
validator attached to the format does (which also shouldn't), so I don't
think the "or die" is required here.

> +    return $res;
> +}
> +
>  my $_host_bits;
>  my sub get_host_phys_address_bits {
>      return $_host_bits if defined($_host_bits);
> @@ -63,6 +95,13 @@ my sub get_max_mem {
>      return $bits_to_max_mem > 4*1024*1024 ? 4*1024*1024 : $bits_to_max_mem;
>  }
>  
> +sub get_current_memory {
> +    my ($value) = @_;
> +
> +    my $memory = parse_memory($value);
> +    return $memory->{current};
> +}
> +
>  sub get_numa_node_list {
>      my ($conf) = @_;
>      my @numa_map;
> @@ -155,16 +194,19 @@ sub foreach_reverse_dimm {
>  }
>  
>  sub qemu_memory_hotplug {
> -    my ($vmid, $conf, $defaults, $value) = @_;
> +    my ($vmid, $conf, $value) = @_;
>  
>      return $value if !PVE::QemuServer::check_running($vmid);
>  
> -    my $sockets = 1;
> -    $sockets = $conf->{sockets} if $conf->{sockets};
> +    my $oldmem = parse_memory($conf->{memory});
> +    my $newmem = parse_memory($value);
> +
> +    return $value if $newmem->{current} == $oldmem->{current};
>  
> -    my $memory = $conf->{memory} || $defaults->{memory};
> -    $value = $defaults->{memory} if !$value;
> -    return $value if $value == $memory;
> +    my $memory = $oldmem->{current};
> +    $value = $newmem->{current};
> +
> +    my $sockets = $conf->{sockets} || 1;

The refactoring of $sockets and below should be its own patch. While it
is small, it has nothing to do with the rest of the patch and the patch
already has quite a bit going on.

>  
>      my $static_memory = $STATICMEM;
>      $static_memory = $static_memory * $sockets if ($conf->{hugepages} && $conf->{hugepages} == 1024);
> @@ -496,12 +543,9 @@ sub hugepages_topology {
>  
>      return if !$conf->{numa};
>  
> -    my $defaults = PVE::QemuServer::load_defaults();
> -    my $memory = $conf->{memory} || $defaults->{memory};
> +    my $memory = get_current_memory($conf->{memory});
> +    my $sockets = $conf->{sockets} || 1;
>      my $static_memory = 0;
> -    my $sockets = 1;
> -    $sockets = $conf->{smp} if $conf->{smp}; # old style - no longer iused
> -    $sockets = $conf->{sockets} if $conf->{sockets};

below here

>      my $numa_custom_topology = undef;
>      my $hotplug_features = PVE::QemuServer::parse_hotplug_features(defined($conf->{hotplug}) ? $conf->{hotplug} : '1');
>  




  reply	other threads:[~2023-02-03 13:44 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 11:03 [pve-devel] [PATCH v3 qemu-server 00/13] rework memory hotplug + virtiomem Alexandre Derumier
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 01/13] memory: extract some code to their own sub for mocking Alexandre Derumier
2023-02-03 13:44   ` Fiona Ebner
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 02/13] tests: add memory tests Alexandre Derumier
2023-02-03 13:44   ` Fiona Ebner
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 03/13] qemu_memory_hotplug: remove unused $opt arg Alexandre Derumier
2023-02-03 13:56   ` [pve-devel] applied: " Fiona Ebner
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 04/13] add memory parser Alexandre Derumier
2023-02-03 13:44   ` Fiona Ebner [this message]
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 05/13] memory: add get_static_mem && remove parse_hotplug_features Alexandre Derumier
2023-02-03 13:44   ` Fiona Ebner
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 06/13] config: memory: add 'max' option Alexandre Derumier
2023-02-03 13:44   ` Fiona Ebner
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 07/13] memory: get_max_mem: use config memory max Alexandre Derumier
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 08/13] memory: don't use foreach_reversedimm for unplug Alexandre Derumier
2023-02-03 13:45   ` Fiona Ebner
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 09/13] memory: use 64 slots && static dimm size when max is defined Alexandre Derumier
2023-02-03 13:45   ` Fiona Ebner
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 10/13] test: add memory-max tests Alexandre Derumier
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 11/13] memory: add virtio-mem support Alexandre Derumier
2023-02-03 13:46   ` Fiona Ebner
2023-02-03 15:48     ` DERUMIER, Alexandre
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 12/13] memory: virtio-mem : implement redispatch retry Alexandre Derumier
2023-02-02 11:03 ` [pve-devel] [PATCH v3 qemu-server 13/13] tests: add virtio-mem tests Alexandre Derumier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d41ff642-c173-42ff-1467-2b6d5f744b92@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=aderumier@odiso.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal