From cc2cc62717f10735f31b0b60f159059891defeb5 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Wed, 1 Oct 2025 14:33:22 +0300 Subject: [PATCH] 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. --- CHANGELOG.md | 1 + proc/freebsd-lib.pl | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b17b587ee..d7f0ae1c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/proc/freebsd-lib.pl b/proc/freebsd-lib.pl index 861006892..630527e56 100755 --- a/proc/freebsd-lib.pl +++ b/proc/freebsd-lib.pl @@ -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) {