From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, "aderumier@odiso.com" <aderumier@odiso.com>
Subject: Re: [pve-devel] [PATCH v2 qemu-server 2/9] add memory parser
Date: Tue, 24 Jan 2023 14:04:48 +0100 [thread overview]
Message-ID: <68928d13-7bd1-90bc-88e7-5db7f727637a@proxmox.com> (raw)
In-Reply-To: <20230104064303.2898194-3-aderumier@odiso.com>
Am 04.01.23 um 07:42 schrieb Alexandre Derumier:
> Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
> ---
> PVE/API2/Qemu.pm | 12 ++++++-
> PVE/QemuConfig.pm | 4 +--
> PVE/QemuMigrate.pm | 6 ++--
> PVE/QemuServer.pm | 24 ++++++-------
> PVE/QemuServer/Helpers.pm | 3 +-
> PVE/QemuServer/Memory.pm | 74 ++++++++++++++++++++++++++++++++-------
> 6 files changed, 91 insertions(+), 32 deletions(-)
>
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index c87602d..4ffa973 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;
> @@ -1608,7 +1609,16 @@ my $update_vm_api = sub {
> }
>
> if ($param->{memory} || defined($param->{balloon})) {
> - my $maxmem = $param->{memory} || $conf->{pending}->{memory} || $conf->{memory} || $defaults->{memory};
Nit: seems like this was the only usage of $defaults in the whole
function, so the variable could be removed too
> +
> + 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});
> + }
> +
> 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.pm b/PVE/QemuServer.pm
> index 39fc6b0..5847a78 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
(...)
> @@ -5113,7 +5110,7 @@ sub vmconfig_hotplug_pending {
> $vmid, $opt, $value, $arch, $machine_type);
> } elsif ($opt =~ m/^memory$/) { #dimms
> die "skip\n" if !$hotplug_features->{memory};
> - $value = PVE::QemuServer::Memory::qemu_memory_hotplug($vmid, $conf, $defaults, $opt, $value);
> + PVE::QemuServer::Memory::qemu_memory_hotplug($vmid, $conf, $defaults, $conf->{pending}->{$opt});
By removing the assignment to $value here, the passed-in value will be
written to the config below, which does not reflect reality. This is a
breaking change:
root@pve701 ~ # qm set 131 --memory 1024
update VM 131: -memory 1024
root@pve701 ~ # cat /etc/pve/qemu-server/131.conf | grep memory:
memory: 1024
root@pve701 ~ # qm start 131
root@pve701 ~ # qm set 131 --memory 1025
update VM 131: -memory 1025
root@pve701 ~ # cat /etc/pve/qemu-server/131.conf | grep memory:
memory: 1025
But it really is 1536, because a 512M dimm was added. And now, because
the value is wrong, the following (or with any higher value) fails:
root@pve701 ~ # qm set 131 --memory 1026
update VM 131: -memory 1026
400 Parameter verification failed.
memory: hotplug problem - VM 131 qmp command 'object-add' failed -
attempt to add duplicate property 'mem-dimm0' to object (type 'container')
qm set <vmid> [OPTIONS]
While the current behavior is arguably also a bit surprising, it
reflects the actual values, and doesn't fail:
root@pve701 ~ # qm set 131 --memory 1024
update VM 131: -memory 1024
root@pve701 ~ # cat /etc/pve/qemu-server/131.conf | grep memory:
memory: 1024
root@pve701 ~ # qm start 131
root@pve701 ~ # qm set 131 --memory 1025
update VM 131: -memory 1025
root@pve701 ~ # cat /etc/pve/qemu-server/131.conf | grep memory:
memory: 1536
root@pve701 ~ # qm set 131 --memory 1026
update VM 131: -memory 1026
try to unplug memory dimm dimm0
root@pve701 ~ # cat /etc/pve/qemu-server/131.conf | grep memory:
memory: 1024
Why not keep assigning and returning the value from
qemu_memory_hotplug() in the cases it's not already written there?
> } elsif ($opt eq 'cpuunits') {
> my $new_cpuunits = PVE::CGroup::clamp_cpu_shares($conf->{pending}->{$opt}); #clamp
> $cgroup->change_cpu_shares($new_cpuunits);
(...)
> diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm
> index 6c1cd94..59e51c8 100644
> --- a/PVE/QemuServer/Memory.pm
> +++ b/PVE/QemuServer/Memory.pm
> @@ -8,10 +8,45 @@ 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;
>
> +my $memory_fmt = {
Since QemuServer.pm references it, shouldn't it be 'our'?
> + current => {
> + description => "Current amount of online RAM for the VM in MB. This is the maximum available memory when"
> + ." you use the balloon device.",
> + type => 'integer',
> + default_key => 1,
> + optional => 1,
Why optional?
> + minimum => 16,
> + default => 512,
> + }
> +};
> +
> +sub print_memory {
> + my $memory = shift;
> +
> + return PVE::JSONSchema::print_property_string($memory, $memory_fmt);
> +}
> +
> +sub parse_memory {
> + my ($value) = @_;
> +
> + my $current_default = $memory_fmt->{current}->{default};
> + my $res = { current => $current_default };
> + return $res if !defined($value);
Style nit: Could be one line:
return { current => $memory_fmt->{current}->{default} } if !defined($value).
> +
> + $res = eval { PVE::JSONSchema::parse_property_string($memory_fmt, $value) };
> + die $@ if $@;
Style nit: No need for eval+die if the error is just passed on as-is
> + return $res;
> +}
> +
> my $_host_bits;
> my sub get_host_phys_address_bits {
> return $_host_bits if defined($_host_bits);
> @@ -63,6 +98,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,17 +197,21 @@ sub foreach_reverse_dimm {
> }
>
> sub qemu_memory_hotplug {
> - my ($vmid, $conf, $defaults, $opt, $value) = @_;
> + my ($vmid, $conf, $defaults, $value) = @_;
Removing the unused $opt from qemu_memory_hotplug() could also be its
own patch.
> +
> + return if !PVE::QemuServer::check_running($vmid);
>
> - return $value if !PVE::QemuServer::check_running($vmid);
> + my $oldmem = parse_memory($conf->{memory});
> + my $newmem = parse_memory($value);
> +
> + my $memory = $oldmem->{current};
> + $value = $newmem->{current};
> +
> + return if $value == $memory;
>
> my $sockets = 1;
> $sockets = $conf->{sockets} if $conf->{sockets};
>
> - my $memory = $conf->{memory} || $defaults->{memory};
> - $value = $defaults->{memory} if !$value;
> - return $value if $value == $memory;
> -
> my $static_memory = $STATICMEM;
> $static_memory = $static_memory * $sockets if ($conf->{hugepages} && $conf->{hugepages} == 1024);
>
(...)
> @@ -270,7 +319,8 @@ sub qemu_dimm_list {
> sub config {
> my ($conf, $vmid, $sockets, $cores, $defaults, $hotplug_features, $cmd) = @_;>
The $defaults parameter can be dropped now
> - my $memory = $conf->{memory} || $defaults->{memory};
> + my $memory = get_current_memory($conf->{memory});
> +
> my $static_memory = 0;
>
> if ($hotplug_features->{memory}) {
(...)
next prev parent reply other threads:[~2023-01-24 13:05 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-04 6:42 [pve-devel] [PATCH v2 qemu-server 0/9] rework memory hotplug + virtiomem Alexandre Derumier
2023-01-04 6:42 ` [pve-devel] [PATCH v2 qemu-server 1/9] test: add memory tests Alexandre Derumier
2023-01-24 13:04 ` Fiona Ebner
2023-01-04 6:42 ` [pve-devel] [PATCH v2 qemu-server 2/9] add memory parser Alexandre Derumier
2023-01-24 13:04 ` Fiona Ebner [this message]
2023-01-04 6:42 ` [pve-devel] [PATCH v2 qemu-server 3/9] memory: add get_static_mem Alexandre Derumier
2023-01-24 13:04 ` Fiona Ebner
2023-01-04 6:42 ` [pve-devel] [PATCH v2 qemu-server 4/9] config: memory: add 'max' option Alexandre Derumier
2023-01-24 13:05 ` Fiona Ebner
2023-01-27 15:03 ` DERUMIER, Alexandre
2023-01-30 8:03 ` Fiona Ebner
2023-01-30 8:45 ` DERUMIER, Alexandre
2023-01-04 6:42 ` [pve-devel] [PATCH v2 qemu-server 5/9] memory: get_max_mem: use config memory max Alexandre Derumier
2023-01-24 13:05 ` Fiona Ebner
2023-01-27 15:15 ` DERUMIER, Alexandre
2023-01-30 8:04 ` Fiona Ebner
2023-01-04 6:43 ` [pve-devel] [PATCH v2 qemu-server 6/9] memory: use 64 slots && static dimm size when max is defined Alexandre Derumier
2023-01-24 13:06 ` Fiona Ebner
2023-01-27 15:52 ` DERUMIER, Alexandre
2023-01-04 6:43 ` [pve-devel] [PATCH v2 qemu-server 7/9] test: add memory-max tests Alexandre Derumier
2023-01-24 13:06 ` Fiona Ebner
2023-01-04 6:43 ` [pve-devel] [PATCH v2 qemu-server 8/9] memory: add virtio-mem support Alexandre Derumier
2023-01-24 13:06 ` Fiona Ebner
2023-01-25 9:00 ` DERUMIER, Alexandre
2023-01-25 9:54 ` Fiona Ebner
2023-01-25 10:28 ` DERUMIER, Alexandre
2023-01-25 10:52 ` Fiona Ebner
2023-01-04 6:43 ` [pve-devel] [PATCH v2 qemu-server 9/9] tests: add virtio-mem tests Alexandre Derumier
2023-01-24 13:08 ` Fiona Ebner
2023-01-24 13:08 ` [pve-devel] [PATCH v2 qemu-server 0/9] rework memory hotplug + virtiomem Fiona Ebner
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=68928d13-7bd1-90bc-88e7-5db7f727637a@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal