Skip to content

runtime: 1.3 garbage collector not releasing server memory back to system from finished goroutines #8287

@gopherbot

Description

@gopherbot

by matusis:

What does 'go version' print?
go version go1.3 linux/amd64

This program http://play.golang.org/p/vnKYk3sO5d creates 100000 goroutines, with each
goroutine allocating some memory and then finishing.
The program prints RES memory of the process as seen by "top" and also prints
runtime.ReadMemStats every 25 minutes.

1. Build the program from http://play.golang.org/p/vnKYk3sO5d on a server and run it
2. Wait at least for 50 minutes for two printouts


What happened?

After 50 minutes, the program produces output like this:
Creating 100000 goroutines
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
19155 alecm     20   0  151m  84m  760 S    0  0.5   0:01.46 bugrep1.3          
Free #0; HeapAlloc: 10531984, HeapInuse: 10813440, HeapReleased: 0, HeapObjs: 36575
Done creating goroutines, freeing memory (every 25 mins)
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
19155 alecm     20   0  151m  79m  836 S    2  0.5   0:01.69 bugrep1.3          
Free #1; HeapAlloc: 5492784, HeapInuse: 5791744, HeapReleased: 5742592, HeapObjs: 18014
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
19155 alecm     20   0  151m  79m  860 S    0  0.5   0:01.88 bugrep1.3          
Free #2; HeapAlloc: 5494912, HeapInuse: 5791744, HeapReleased: 5742592, HeapObjs: 18061

The program released only 5MB or RES memory after 50 min. HeapReleased value matches RES
drop displayed by "top".

What should have happened instead?

Since goroutines exit and the slices created in them are not stored, most memory
(>80MB) should be returned to the OS. Only 5MB is returned however.

PS. We first saw this behavior in a simple TCP server accepting, reading from and
closing 10000 connections: please see
https://groups.google.com/forum/#!topic/golang-nuts/0WSOKnHGBZE

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions