In preparation for fixing #6285 [0]. `0` means to just skip writing the module parameter. But (especially) with the upcoming change in ZFS 2.3 - which makes the size basically that of the system memory minus 1 GiB - we want to always write some value.
[0] https://bugzilla.proxmox.com/show_bug.cgi?id=6285 Signed-off-by: Christoph Heiss <c.he...@proxmox.com> --- Proxmox/Install/RunEnv.pm | 9 +++++---- test/zfs-arc-max.pl | 42 +++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Proxmox/Install/RunEnv.pm b/Proxmox/Install/RunEnv.pm index 407d05c..02c603d 100644 --- a/Proxmox/Install/RunEnv.pm +++ b/Proxmox/Install/RunEnv.pm @@ -337,14 +337,15 @@ sub default_zfs_arc_max { my $product = Proxmox::Install::ISOEnv::get('product'); 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. + # By default limit PVE and low-memory systems, for all just use the 50% of system memory if ($product ne 'pve') { - return 0 if $total_memory >= 2048 && $product ne 'pmg'; - return 0 if $total_memory >= 4096; # PMG's base memory requirement is much higer + my $zfs_default_mib = int(sprintf('%.0f', $total_memory / 2)); + return $zfs_default_mib if $total_memory >= 2048 && $product ne 'pmg'; + return $zfs_default_mib if $total_memory >= 4096; # PMG's base memory requirement is much higher } my $default_mib = $total_memory * $ZFS_ARC_SYSMEM_PERCENTAGE; + # int(sprintf()) rounds up instead of truncating my $rounded_mib = int(sprintf('%.0f', $default_mib)); if ($rounded_mib > $ZFS_ARC_MAX_SIZE_MIB) { diff --git a/test/zfs-arc-max.pl b/test/zfs-arc-max.pl index 8cf093f..a8c0a37 100755 --- a/test/zfs-arc-max.pl +++ b/test/zfs-arc-max.pl @@ -21,8 +21,10 @@ sub mock_product { ); } -my %default_tests = ( - 16 => 64, # at least 64 MiB +use constant ZFS_ARC_MIN_MIB => 64; + +my %default_tests_pve = ( + 16 => ZFS_ARC_MIN_MIB, # at least 64 MiB 1024 => 102, 4 * 1024 => 410, 8 * 1024 => 819, @@ -31,26 +33,36 @@ my %default_tests = ( 1024 * 1024 => 16384, # maximum of 16 GiB ); -while (my ($total_mem, $expected) = each %default_tests) { +my %default_tests_others = ( + 16 => ZFS_ARC_MIN_MIB, # at least 64 MiB + 1024 => 102, + 4 * 1024 => 2048, + 8 * 1024 => 4096, + 150 * 1024 => 76800, + 160 * 1024 => 81920, + 1024 * 1024 => 524288, +); + +mock_product('pve'); +while (my ($total_mem, $expected) = each %default_tests_pve) { $proxmox_install_runenv->redefine( query_total_memory => sub { return $total_mem; }, ); - mock_product('pve'); is(Proxmox::Install::RunEnv::default_zfs_arc_max(), $expected, - "$expected MiB should be zfs_arc_max for PVE with $total_mem MiB system memory"); + "zfs_arc_max should default to $expected for pve with $total_mem MiB system memory"); +} - mock_product('pbs'); - is(Proxmox::Install::RunEnv::default_zfs_arc_max(), $total_mem < 2048 ? $expected : 0, - "zfs_arc_max should default to `0` for PBS with $total_mem MiB system memory"); +while (my ($total_mem, $expected) = each %default_tests_others) { + $proxmox_install_runenv->redefine( + query_total_memory => sub { return $total_mem; }, + ); - mock_product('pmg'); - is(Proxmox::Install::RunEnv::default_zfs_arc_max(), $total_mem < 4096 ? $expected : 0, - "zfs_arc_max should default to `0` for PMG with $total_mem MiB system memory"); - - mock_product('pdm'); - is(Proxmox::Install::RunEnv::default_zfs_arc_max(), $total_mem < 2048 ? $expected : 0, - "zfs_arc_max should default to `0` for PDM with $total_mem MiB system memory"); + foreach my $product ('pbs', 'pmg', 'pdm') { + mock_product($product); + is(Proxmox::Install::RunEnv::default_zfs_arc_max(), $expected, + "zfs_arc_max should default to $expected for $product with $total_mem MiB system memory"); + } } my @clamp_tests = ( -- 2.48.1 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel