From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id A290C1FF16F
	for <inbox@lore.proxmox.com>; Thu, 19 Dec 2024 17:02:06 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id A9A85BEE1;
	Thu, 19 Dec 2024 17:02:06 +0100 (CET)
From: Daniel Kral <d.kral@proxmox.com>
To: f.gruenbichler@proxmox.com
Date: Thu, 19 Dec 2024 17:01:57 +0100
Message-Id: <20241219160157.183450-1-d.kral@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20240416122054.733817-3-f.gruenbichler@proxmox.com>
References: <20240416122054.733817-3-f.gruenbichler@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.004 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH v2 container 1/7] config: add pool usage
 helper
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Cc: pve-devel@lists.proxmox.com
Content-Type: multipart/mixed; boundary="===============4011098201117740337=="
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

--===============4011098201117740337==
Content-Transfer-Encoding: quoted-printable

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



--===============4011098201117740337==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

--===============4011098201117740337==--