Skip to content
Advertisement

How to get Resident Set Size (RSS)

I need to know physical memory consumption of my Go process in Linux. What I need is Resident Set Size (RSS).

runtime.ReadMemStats is not suitable because there is no way to get a size of a portion of a virtual memory that is resident.

syscall.Getrusage is not suitable because it returns only Maxrss that is maximal RSS during process life.

How can I query RSS in Go?

Advertisement

Answer

You can parse /proc/self/statm file. It contains only integers so it is easy to parse. Second field is RSS measured in pages.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement