Bug #3349
closedSystem Information Widget Showing Incorrect Memory Used %
0%
Description
I have 2048MB on my system. With the code below the web gui system information widget shows i have 512MB installed, the code is in the functions.inc.php file.
function mem_usage() { $memory = ""; exec("/sbin/sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_inactive_count " . "vm.stats.vm.v_cache_count vm.stats.vm.v_free_count", $memory); $totalMem = $memory[0]; $availMem = $memory[1] + $memory[2] + $memory[3]; $usedMem = $totalMem - $availMem; $memUsage = round(($usedMem * 100) / $totalMem,0); return $memUsage;
I took a look at the math and the sysctl commands used. I re-coded the math and also switched the commands to use the one that pulls the actual memory allocated by the system which is the same command that is pulling the total memory right next to the used % on the system information widget.
function mem_usage() { $memory = ""; exec("/sbin/sysctl -n vm.stats.vm.v_free_count hw.physmem hw.pagesize", $memory); $totalMem = $memory[1]; $availMem = $memory[0] * $memory[2]; $usedMem = $totalMem - $availMem; $memUsage = round(($usedMem * 100) / $totalMem, 2); return $memUsage;
Updated by Renato Botelho over 11 years ago
You should take inactive and cache into consideration, as it happens today. Considering it you still see differences on results?
BTW, if you can submit changes using github's pull request, it's easy for review and apply changes.
Updated by Wifi Ghost over 11 years ago
Yes, i have tested my new code on 4 systems and tried it with varying amounts of memory, anything over 512MB, and with the code i listed above it works perfectly. If you have a system with the original code using over 512MB of memory do the math per the code and watch what MB amount it comes up with. People using 512MB on their system wont see an issue since the math reports 498MB of ram being allocated by the system. I have a perl script you can run that shows all memory values with what the sysctl value is and converts it to MB and you can use that and compare it to the system information widget to see it is off unless you only use 512MB of memory, the same math and sysctl commands are used in the perl script. The LCD on 3 of my systems uses the hw.physmem value and it shows im using 24% of my memory while the widget shows im using 13%. The LCD also shows the total of the memory it is using to calculate the %. The number being pulled right next to the reported % on the widget is correct and using the hw.physmem to pull the memory allocated by the system. If you add the $memory1 + $memory2 + $memory3 (vm.stats.vm.v_inactive_count + vm.stats.vm.v_cache_count + vm.stats.vm.v_free_count) and use the Google converter on a system using over 512MB it reports an incorrect value. There are quite a few places showing how to calc the memory usage and total on a freeBSD system that confirm my math and sysctl commands. I will add my code to github now, i have seen this code not only in 2.1 but previous versions as well.
Updated by Wifi Ghost over 11 years ago
Also i created some code to accurately show what % of the disk space is being used instead of pulling what % DF puts out. Would that be helpful? I have it on my systems, DF reports a rounded up # of 1% while my code and math shows im actually using .499% (.5)
Updated by Chris Buechler almost 10 years ago
- Description updated (diff)
- Status changed from New to Feedback
- % Done changed from 100 to 0
The calculations there seem fine, the counters it's pulling from are those that top uses and the math is correct. I don't see how that could get 512 MB on a system with 2 GB. Maybe a misunderstanding of what that's actually showing? It's page count, and page size is 4096, so total RAM is 4096 * v_page_count. Misinterpret the units and and you might get the impression it's 1/4th the total memory size.
Will leave for feedback for now but I don't see a problem here.
Updated by Chris Buechler over 9 years ago
- Status changed from Feedback to Not a Bug
- Affected Version deleted (
All)