[pve-devel] [PATCH manager] use rebalance_lxc_containers from PVE::LXC
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Nov 17 11:27:20 CET 2016
---
PVE/Service/pvestatd.pm | 120 +-----------------------------------------------
1 file changed, 1 insertion(+), 119 deletions(-)
diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index 3774833..860d97a 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -222,124 +222,6 @@ sub remove_stale_lxc_consoles {
}
}
-sub rebalance_lxc_containers {
-
- return if !-d '/sys/fs/cgroup/cpuset/lxc'; # nothing to do...
-
- my $all_cpus = PVE::CpuSet->new_from_cgroup('lxc', 'effective_cpus');
- my @allowed_cpus = $all_cpus->members();
- my $cpucount = scalar(@allowed_cpus);
- my $max_cpuid = PVE::CpuSet::max_cpuid();
-
- my @cpu_ctcount = (0) x $max_cpuid;
- my @balanced_cts;
-
- my $ctlist = PVE::LXC::config_list();
-
- foreach my $vmid (sort keys %$ctlist) {
- next if ! -d "/sys/fs/cgroup/cpuset/lxc/$vmid";
-
- my ($conf, $cpuset);
- eval {
-
- $conf = PVE::LXC::Config->load_config($vmid);
-
- $cpuset = PVE::CpuSet->new_from_cgroup("lxc/$vmid");
- };
- if (my $err = $@) {
- warn $err;
- next;
- }
-
- my @cpuset_members = $cpuset->members();
-
- if (!PVE::LXC::Config->has_lxc_entry($conf, 'lxc.cgroup.cpuset.cpus')) {
-
- my $cores = $conf->{cores} || $cpucount;
- $cores = $cpucount if $cores > $cpucount;
-
- # see if the number of cores was hot-reduced or
- # hasn't been enacted at all yet
- my $newset = PVE::CpuSet->new();
- if ($cores < scalar(@cpuset_members)) {
- for (my $i = 0; $i < $cores; $i++) {
- $newset->insert($cpuset_members[$i]);
- }
- } elsif ($cores > scalar(@cpuset_members)) {
- my $count = $newset->insert(@cpuset_members);
- foreach my $cpu (@allowed_cpus) {
- $count += $newset->insert($cpu);
- last if $count >= $cores;
- }
- } else {
- $newset->insert(@cpuset_members);
- }
-
- # Apply hot-plugged changes if any:
- if (!$newset->is_equal($cpuset)) {
- @cpuset_members = $newset->members();
- syslog('info', "detected changed cpu set for lxc/$vmid: " .
- $newset->short_string());
- $newset->write_to_cgroup("lxc/$vmid");
- }
-
- # Note: no need to rebalance if we already use all cores
- push @balanced_cts, [$vmid, $cores, $newset]
- if defined($conf->{cores}) && ($cores != $cpucount);
- }
-
- foreach my $cpu (@cpuset_members) {
- $cpu_ctcount[$cpu]++ if $cpu <= $max_cpuid;
- }
- }
-
- my $find_best_cpu = sub {
- my ($cpulist, $cpu) = @_;
-
- my $cur_cost = $cpu_ctcount[$cpu];
- my $cur_cpu = $cpu;
-
- foreach my $candidate (@$cpulist) {
- my $cost = $cpu_ctcount[$candidate];
- if ($cost < ($cur_cost -1)) {
- $cur_cost = $cost;
- $cur_cpu = $candidate;
- }
- }
-
- return $cur_cpu;
- };
-
- foreach my $bct (@balanced_cts) {
- my ($vmid, $cores, $cpuset) = @$bct;
-
- my $newset = PVE::CpuSet->new();
-
- my $rest = [];
- foreach my $cpu (@allowed_cpus) {
- next if $cpuset->has($cpu);
- push @$rest, $cpu;
- }
-
- my @members = $cpuset->members();
- foreach my $cpu (@members) {
- my $best = &$find_best_cpu($rest, $cpu);
- if ($best != $cpu) {
- $cpu_ctcount[$best]++;
- $cpu_ctcount[$cpu]--;
- }
- $newset->insert($best);
- }
-
- if (!$newset->is_equal($cpuset)) {
- syslog('info', "modified cpu set for lxc/$vmid: " .
- $newset->short_string());
- eval { $newset->write_to_cgroup("lxc/$vmid"); };
- warn $@ if $@;
- }
- }
-}
-
sub update_lxc_status {
my ($status_cfg) = @_;
@@ -435,7 +317,7 @@ sub update_status {
syslog('err', "lxc status update error: $err") if $err;
eval {
- rebalance_lxc_containers();
+ PVE::LXC::rebalance_lxc_containers();
};
$err = $@;
syslog('err', "lxc cpuset rebalance error: $err") if $err;
--
2.1.4
More information about the pve-devel
mailing list