libmemstat uses kvm to dig into kernel memory to get malloc stats. However, the way stats are kept is not verioned in any way and the recent change results in garbage results or crashes
e.g. using vmstat -m -M /dev/null
Patch below is more of a WIP/RFC than something I consider committable just yet. It works, just needs deobfuscation.
Critical parts are:
- the symbol name for versioning is a mouthful, looking for a better name not breaking the scheme
- the sysctl added is there mostly to prevent LTO'ing the symbol in the future
- support for the old format is removed
- provisional support for possibly more formats is put in place so that should stats change in the future, a transitional period is provided where tooling works with mismatched kernel
Shortest variant can just change the code to read the per-cpu zone (which is few lines) and all other changes can be postponed.
the issue was reported by yuripv