On 16/04/2024 14:20, Fabian Grünbichler wrote: > to avoid repeating those calculations all over the place. > > Signed-off-by: Fabian Grünbichler > --- > src/PVE/LXC/Config.pm | 35 +++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm > index 1664a35..a6baccd 100644 > --- a/src/PVE/LXC/Config.pm > +++ b/src/PVE/LXC/Config.pm > @@ -11,6 +11,7 @@ use PVE::DataCenterConfig; > use PVE::GuestHelpers; > use PVE::INotify; > use PVE::JSONSchema qw(get_standard_option); > +use PVE::ProcFSTools; > use PVE::Tools; > > use PVE::LXC; > @@ -1886,4 +1887,38 @@ sub foreach_passthrough_device { > } > } > > +my $cpuinfo = PVE::ProcFSTools::read_cpuinfo(); > + > +# for determining pool usage vs limits > +# > +# this gives the higher of pending or currently configured > +sub get_pool_usage { hm, would it make sense to rename this sub to `get_configured_lxc_usage` or something similar to make it clear that it is used for the currently configured resources and not for the running? It was a little confusing to me at first, that `$usage` is used for the configuration in 'confmem' and not for 'runmem'. Also dropped the `_pool` because it could be independently used in the future. > + my ($class, $conf) = @_; > + > + my $usage = {}; > + > + my $get_max = sub { > + my $max = 0; > + > + for my $curr (@_) { > + $max = $curr if defined($curr) && $curr > $max; > + } > + > + return $max; > + }; > + > + $usage->{cpu} = $get_max->( > + $conf->{pending}->{cores}, > + $conf->{cores}, > + ); nit: this could be written in one line like for `$swap` and `$mem`. > + $usage->{cpu} = $cpuinfo->{cpus} if !$usage->{cpu}; nit: we could name this 'cpus' just for consistency's sake (as 'cpu' holds the cpu usage % and 'cpus' the amount of cores). > + > + my $swap = $get_max->($conf->{pending}->{swap}, $conf->{swap}); > + my $mem = $get_max->($conf->{pending}->{memory}, $conf->{memory}, 512); > + $usage->{mem} = $mem+$swap; > + $usage->{mem} *= 1024*1024; > + > + return $usage; > +} > + > 1; > -- > 2.39.2