runtime.ReadMemStats memory buckets to structures in code

Hello! I am using runtime.ReadMemStats() which gives my mem allocation by size of the structure (buckets). how do I use the top buckets to find out corresponding data structures in my Go code?

“Frees”: 12141859,
“Mallocs”: 12149121,
“Size”: 4096

(Malloc - Frees) * Size ~29MB. How do I get all structures of size 29 MB in my Go code?

This isn’t saying you have 29MB structs, it says you have 7262 allocations less than or equal to 4096 bytes and greater than some other size (based on the documentation of runtime.ReadMemStats: “BySize[N] gives statistics for allocations of size S where BySize[N-1].Size < S ≤ BySize[N].Size.”). Perhaps that other size is 2048, maybe 1024, maybe 1536, etc… You’d have to check the array to see what that smaller size is.

As far as tracking what those allocations are, I don’t think that information is exposed through any public API.

Memory bucket lower than that is 3456. So it means 29MB allocated by structures whose sizes vary from 3456 to 4096?


Yes, that’s my understanding based on the documentation.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.