Fix to query specific fields in FreeBSD memory stats collection

*Note: Replace `sysctl -a` with targeted queries for only the 5 needed values (hw.physmem, hw.pagesize, vm.stats.vm.v_*_count) instead of dumping thousands of kernel params. This reduces `get_memory_info()` overhead from 25% CPU to ~5% CPU when called by real-time monitoring every 1-3 seconds.
This commit is contained in:
Ilia Ross
2025-10-01 14:33:22 +03:00
parent c59591e3de
commit cc2cc62717
2 changed files with 11 additions and 1 deletions

View File

@@ -6,6 +6,7 @@
* Fix the printing of the bottom button row in the form column table
* Fix to recommend Perl `Sys::Syslog` module #2557
* Fix to avoid using short hostname in HTTPS redirects when an FQDN is available
* Fix to query specific fields in FreeBSD memory stats collection, cutting CPU use by 80%
* Add a complete overhaul of `var_dump` subroutine, which is now fully portable
* Update the Authentic theme to the latest version with various fixes:
- Fix the text color when reading email in the Read User Mail module [webmin#2555](https://github.com/webmin/webmin/issues/2555)

View File

@@ -101,7 +101,16 @@ ioctl($ttyfh, 536900705, 0);
sub get_memory_info
{
my $sysctl = {};
my $sysctl_output = &backquote_command("/sbin/sysctl -a 2>/dev/null");
# Get only the specific values we need not all with -a
my @needed = qw(
hw.physmem
hw.pagesize
vm.stats.vm.v_inactive_count
vm.stats.vm.v_cache_count
vm.stats.vm.v_free_count
);
my $sysctl_output = &backquote_command("/sbin/sysctl " .
join(" ", @needed) . " 2>/dev/null");
return ( ) if ($?);
foreach my $line (split(/\n/, $sysctl_output)) {
if ($line =~ m/^([^:]+):\s+(.+)\s*$/s) {