From d613b9d52225278d1319626b5508c91ea7b6935d Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 2 Sep 2013 03:54:22 -0700 Subject: [PATCH 1/5] Improve var names in get_memory Backport from master --- etc/inc/util.inc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/etc/inc/util.inc b/etc/inc/util.inc index d6d05acd0b..58153aa0ee 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -1514,14 +1514,15 @@ function set_sysctl($values) { * get_memory() * returns an array listing the amount of * memory installed in the hardware - * [0]real and [1]available + * [0] net memory available for the OS (FreeBSD) after some is taken by BIOS, video or whatever - e.g. 235 MBytes + * [1] real (actual) memory of the system, should be the size of the RAM card/s - e.g. 256 MBytes */ function get_memory() { - $real = trim(`sysctl -n hw.physmem`, " \n"); - $avail = trim(`sysctl -n hw.realmem`, " \n"); + $physmem = trim(`sysctl -n hw.physmem`, " \n"); + $realmem = trim(`sysctl -n hw.realmem`, " \n"); /* convert from bytes to megabytes */ - return array(($real/1048576),($avail/1048576)); + return array(($physmem/1048576),($realmem/1048576)); } function mute_kernel_msgs() { From 0c3a7a05f9dd5f94ae17ec0c524baf00a91a0db0 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 2 Sep 2013 04:12:47 -0700 Subject: [PATCH 2/5] Use updated get_memory var names Backport to 2.1 --- etc/inc/config.console.inc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/etc/inc/config.console.inc b/etc/inc/config.console.inc index f7494dbdcb..6c290c0cce 100644 --- a/etc/inc/config.console.inc +++ b/etc/inc/config.console.inc @@ -51,13 +51,14 @@ function set_networking_interfaces_ports() { $fp = fopen('php://stdin', 'r'); $memory = get_memory(); - $avail = $memory[1]; + $physmem = $memory[0]; + $realmem = $memory[1]; - if($avail < $g['minimum_ram_warning']) { + if($physmem < $g['minimum_ram_warning']) { echo "\n\n\n"; echo gettext("DANGER! WARNING! ACHTUNG!") . "\n\n"; printf(gettext("%s requires *AT LEAST* %s RAM to function correctly.%s"), $g['product_name'], $g['minimum_ram_warning_text'], "\n"); - printf(gettext("Only (%s) MB RAM has been detected.%s"), $avail, "\n"); + printf(gettext("Only (%s) MB RAM has been detected, with (%s) available to %s.%s"), $realmem, $physmem, $g['product_name'], "\n"); echo "\n" . gettext("Press ENTER to continue.") . " "; fgets($fp); echo "\n"; From 68b253adeefe0c08b1a633208c2caeb4a849b02d Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 2 Sep 2013 23:35:08 -0700 Subject: [PATCH 3/5] Use hw.physmem when calculating pfsense_default_state_size hw.physmem is the actual amount of memory that FreeBSD/pfSense can get its hands on, so use this for the calculation. Backport to 2.1 --- etc/inc/pfsense-utils.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 764d0103b1..ac2db3f5d8 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -1494,9 +1494,9 @@ function is_fqdn($fqdn) { function pfsense_default_state_size() { /* get system memory amount */ $memory = get_memory(); - $avail = $memory[1]; + $physmem = $memory[0]; /* Be cautious and only allocate 10% of system memory to the state table */ - $max_states = (int) ($avail/10)*1000; + $max_states = (int) ($physmem/10)*1000; return $max_states; } From 98c10c92c2d5d9c406841ed067811f645762733a Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 2 Sep 2013 23:43:54 -0700 Subject: [PATCH 4/5] Use new names for get_memory parameters --- etc/inc/system.inc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/etc/inc/system.inc b/etc/inc/system.inc index 7e59a59ca5..210479033c 100644 --- a/etc/inc/system.inc +++ b/etc/inc/system.inc @@ -878,21 +878,21 @@ function system_generate_lighty_config($filename, $lighty_port = $port; $memory = get_memory(); - $avail = $memory[1]; + $realmem = $memory[1]; // Determine web GUI process settings and take into account low memory systems - if ($avail < 255) + if ($realmem < 255) $max_procs = 1; else $max_procs = ($config['system']['webgui']['max_procs']) ? $config['system']['webgui']['max_procs'] : 2; // Ramp up captive portal max procs, assuming each PHP process can consume up to 64MB RAM if ($captive_portal !== false) { - if ($avail > 135 and $avail < 256) { + if ($realmem > 135 and $realmem < 256) { $max_procs += 1; // 2 worker processes - } else if ($avail > 255 and $avail < 513) { + } else if ($realmem > 255 and $realmem < 513) { $max_procs += 2; // 3 worker processes - } else if ($avail > 512) { + } else if ($realmem > 512) { $max_procs += 4; // 6 worker processes } if ($max_procs > 1) @@ -901,7 +901,7 @@ function system_generate_lighty_config($filename, $max_php_children = 1; } else { - if ($avail < 78) + if ($realmem < 78) $max_php_children = 0; else $max_php_children = 1; From e9215ad443d485a1fc7c2fa3a065025539ede861 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 2 Sep 2013 23:49:02 -0700 Subject: [PATCH 5/5] Use physmem and realmem from get_memory() in the appropriate places Backport to 2.1 --- etc/rc.bootup | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/etc/rc.bootup b/etc/rc.bootup index dda0b3c2cd..ab10e53d49 100755 --- a/etc/rc.bootup +++ b/etc/rc.bootup @@ -128,7 +128,8 @@ echo "."; /* get system memory amount */ $memory = get_memory(); -$avail = $memory[1]; +$physmem = $memory[0]; +$realmem = $memory[1]; echo " done.\n"; conf_mount_rw(); @@ -295,8 +296,8 @@ echo "Synchronizing user settings..."; local_sync_accounts(); echo "done.\n"; -if($avail > 0 and $avail < 65) { - echo "System has less than 65 megabytes of ram {$avail}. Delaying webConfigurator startup.\n"; +if($realmem > 0 and $realmem < 65) { + echo "System has less than 65 megabytes of ram {$realmem}. Delaying webConfigurator startup.\n"; /* start webConfigurator up on final pass */ mwexec("/usr/local/sbin/pfSctl -c 'service restart webgui'"); } else { @@ -385,7 +386,7 @@ if($config['system']['afterbootupshellcmd'] <> "") { mwexec($config['system']['afterbootupshellcmd']); } -if($avail < $g['minimum_ram_warning']) { +if($physmem < $g['minimum_ram_warning']) { require_once("/etc/inc/notices.inc"); file_notice("{$g['product_name']}MemoryRequirements", "{$g['product_name']} requires at least {$g['minimum_ram_warning_text']} of RAM. Expect unusual performance. This platform is not supported.", "Memory", "", 1); mwexec("/sbin/sysctl net.inet.tcp.recvspace=4096");