[pve-devel] [RFC v1/2 manager] pvestatd: add simple container cpuset balancing

Dietmar Maurer dietmar at proxmox.com
Mon Oct 24 06:42:46 CEST 2016


just a side note.

I see that you try to avoid using sort(), and I fully agree
that this is nice to have if you work on larger datasets.
But we have very few entries, so I would prefer using sort().


> +	# We need to keep cpus_by_count sorted:
> +	# 1) Since cpus can only be used once the order does not need to be
> +	# changed if we walked up to the last cpu in the sorted list:
> +	next if $i >= @cpus_by_count;
> +
> +	my $lastcpu = $cpus_by_count[$i-1];
> +	my $nextcpu = $cpus_by_count[$i];
> +	my $count = $cpu_ctcount[$nextcpu];
> +	# 2) If the next count is equal to the bumped-up count of the last cpu
> +	# we assigned the container to, the order is still fine, too.
> +	next if $count >= $cpu_ctcount[$lastcpu];
> +
> +	# 3) Find the range of cpus we need to sort forward. Under our
> +	# conditions this translates to finding the next cpu with a different
> +	# count (since they're sorted and adding even just 1 means we're equal
> +	# to the last assigned cpu).
> +	# (This should be a stable sort with respect to equally-utilized cpus)
> +	my $from = $i;
> +	++$i;
> +	while ($i < @cpus_by_count &&
> +	       $cpu_ctcount[$cpus_by_count[$i]] == $count) {
> +	    ++$i;
> +	}
> +	my $to = $i;
> +
> +	# 3) find the last cpu with a count lower than or equal to the first
> +	# one we want to move:
> +	$i = $from-1;
> +	while ($i && $cpu_ctcount[$cpus_by_count[$i]] > $count) {
> +	    --$i;
> +	}
> +
> +	# 4) Move:
> +	my @range = (@cpus_by_count[$from..($to-1)]);
> +	splice @cpus_by_count, $from, $to-$from;




More information about the pve-devel mailing list