Skip to content

sysinfo.pl: fix memory usage on kernel >= 6.x, auto-scale units - #610

Closed
TehPeGaSuS wants to merge 1 commit into
weechat:mainfrom
TehPeGaSuS:fix-sysinfo-kernel-memory-detection
Closed

sysinfo.pl: fix memory usage on kernel >= 6.x, auto-scale units#610
TehPeGaSuS wants to merge 1 commit into
weechat:mainfrom
TehPeGaSuS:fix-sysinfo-kernel-memory-detection

Conversation

@TehPeGaSuS

Copy link
Copy Markdown
Contributor

The kernel version detection regex only matched majors 3-5:

my $l3 = 1 if $linux && $osv =~ /^2\.7/  || $osv =~ /^[3-5]\./;

On kernel 6.x/7.x neither $l26 nor $l3 gets set, so memoryusage() falls
through to the old vmstat-style branch which reads garbage from $vara/$vard,
causing the uninitialized-value warnings and "Illegal division by zero" from
#581.

This patch:

  • detects any Linux kernel major >= 3 instead of hardcoding 3-5
  • adds a small human_size() helper and uses it for both memory and disk
    usage output, so results are auto-scaled (B/KB/MB/GB/TB) instead of always
    hardcoded to MB/GB

Tested on kernel 7.0.0, /sysinfo memory and /sysinfo disk both work as
expected.

Closes #581

The kernel version regex only matched majors 3-5, so on kernel 6.x/7.x
neither $l26 nor $l3 got set and memoryusage() fell through to a stale
vmstat-style branch that reads $vara/$vard as uninitialized, causing
'Illegal division by zero' (closes weechat#581).

Also show memory/disk usage with an auto-scaled unit (B/KB/MB/GB/TB)
instead of always hardcoding MB/GB.
@TehPeGaSuS
TehPeGaSuS force-pushed the fix-sysinfo-kernel-memory-detection branch from 8f75104 to bd1e3f8 Compare September 5, 2026 16:45
@flashcode flashcode self-assigned this Sep 5, 2026
@flashcode flashcode added the bug Unexpected problem or unintended behavior label Sep 5, 2026
@flashcode

Copy link
Copy Markdown
Member

Thanks, merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Unexpected problem or unintended behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sysinfo.pl: unitialized values and division by 0

2 participants