diff --git a/src/etc/rc.subr.d/tmp b/src/etc/rc.subr.d/tmp index 15a2caf75..a5daa5991 100755 --- a/src/etc/rc.subr.d/tmp +++ b/src/etc/rc.subr.d/tmp @@ -42,7 +42,15 @@ fi mkdir -p /tmp if [ ${USE_MFS_TMP} -ne 0 ]; then - mount -t tmpfs -o mode=01777 tmpfs /tmp + MAX_MFS_TMP=$(grep 'max_mfs_tmp' /conf/config.xml | sed 's/[^>]*>\([^<]*\)<.*/\1/') + MAX_MEM_SYS=$(sysctl -n hw.physmem) + + if [ -z "${MAX_MFS_TMP}" ]; then + # cap to 50% by default to avoid swapping + MAX_MFS_TMP=50 + fi + + mount -t tmpfs -o mode=01777,size=$((MAX_MEM_SYS / 100 * MAX_MFS_TMP)) tmpfs /tmp else rm -rf /tmp/* chmod 1777 /tmp diff --git a/src/www/system_advanced_misc.php b/src/www/system_advanced_misc.php index 4b234a330..cd6118b74 100644 --- a/src/www/system_advanced_misc.php +++ b/src/www/system_advanced_misc.php @@ -77,7 +77,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig['crypto_hardware'] = !empty($config['system']['crypto_hardware']) ? explode(',', $config['system']['crypto_hardware']) : []; $pconfig['thermal_hardware'] = !empty($config['system']['thermal_hardware']) ? $config['system']['thermal_hardware'] : null; $pconfig['use_mfs_var'] = isset($config['system']['use_mfs_var']); + $pconfig['max_mfs_var'] = $config['system']['max_mfs_var'] ?? null; $pconfig['use_mfs_tmp'] = isset($config['system']['use_mfs_tmp']); + $pconfig['max_mfs_tmp'] = $config['system']['max_mfs_tmp'] ?? null; $pconfig['use_swap_file'] = isset($config['system']['use_swap_file']); $pconfig['dhparamusage'] = !empty($config['system']['dhparamusage']) ? $config['system']['dhparamusage'] : null; $pconfig['rrdbackup'] = !empty($config['system']['rrdbackup']) ? $config['system']['rrdbackup'] : null; @@ -105,11 +107,27 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (!empty($pconfig['crypto_hardware'])) { if (count(array_intersect($pconfig['crypto_hardware'], crypto_modules())) == count($pconfig['crypto_hardware'])) { $input_errors[] = gettext('Please select a valid Cryptographic Accelerator.'); - } + } } else { $pconfig['crypto_hardware'] = []; } + if (isset($pconfig['max_mfs_var']) && $pconfig['max_mfs_var'] != '') { + if (!is_numeric($pconfig['max_mfs_var'])) { + $input_errors[] = gettext('Memory usage percentage is not a number.'); + } else if ($pconfig['max_mfs_var'] < 0 || $pconfig['max_mfs_var'] > 100) { + $input_errors[] = gettext('Memory usage percentage out of bounds.'); + } + } + + if (isset($pconfig['max_mfs_tmp']) && $pconfig['max_mfs_tmp'] != '') { + if (!is_numeric($pconfig['max_mfs_tmp'])) { + $input_errors[] = gettext('Memory usage percentage is not a number.'); + } else if ($pconfig['max_mfs_tmp'] < 0 || $pconfig['max_mfs_tmp'] > 100) { + $input_errors[] = gettext('Memory usage percentage out of bounds.'); + } + } + if (!empty($pconfig['thermal_hardware']) && !array_key_exists($pconfig['thermal_hardware'], thermal_modules())) { $input_errors[] = gettext("Please select a valid Thermal Hardware Sensor."); } @@ -143,12 +161,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { unset($config['system']['use_mfs_var']); } + if (isset($pconfig['max_mfs_var']) && $pconfig['max_mfs_var'] != '') { + $pconfig['max_mfs_var'] = trim($pconfig['max_mfs_var']); + $config['system']['max_mfs_var'] = $pconfig['max_mfs_var']; + } elseif (isset($config['system']['max_mfs_var'])) { + unset($config['system']['max_mfs_var']); + } + if (!empty($pconfig['use_mfs_tmp'])) { $config['system']['use_mfs_tmp'] = true; } elseif (isset($config['system']['use_mfs_tmp'])) { unset($config['system']['use_mfs_tmp']); } + if (isset($pconfig['max_mfs_tmp']) && $pconfig['max_mfs_tmp'] != '') { + $pconfig['max_mfs_tmp'] = trim($pconfig['max_mfs_tmp']); + $config['system']['max_mfs_tmp'] = $pconfig['max_mfs_tmp']; + } elseif (isset($config['system']['max_mfs_tmp'])) { + unset($config['system']['max_mfs_tmp']); + } + if (!empty($pconfig['use_swap_file'])) { /* set explicit value here in case we want to make it flexible */ $config['system']['use_swap_file'] = 2048; @@ -495,6 +527,15 @@ include("head.inc"); + + + + + + + @@ -505,6 +546,15 @@ include("head.inc"); + + + + + + +