We have a golang process that internally uses CGO libraries. We are observing OOM kills for this process after some time.
kernel: [322533.632311] Memory cgroup out of memory: Killed process 1895550 (grpc_latest_srvc) total-vm:3072488kB, anon-rss:634580kB, file-rss:17192kB, shmem-rss:0kB, UID:0 pgtables:1812kB oom_score_adj:936
I am debugging the memory usage of my process by printing runtime.MemStats and also using pprof package and getting heap file. The heap file is showing just 60 to 100 MB but top command RES is showing around 620MB.
In some documents I read that go GC will not release the freed memory to OS to fix that we are calling runtime.debug.FreeOSMemory() at some intervals.
But still, top RES is keep on increasing, and after few hours process gets killed with OOM. runtime.MemStats/pprof-heap data is showing consistent memory usage of around 60 to 100MB
can someone help me to understand why there was a lot of difference between the top RES and runtime.MemStats/pprof-heap?
runtime.MemStats are like:
Alloc: 104 MiB
TotalAlloc: 366909 MiB
StackInuse: 1152 KiB
Sys: 155 MiB
NumGC: 84458
Top command results:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+
69917 root 20 0 3072488 620116 31160 S 141.8 3.8 88:59.63