mirror of
				https://git.proxmox.com/git/pve-installer
				synced 2025-10-31 14:21:19 +00:00 
			
		
		
		
	fix #4829: install: add new ZFS arc_max setup option
				
					
				
			Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
This commit is contained in:
		
							parent
							
								
									e8a7b9ba86
								
							
						
					
					
						commit
						42aa2fa7ef
					
				| @ -291,6 +291,19 @@ sub get_zfs_raid_setup { | ||||
|     return ($devlist, $cmd); | ||||
| } | ||||
| 
 | ||||
| # If the maximum ARC size for ZFS was explicitly changed by the user, applies | ||||
| # it to the new system by setting the `zfs_arc_max` module parameter in /etc/modprobe.d/zfs.conf | ||||
| my sub zfs_setup_module_conf { | ||||
|     my ($targetdir) = @_; | ||||
| 
 | ||||
|     my $arc_max = Proxmox::Install::Config::get_zfs_opt('arc_max'); | ||||
|     my $arc_max_mib = Proxmox::Install::RunEnv::clamp_zfs_arc_max($arc_max) * 1024 * 1024; | ||||
| 
 | ||||
|     if ($arc_max > 0) { | ||||
| 	file_write_all("$targetdir/etc/modprobe.d/zfs.conf", "options zfs zfs_arc_max=$arc_max\n") | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| sub get_btrfs_raid_setup { | ||||
|     my $filesys = Proxmox::Install::Config::get_filesys(); | ||||
| 
 | ||||
| @ -1141,6 +1154,7 @@ _EOD | ||||
| 
 | ||||
| 	    file_write_all("$targetdir/etc/kernel/cmdline", "root=ZFS=$zfs_pool_name/ROOT/$zfs_root_volume_name boot=zfs\n"); | ||||
| 
 | ||||
| 	    zfs_setup_module_conf($targetdir); | ||||
| 	} | ||||
| 
 | ||||
| 	diversion_remove($targetdir, "/usr/sbin/update-grub"); | ||||
|  | ||||
| @ -72,6 +72,7 @@ my sub init_cfg { | ||||
| 	    compress => 'on', | ||||
| 	    checksum => 'on', | ||||
| 	    copies => 1, | ||||
| 	    arc_max => Proxmox::Install::RunEnv::default_zfs_arc_max(), # in MiB | ||||
| 	}, | ||||
| 	# TODO: single disk selection config | ||||
| 	target_hd => undef, | ||||
|  | ||||
| @ -303,6 +303,51 @@ sub query_installation_environment : prototype() { | ||||
|     return $output; | ||||
| } | ||||
| 
 | ||||
| # OpenZFS specifies 64 MiB as the absolute minimum: | ||||
| # https://openzfs.github.io/openzfs-docs/Performance%20and%20Tuning/Module%20Parameters.html#zfs-arc-max | ||||
| our $ZFS_ARC_MIN_SIZE_MIB = 64; # MiB | ||||
| 
 | ||||
| # See https://bugzilla.proxmox.com/show_bug.cgi?id=4829 | ||||
| our $ZFS_ARC_MAX_SIZE_MIB = 16 * 1024; # 16384 MiB = 16 GiB | ||||
| our $ZFS_ARC_SYSMEM_PERCENTAGE = 0.1; # use 10% of available system memory by default | ||||
| 
 | ||||
| # Calculates the default upper limit for the ZFS ARC size. | ||||
| # Returns the default ZFS maximum ARC size in MiB. | ||||
| sub default_zfs_arc_max { | ||||
|     # Use ZFS default on non-PVE | ||||
|     return 0 if Proxmox::Install::ISOEnv::get('product') ne 'pve'; | ||||
| 
 | ||||
|     my $default_mib = get('total_memory') * $ZFS_ARC_SYSMEM_PERCENTAGE; | ||||
|     my $rounded_mib = int(sprintf('%.0f', $default_mib)); | ||||
|     print "total_memory:" . get('total_memory') . " mib_rounded:$rounded_mib\n"; | ||||
| 
 | ||||
|     if ($rounded_mib > $ZFS_ARC_MAX_SIZE_MIB) { | ||||
| 	return $ZFS_ARC_MAX_SIZE_MIB; | ||||
|     } elsif ($rounded_mib < $ZFS_ARC_MIN_SIZE_MIB) { | ||||
| 	return $ZFS_ARC_MIN_SIZE_MIB; | ||||
|     } | ||||
| 
 | ||||
|     return $rounded_mib; | ||||
| } | ||||
| 
 | ||||
| # Clamps the provided ZFS arc_max value (in MiB) to the accepted bounds. The | ||||
| # lower is specified by `$ZFS_ARC_MIN_SIZE_MIB`, the upper by the available system memory. | ||||
| # Returns the clamped value in MiB. | ||||
| sub clamp_zfs_arc_max { | ||||
|     my ($mib) = @_; | ||||
| 
 | ||||
|     return $mib if $mib == 0; | ||||
| 
 | ||||
|     my $total_mem_mib = get('total_memory'); | ||||
|     if ($mib > $total_mem_mib) { | ||||
| 	return $total_mem_mib; | ||||
|     } elsif ($mib < $ZFS_ARC_MIN_SIZE_MIB) { | ||||
| 	return $ZFS_ARC_MIN_SIZE_MIB; | ||||
|     } | ||||
| 
 | ||||
|     return $mib; | ||||
| } | ||||
| 
 | ||||
| my $_env = undef; | ||||
| sub get { | ||||
|     my ($k) = @_; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Christoph Heiss
						Christoph Heiss