From: Michael Ryom <Michael@RyomHerold.dk>
To: pve-devel@lists.proxmox.com
Cc: Michael Ryom <Michael@RyomHerold.dk>
Subject: [PATCH ha-manager v2 08/14] manager: auto rebalance: allow an absolute margin
Date: Sun, 18 Oct 2026 14:45:52 +0200 [thread overview]
Message-ID: <20261018124559.24305-9-Michael@RyomHerold.dk> (raw)
In-Reply-To: <20261018124559.24305-1-Michael@RyomHerold.dk>
The automatic load balancer only requires a relative improvement of the
node imbalance (default 10%). When a single resource dominates the
cluster load, the relative margin provides almost no hysteresis: with
two nodes, a resource load v and a node base load difference d, the
relative improvement of moving the resource is 2d / (v + d), so it
exceeds a margin m as soon as d > v * m / (2 - m). For a mid-size VM
that is a base load difference of about half a percentage point, well
within the normal fluctuation of e.g. the ZFS ARC or Ceph daemons, and
each fluctuation then qualifies a motion (and, after it was carried
out, its reverse) (see bug #8059).
Add the ha-auto-rebalance-margin-mode option, which allows to interpret
the existing margin as the minimum absolute improvement in percentage
points instead. This creates a dead band for motions that shuffle load
without meaningfully improving the cluster balance. The relative margin
was introduced when the imbalance was not yet bounded for different
cluster sizes; now that it is in [0, 1] for all cluster sizes, an
absolute margin is meaningful on its own.
The margin mode defaults to 'relative', i.e. the behavior of existing
setups does not change.
The expected log of test-crs-dynamic-auto-rebalance8 changes, as the
improvement of 4.4 percentage points of migrating vm:101 is below the
configured absolute margin of 5 percentage points.
Signed-off-by: Michael Ryom <Michael@RyomHerold.dk>
---
src/PVE/HA/Manager.pm | 14 ++++++++++----
.../test-crs-dynamic-auto-rebalance8/log.expect | 9 ---------
2 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/src/PVE/HA/Manager.pm b/src/PVE/HA/Manager.pm
index c480b73..b804602 100644
--- a/src/PVE/HA/Manager.pm
+++ b/src/PVE/HA/Manager.pm
@@ -141,6 +141,8 @@ sub update_crs_scheduler_mode {
// 3;
$self->{crs}->{auto_rebalance}->{margin} =
($crs_cfg->{'ha-auto-rebalance-margin'} // 10) / 100.0;
+ $self->{crs}->{auto_rebalance}->{margin_mode} = $crs_cfg->{'ha-auto-rebalance-margin-mode'}
+ // 'relative';
$self->{crs}->{auto_rebalance}->{cooldown} = $crs_cfg->{'ha-auto-rebalance-cooldown'} // 0;
my $old_mode = $self->{crs}->{scheduler};
@@ -370,8 +372,8 @@ sub load_balance {
return if $self->any_resource_motion_queued_or_running();
- my ($threshold, $method, $hold_duration, $margin) =
- $auto_rebalance_opts->@{qw(threshold method hold_duration margin)};
+ my ($threshold, $method, $hold_duration, $margin, $margin_mode) =
+ $auto_rebalance_opts->@{qw(threshold method hold_duration margin margin_mode)};
# with threshold and margin both at 0% any non-zero imbalance triggers a non-improving
# migration, churning the cluster forever - skip and warn instead of silently looping.
@@ -421,8 +423,12 @@ sub load_balance {
my ($migration, $target_imbalance) = $result->@{qw(migration imbalance)};
- my $relative_change = ($imbalance - $target_imbalance) / $imbalance;
- return if $relative_change < $margin;
+ # the relative margin alone provides almost no hysteresis if a single resource
+ # dominates the cluster load, so tiny fluctuations of the node base loads can
+ # make a motion and its reverse qualify; an absolute margin guards against it
+ my $absolute_change = $imbalance - $target_imbalance;
+ my $change = $margin_mode eq 'absolute' ? $absolute_change : $absolute_change / $imbalance;
+ return if $change < $margin;
my ($sid, $source, $target) = $migration->@{qw(sid source-node target-node)};
diff --git a/src/test/test-crs-dynamic-auto-rebalance8/log.expect b/src/test/test-crs-dynamic-auto-rebalance8/log.expect
index df11212..6c84e42 100644
--- a/src/test/test-crs-dynamic-auto-rebalance8/log.expect
+++ b/src/test/test-crs-dynamic-auto-rebalance8/log.expect
@@ -27,13 +27,4 @@ info 23 node2/lrm: got lock 'ha_agent_node2_lock'
info 23 node2/lrm: status change wait_for_agent_lock => active
info 23 node2/lrm: starting service vm:200
info 23 node2/lrm: service status vm:200 started
-info 80 node1/crm: auto rebalance - migrate vm:101 to node2 (expected change for imbalance from 35.6% to 31.1%)
-info 80 node1/crm: got crm command: migrate vm:101 node2
-info 80 node1/crm: migrate service 'vm:101' to node 'node2'
-info 80 node1/crm: service 'vm:101': state changed from 'started' to 'migrate' (node = node1, target = node2)
-info 81 node1/lrm: service vm:101 - start migrate to node 'node2'
-info 81 node1/lrm: service vm:101 - end migrate to node 'node2'
-info 100 node1/crm: service 'vm:101': state changed from 'migrate' to 'started' (node = node2)
-info 103 node2/lrm: starting service vm:101
-info 103 node2/lrm: service status vm:101 started
info 620 hardware: exit simulation - done
--
2.47.3
next prev parent reply other threads:[~2026-10-18 12:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 12:45 [PATCH cluster/ha-manager/manager/docs v2 00/14] auto rebalance: fix failure retry loop and oscillation Michael Ryom
2026-10-18 12:45 ` [PATCH cluster v2 01/14] datacenter config: add HA auto-rebalance margin mode and cooldown Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 02/14] manager: factor out checking whether a resource motion is queued or running Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 03/14] test: add auto rebalance test cases for failing rebalance motions Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 04/14] fix #8059: manager: auto rebalance: do not retry failed rebalance motions right away Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 05/14] test: add auto rebalance test case for an immediate reverse motion Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 06/14] manager: auto rebalance: add optional cooldown for moved resources Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 07/14] test: add auto rebalance test case for a marginal absolute improvement Michael Ryom
2026-10-18 12:45 ` Michael Ryom [this message]
2026-10-18 12:45 ` [PATCH ha-manager v2 09/14] sim: hardware: report actual running state in cluster service stats Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 10/14] sim: hardware: allow setting a base load for nodes Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 11/14] test: add auto rebalance test case for fluctuating node base loads Michael Ryom
2026-10-18 12:45 ` [PATCH ha-manager v2 12/14] usage: dynamic: smooth the unaccounted node load Michael Ryom
2026-10-18 12:45 ` [PATCH manager v2 13/14] ui: crs options: expose the auto-rebalance margin mode and cooldown Michael Ryom
2026-10-18 12:45 ` [PATCH docs v2 14/14] ha-manager: document the auto-rebalance margin mode, cooldown and failed migrations Michael Ryom
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=20261018124559.24305-9-Michael@RyomHerold.dk \
--to=michael@ryomherold.dk \
--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.