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 5E8AC1FF0B0 for ; Fri, 09 Oct 2026 18:23:05 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id DBA212160B; Fri, 09 Oct 2026 18:23:00 +0200 (CEST) Message-ID: Date: Fri, 9 Oct 2026 18:22:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH guest-common v7 05/24] add module to track previously used guest IDs To: =?UTF-8?Q?Michael_K=C3=B6ppl?= , pve-devel@lists.proxmox.com References: <20261005144805.825538-1-m.koeppl@proxmox.com> <20261005144805.825538-6-m.koeppl@proxmox.com> Content-Language: en-US From: Fiona Ebner In-Reply-To: <20261005144805.825538-6-m.koeppl@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1791562976370 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.297 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) POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes 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: C5A5NPCTYLPSPG6V3KWXELK5OZ5WC5XT X-Message-ID-Hash: C5A5NPCTYLPSPG6V3KWXELK5OZ5WC5XT X-MailFrom: f.ebner@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: Am 05.10.26 um 4:50 PM schrieb Michael Köppl: > +my sub next_unused($ranges, $id) { > + my $next = $id; > + for my $range ($ranges->@*) { > + my ($start, $end) = $range->@*; > + next if $end < $next; > + last if $next < $start; > + $next = $end + 1; > + } > + return $next; > +} > + ---snip 8<--- > +} > + > +# Returns the lowest ID at or above $id that is neither taken by an > +# existing guest nor recorded as used before. > +sub get_next_unused_id($id) { > + my $ranges = cfs_read_file($FILENAME); > + my $vmlist = PVE::Cluster::get_vmlist() // {}; > + my $existing = $vmlist->{ids} // {}; > + > + $id = next_unused($ranges, $id); > + while (defined($existing->{$id})) { > + $id = next_unused($ranges, $id + 1); This one was found by our LLM auto-review: "Consider checking the scaling of get_next_unused_id() and retaining a range cursor: each existing guest whose ID was never recorded causes next_unused() to restart traversal of the historical ranges. This makes a request O(historical ranges × consecutive existing guests). For example, 100,000 isolated recorded IDs below lower=500000 fit below the file-size cap. If 10,000 pre-tracking guests occupy IDs 500000–509999, a single /cluster/nextid request performs roughly one billion range iterations, potentially tying up its API worker." I think we can just pass along $existing and check within the next_unused() function. Or even inline next_unused() if we switch assert_id_satisfies_next_id_settings() to use get_next_unused_id(), maybe with a param to ignore the existing guests, since that is already done on the call site, i.e. the nextid endpoint. But also wouldn't be expensive to consider them.