Am 13.02.23 um 13:00 schrieb Alexandre Derumier: > If some memory can be removed on a specific node, > we try to rebalance again on other nodes > > Signed-off-by: Alexandre Derumier <aderum...@odiso.com> > --- > PVE/QemuServer/Memory.pm | 51 +++++++++++++++++++++++++++------------- > 1 file changed, 35 insertions(+), 16 deletions(-) > > diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm > index bf4e92a..f02b4e0 100644 > --- a/PVE/QemuServer/Memory.pm > +++ b/PVE/QemuServer/Memory.pm > @@ -201,13 +201,28 @@ my sub get_virtiomem_total_current_size { > return $size; > } > > +my sub get_virtiomem_total_errors_size { > + my ($mems) = @_; > + > + my $size = 0; > + for my $mem (values %$mems) { > + next if !$mem->{error}; > + $size += $mem->{current}; > + } > + return $size; > +} > + > my sub balance_virtiomem { > my ($vmid, $virtiomems, $blocksize, $target_total) = @_; > > - my $nb_virtiomem = scalar(keys %$virtiomems); > + my $nb_virtiomem = scalar(grep { !$_->{error} } values $virtiomems->%*); > > print"try to balance memory on $nb_virtiomem virtiomems\n"; > > + die "No more available blocks in virtiomem to balance all requested > memory\n" > + if $target_total < 0;
I fee like this message is a bit confusing. This can only happen on unplug, right? And reading that "no more blocks are available" sounds like a paradox then. It's rather that no more blocks can be unplugged. If we really want to, if the $target_total is negative, we could set it to 0 (best to do it at the call-side already) and try to unplug everything else? We won't reach the goal anymore, but we could still get closer to it in some cases. Would need a bit more adaptation to avoid an endless loop: we also need to stop if all devices reached their current goal this round (and no new errors appeared), e.g. balance_virtiomem() could just have that info as its return value. Example: > update VM 101: -memory 4100,max=65536,virtio=1 > try to balance memory on 2 virtiomems > virtiomem0: set-requested-size : 0 > virtiomem1: set-requested-size : 4 > virtiomem1: last: 4 current: 4 target: 4 > virtiomem1: completed > virtiomem0: last: 16 current: 16 target: 0 > virtiomem0: increase retry: 0 > virtiomem0: last: 16 current: 16 target: 0 > virtiomem0: increase retry: 1 > virtiomem0: last: 16 current: 16 target: 0 > virtiomem0: increase retry: 2 > virtiomem0: last: 16 current: 16 target: 0 > virtiomem0: increase retry: 3 > virtiomem0: last: 16 current: 16 target: 0 > virtiomem0: increase retry: 4 > virtiomem0: last: 16 current: 16 target: 0 > virtiomem0: too many retry. set error > virtiomem0: increase retry: 5 Currently it stops here, but with setting $target_total = 0 it continues... > try to balance memory on 1 virtiomems > virtiomem1: set-requested-size : 0 > virtiomem1: last: 4 current: 0 target: 0 > virtiomem1: completed ...and gets closer to the goal... > try to balance memory on 1 virtiomems > virtiomem1: set-requested-size : 0 > virtiomem1: last: 4 current: 0 target: 0 > virtiomem1: completed > try to balance memory on 1 virtiomems > virtiomem1: set-requested-size : 0 > virtiomem1: last: 4 current: 0 target: 0 > virtiomem1: completed ...but then it loops, because I didn't add the other stop condition yet ;). But not sure, likely too much magic. > + die "No more available virtiomem to balance the remaining memory\n" if > $nb_virtiomem == 0; "No more virtiomem devices left to try to ..." might be a bit clearer. Technically, they are still available, we just ignore them because they don't reach the target in time. > + > #if we can't share exactly the same amount, we add the remainder on last > node > my $target_aligned = int( $target_total / $nb_virtiomem / $blocksize) * > $blocksize; > my $target_remaining = $target_total - ($target_aligned * > ($nb_virtiomem-1)); _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel