public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 1/4] run env: provide default ZFS ARC maximum size value
Date: Fri, 28 Feb 2025 10:43:36 +0100	[thread overview]
Message-ID: <20250228094341.147783-2-c.heiss@proxmox.com> (raw)
In-Reply-To: <20250228094341.147783-1-c.heiss@proxmox.com>

This can be then used by the Rust parts directly, without having to
duplicate the calculation.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 Proxmox/Install/RunEnv.pm | 10 +++++++---
 test/zfs-arc-max.pl       | 12 ++----------
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/Proxmox/Install/RunEnv.pm b/Proxmox/Install/RunEnv.pm
index 701343d..407d05c 100644
--- a/Proxmox/Install/RunEnv.pm
+++ b/Proxmox/Install/RunEnv.pm
@@ -238,6 +238,7 @@ my sub detect_country_tracing_to : prototype($$) {
 #     hvm_supported = <1 if the CPU supports hardware-accelerated virtualization>,
 #     secure_boot = <1 if SecureBoot is enabled>,
 #     boot_type = <either 'efi' or 'bios'>,
+#     default_zfs_arc_max => <default upper limit for the ZFS ARC size in MiB>,
 #     disks => <see Proxmox::Sys::Block::hd_list()>,
 #     network => {
 #         interfaces => <see query_netdevs()>,
@@ -285,6 +286,7 @@ sub query_installation_environment : prototype() {
     $output->{total_memory} = query_total_memory();
     $output->{hvm_supported} = query_cpu_hvm_support();
     $output->{boot_type} = -d '/sys/firmware/efi' ? 'efi' : 'bios';
+    $output->{default_zfs_arc_max} = default_zfs_arc_max();
 
     if ($output->{boot_type} eq 'efi') {
 	my $content = eval { file_read_all("/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c") };
@@ -329,9 +331,11 @@ our $ZFS_ARC_SYSMEM_PERCENTAGE = 0.1; # use 10% of available system memory by de
 
 # Calculates the default upper limit for the ZFS ARC size.
 # Returns the default ZFS maximum ARC size in MiB.
+# See also <https://bugzilla.proxmox.com/show_bug.cgi?id=4829> and
+# https://openzfs.github.io/openzfs-docs/Performance%20and%20Tuning/Module%20Parameters.html#zfs-arc-max
 sub default_zfs_arc_max {
     my $product = Proxmox::Install::ISOEnv::get('product');
-    my $total_memory = get('total_memory');
+    my $total_memory = query_total_memory();
 
     # By default limit PVE and low-memory systems, for all others let ZFS decide on its own by
     # returning `0`, which causes the installer to skip writing the `zfs_arc_max` module parameter.
@@ -340,7 +344,7 @@ sub default_zfs_arc_max {
 	return 0 if $total_memory >= 4096; # PMG's base memory requirement is much higer
     }
 
-    my $default_mib = get('total_memory') * $ZFS_ARC_SYSMEM_PERCENTAGE;
+    my $default_mib = $total_memory * $ZFS_ARC_SYSMEM_PERCENTAGE;
     my $rounded_mib = int(sprintf('%.0f', $default_mib));
 
     if ($rounded_mib > $ZFS_ARC_MAX_SIZE_MIB) {
@@ -361,7 +365,7 @@ sub clamp_zfs_arc_max {
     return $mib if $mib == 0;
 
     # upper limit is total system memory with a GiB headroom for the base system
-    my $total_mem_with_headroom_mib = get('total_memory') - 1024;
+    my $total_mem_with_headroom_mib = query_total_memory() - 1024;
     if ($mib > $total_mem_with_headroom_mib) {
 	$mib = $total_mem_with_headroom_mib; # do not return directly here, to catch < min ARC size
     }
diff --git a/test/zfs-arc-max.pl b/test/zfs-arc-max.pl
index 6ae6356..8cf093f 100755
--- a/test/zfs-arc-max.pl
+++ b/test/zfs-arc-max.pl
@@ -33,11 +33,7 @@ my %default_tests = (
 
 while (my ($total_mem, $expected) = each %default_tests) {
     $proxmox_install_runenv->redefine(
-	get => sub {
-	    my ($k) = @_;
-	    return $total_mem if $k eq 'total_memory';
-	    die "runtime environment key $k not mocked!\n";
-	},
+	query_total_memory => sub { return $total_mem; },
     );
 
     mock_product('pve');
@@ -71,11 +67,7 @@ foreach (@clamp_tests) {
     my ($input, $total_mem, $expected) = @$_;
 
     $proxmox_install_runenv->redefine(
-	get => sub {
-	    my ($k) = @_;
-	    return $total_mem if $k eq 'total_memory';
-	    die "runtime environment key $k not mocked!\n";
-	},
+	query_total_memory => sub { return $total_mem; },
     );
 
     is(Proxmox::Install::RunEnv::clamp_zfs_arc_max($input), $expected,
-- 
2.47.1



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


  reply	other threads:[~2025-02-28  9:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-28  9:43 [pve-devel] [PATCH installer 0/4] tui, auto: re-use default zfs arc calculation from run env Christoph Heiss
2025-02-28  9:43 ` Christoph Heiss [this message]
2025-02-28  9:43 ` [pve-devel] [PATCH installer 2/4] tui: use default ZFS ARC maximum size from runtime enviroment Christoph Heiss
2025-02-28  9:43 ` [pve-devel] [PATCH installer 3/4] auto: " Christoph Heiss
2025-02-28  9:43 ` [pve-devel] [PATCH installer 4/4] gtk, tui: leave 1 GiB headroom for OS in ZFS ARC max size edit view Christoph Heiss
2025-04-04  8:49 ` [pve-devel] applied-series: [PATCH installer 0/4] tui, auto: re-use default zfs arc calculation from run env Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250228094341.147783-2-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal