Page MenuHomeFreeBSD

Adjust libmemstat after r338899
ClosedPublic

Authored by mjg on Oct 10 2018, 1:23 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 17 2024, 2:13 AM
Unknown Object (File)
Mar 8 2024, 10:38 AM
Unknown Object (File)
Mar 8 2024, 10:38 AM
Unknown Object (File)
Mar 8 2024, 10:38 AM
Unknown Object (File)
Mar 8 2024, 10:38 AM
Unknown Object (File)
Mar 8 2024, 9:14 AM
Unknown Object (File)
Jan 27 2024, 4:05 PM
Unknown Object (File)
Jan 20 2024, 4:47 PM
Subscribers

Details

Summary

libmemstat uses kvm to dig into kernel memory to get malloc stats. However, the way stats are kept is not versioned in any way and the recent change results in garbage results or crashes
e.g. using vmstat -m -M /dev/mem

The change simply updates the lib to match the kernel.

the issue was reported by yuripv

Test Plan

compared vmstat -m -M /dev/mem to vmstat -m

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I do not remember that we ever supported non-current kernel in the core/live kernel tools. In other words, I do not think that the versioning to support future compatibility is needed. If you want some assurance, use __FreeBSD_version, this is a rare case where the value is actually useful and can be applied on purpose.

In D17490#373345, @kib wrote:

I do not remember that we ever supported non-current kernel in the core/live kernel tools.

I agree, in general we simply don't provide backwards compatibility for -M. Support for this option typically requires embedding kernel struct layout into userspace, and we have no versioning mechanism for that.

mjg retitled this revision from Adjust libmemstat after r338899 and add versioning to Adjust libmemstat after r338899.
mjg edited the summary of this revision. (Show Details)
mjg edited the test plan for this revision. (Show Details)

Just implement support for the updated layout.

The intent was not really to be compatible, but to provide the library a fighting chance to fail gracefully instead of crashing in case of potential future changes.

This revision is now accepted and ready to land.Oct 10 2018, 10:07 PM
lib/libmemstat/memstat_malloc.c
408 ↗(On Diff #48989)

It looks like you should not be re-initializing j here.

Looks ok to me otherwise.

This revision was automatically updated to reflect the committed changes.