From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 143291FF0C0 for ; Wed, 21 Oct 2026 10:59:54 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id D838E2167C; Wed, 21 Oct 2026 10:59:41 +0200 (CEST) From: Dominik Rusovac To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox 02/15] resource-scheduling: scheduler: abstract post-migration stats logic Date: Wed, 21 Oct 2026 10:59:19 +0200 Message-ID: <20261021085932.1196302-3-d.rusovac@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261021085932.1196302-1-d.rusovac@proxmox.com> References: <20261021085932.1196302-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: 1792573177023 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.164 Adjusted score from AWL reputation of From: address 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: PBTWGPGWX2IBALCXERCVMCMDPFYJP2S4 X-Message-ID-Hash: PBTWGPGWX2IBALCXERCVMCMDPFYJP2S4 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: DRY and hide repeatedly used closure inside reuasble function. Signed-off-by: Dominik Rusovac --- proxmox-resource-scheduling/src/scheduler.rs | 41 ++++++++------------ 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/proxmox-resource-scheduling/src/scheduler.rs b/proxmox-resource-scheduling/src/scheduler.rs index 9078fa72..a12cd519 100644 --- a/proxmox-resource-scheduling/src/scheduler.rs +++ b/proxmox-resource-scheduling/src/scheduler.rs @@ -56,6 +56,19 @@ fn calculate_node_imbalance(nodes: &[NodeUsage], to_load: impl Fn(&NodeUsage) -> cv / max_cv } +/// Returns the hypothetical [`NodeStats`] of `node` with respect to the migration `candidate`. +fn node_stats_after_migration(candidate: &MigrationCandidate, node: &NodeUsage) -> NodeStats { + let mut new_stats = node.stats; + + if node.name == candidate.migration.source_node { + new_stats.remove_running_resource(&candidate.stats); + } else if node.name == candidate.migration.target_node { + new_stats.add_running_resource(&candidate.stats); + } + + new_stats +} + criteria_struct! { /// A given alternative. struct PveTopsisAlternative { @@ -216,15 +229,7 @@ impl Scheduler { /// See [`calculate_node_imbalance`] for more information. fn node_imbalance_with_migration_candidate(&self, candidate: &MigrationCandidate) -> f64 { calculate_node_imbalance(&self.nodes, |node| { - let mut new_stats = node.stats; - - if node.name == candidate.migration.source_node { - new_stats.remove_running_resource(&candidate.stats); - } else if node.name == candidate.migration.target_node { - new_stats.add_running_resource(&candidate.stats); - } - - new_stats.load() + node_stats_after_migration(candidate, node).load() }) } @@ -288,22 +293,8 @@ impl Scheduler { let matrix = candidates .iter() .map(|candidate| { - let resource_stats = &candidate.stats; - let source_node = &candidate.migration.source_node; - let target_node = &candidate.migration.target_node; - - self.topsis_alternative_with(|node| { - let mut new_stats = node.stats; - - if &node.name == source_node { - new_stats.remove_running_resource(resource_stats); - } else if &node.name == target_node { - new_stats.add_running_resource(resource_stats); - } - - new_stats - }) - .into() + self.topsis_alternative_with(|node| node_stats_after_migration(candidate, node)) + .into() }) .collect::>(); -- 2.47.3