From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id A971B1FF0DF for ; Fri, 28 Aug 2026 14:32:53 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id EBC08214E0; Fri, 28 Aug 2026 14:32:50 +0200 (CEST) From: Dominik Rusovac To: pve-devel@lists.proxmox.com Subject: [PATCH pve-ha-manager 2/2] fix #7974: env: pve2: set dynamic service mem value to host memory usage Date: Fri, 28 Aug 2026 14:32:39 +0200 Message-ID: <20260828123239.1110595-2-d.rusovac@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260828123239.1110595-1-d.rusovac@proxmox.com> References: <20260828123239.1110595-1-d.rusovac@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1787920355185 X-SPAM-LEVEL: Spam detection results: 0 DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: CI5CSQLWWVCPZ5I4J5PMOGESBTKW2HKK X-Message-ID-Hash: CI5CSQLWWVCPZ5I4J5PMOGESBTKW2HKK X-MailFrom: d.rusovac@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Make memory accounting in dynamic CRS consistent. Atm the imbalance value that triggers rebalancing is derived from the guests' host memory usage, which corresponds to the respective host-side cgroup footprints of the guests. However, the scheduler's decision procedure predicts the changes in imbalance caused by migration candidates based on memory usage (inside the guests). This discrepancy can lead to oscillating migrations, as described in detail in [0]. For VMs, host memory usage is the relevant stat, as it better describes the actual cost of running on a node than memory usage. Host memory usage is not available for containers, so fall back to memory usage for containers. [0] https://bugzilla.proxmox.com/show_bug.cgi?id=7974 Signed-off-by: Dominik Rusovac --- src/PVE/HA/Env/PVE2.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm index 782d19d..5f195da 100644 --- a/src/PVE/HA/Env/PVE2.pm +++ b/src/PVE/HA/Env/PVE2.pm @@ -46,6 +46,7 @@ use constant { RRD_VM_INDEX_CPU => 6, RRD_VM_INDEX_MAXMEM => 7, RRD_VM_INDEX_MEM => 8, + RRD_VM_INDEX_MEMHOST => 15, }; # rrd entry indices for PVE nodes @@ -598,11 +599,14 @@ sub get_dynamic_service_stats { # NOTE the guests' broadcasted vmstatus() caps maxcpu at the node's maxcpu my $maxcpu = ($rrdentry->[RRD_VM_INDEX_MAXCPU] || 0.0) + 0.0; + # designated fallback for containers + my $mem = $rrdentry->[RRD_VM_INDEX_MEMHOST] // $rrdentry->[RRD_VM_INDEX_MEM]; + $stats->{$sid}->{usage} = { maxcpu => $maxcpu, cpu => (($rrdentry->[RRD_VM_INDEX_CPU] || 0.0) + 0.0) * $maxcpu, maxmem => int($rrdentry->[RRD_VM_INDEX_MAXMEM] || 0), - mem => int($rrdentry->[RRD_VM_INDEX_MEM] || 0), + mem => int($mem || 0), }; } -- 2.47.3