Open aschran opened 2 years ago
FWIW I think even simply checking objects count in global data structures can be a pretty good signal on memory leaks, without estimate on the size itself if it turns out complicated or performance costly
Yes, this is anyway going to just be a rough estimate, since we are not using exact size measurements from the allocator
I think we can obtain a cheap estimate by multiplying object count (say of a Vec) * the static size computed by for example deep size
(It should be static since it is a struct).
It might also be possible to track retained memory size of specific structures using instrumentation and some custom tracking code. It wouldn't be that hard. (basically tracking memory allocator re-allocs and size changes for structures like Vec's - we just need to correlate addresses with code locations and whether it is a Vec, perhaps with some extra debug information)
I think we can obtain a cheap estimate by multiplying object count (say of a Vec) * the static size computed by for example
deep size
(It should be static since it is a struct).
This is for the most part how the implementations in parity-mem-util
work when running it in estimate-heapsize
mode (which is what I'm starting with to avoid interfering with the allocator-based heap profiling stuff).
FWIW I'm working on a separate heap profiling tool that should give much better signals than what current tools are capable of. Ping me for details
Summarizing input from François:
Look into integrating a trait-based crate for tracking heap memory usage, perhaps:
Validate the approach by carefully instrumenting a set of types on Narwhal with trait implementations (ideally derived as often as possible), up to what's needed to track the memory usage of the following table: https://github.com/MystenLabs/narwhal/blob/main/consensus/src/consensus.rs#L33
Export the memory usage gauge in a metric.
Related work in Sui: https://github.com/MystenLabs/sui/issues/3835