X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FCGroup.pm;h=dd9b034c5872eca57292b3a13abae7e5a11d16c5;hp=45b9e7c12a0b7a426b09851e64caf5d5d97dd987;hb=d37a71867233a09803e825f0249a1c7df8be25a0;hpb=9465abe251ae62a9938564394dbbef4f350fee0c diff --git a/src/PVE/CGroup.pm b/src/PVE/CGroup.pm index 45b9e7c..dd9b034 100644 --- a/src/PVE/CGroup.pm +++ b/src/PVE/CGroup.pm @@ -341,13 +341,11 @@ sub get_memory_stat { } elsif ($ver == 2) { my $mem = file_get_contents("$path/memory.current"); my $swap = file_get_contents("$path/memory.swap.current"); + my $stat = parse_flat_keyed_file(file_get_contents("$path/memory.stat")); chomp ($mem, $swap); - # FIXME: For the cgv1 equivalent of `total_cache` we may need to sum up - # the values in `memory.stat`... - - $res->{mem} = $mem; + $res->{mem} = $mem - $stat->{file}; $res->{swap} = $swap; } elsif ($ver == 1) { # cgroupv1 environment: @@ -365,6 +363,40 @@ sub get_memory_stat { return $res; } +sub get_pressure_stat { + my ($self) = @_; + + my $res = { + cpu => { + some => { avg10 => 0, avg60 => 0, avg300 => 0 } + }, + memory => { + some => { avg10 => 0, avg60 => 0, avg300 => 0 }, + full => { avg10 => 0, avg60 => 0, avg300 => 0 } + }, + io => { + some => { avg10 => 0, avg60 => 0, avg300 => 0 }, + full => { avg10 => 0, avg60 => 0, avg300 => 0 } + }, + }; + + my ($path, $version) = $self->get_path(undef, 1); + if (!defined($path)) { + return $res; # container or VM most likely isn't running, retrun zero stats + } elsif ($version == 1) { + return undef; # v1 controller does not provides pressure stat + } elsif ($version == 2) { + for my $type (qw(cpu memory io)) { + my $stats = PVE::ProcFSTools::parse_pressure("$path/$type.pressure"); + $res->{$type} = $stats if $stats; + } + } else { + die "bad cgroup version: $version\n"; + } + + return $res; +} + # Change the memory limit for this container. # # Dies on error (including a not-running or currently-shutting-down guest). @@ -435,8 +467,8 @@ sub change_cpu_quota { PVE::ProcFSTools::write_proc_entry("$path/cpu.max", 'max'); } } elsif ($ver == 1) { - $quota //= -1; # unlimited - $period //= -1; + $quota //= -1; # default (unlimited) + $period //= 100_000; # default (100 ms) PVE::ProcFSTools::write_proc_entry("$path/cpu.cfs_period_us", $period); PVE::ProcFSTools::write_proc_entry("$path/cpu.cfs_quota_us", $quota); } else { @@ -472,7 +504,7 @@ sub change_cpu_shares { die "cpu weight (shares) must be in range [1, 10000]\n" if $shares < 1 || $shares > 10000; PVE::ProcFSTools::write_proc_entry("$path/cpu.weight", $shares); } elsif ($ver == 1) { - $shares //= 100; + $shares //= 1024; PVE::ProcFSTools::write_proc_entry("$path/cpu.shares", $shares // $cgroupv1_default); } else { die "bad cgroup version: $ver\n";