Hi Sebastian,
On 30 September 2012 14:52, Sébastien Paolacci wrote:
Do you have any small reproducer of the situation you're trying to solve
(incl. resources info)?
I just whipped something up to illustrate the problem: it's attached. I did
my best to satisfy the "small" requirement but mostly I pasted things in
from other projects without modifying them too much. Output is pasted below.
Quick explanation: The program will consume some number of GB of memory
(with the -n) parameter. It writes one byte into every page to force the
memory to be resident. It will wait some time, then use the memory to
evaluate something stupid, then try to free it by assigning an empty byte
slice and calling runtime.GC(). In order to simulate "memory outside of the
go process", the program runs itself again, if this is the first time it is
running.
What you see is that `Inuse` increases during allocation, and decreases as
`Idle` goes up when you "free" (& GC) the memory. Free system memory is the
far left number, and never goes down (which is what we would like to fix).
Note that if "-n" is to high, the second execution fails because exec/fork
fails due to lack of memory.
Oddity which I don't understand: The GC actually somehow "misses" 1GB. I
haven't figured out why yet, I guess it is some feature of my program.
Thanks for taking a look,
- Peter
$ go build && time ./go-consumememory -n=3
[parent] 18:42:01.564907 --------- Program start ----------
[parent] 18:42:01.564954 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[parent] 18:42:01.565299 6.72GB 345.26kB 359.66kB 2.63MB
345.26kB 1.05MB 585.73kB 462.85kB 0.00B 148
[parent] 18:42:01.739056 --------- After allocation 0 ----------
[parent] 18:42:01.739124 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[parent] 18:42:01.739511 5.72GB 1.00GB 1.00GB 1.07GB
1.00GB 1.00GB 512.00kB 1.00GB 0.00B 177
[parent] 18:42:01.912637 --------- After allocation 1 ----------
[parent] 18:42:01.912672 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[parent] 18:42:01.913047 4.71GB 2.00GB 2.00GB 2.13GB
2.00GB 2.00GB 475.14kB 2.00GB 0.00B 575
[parent] 18:42:02.086908 --------- After allocation 2 ----------
[parent] 18:42:02.086944 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[parent] 18:42:02.087332 3.71GB 3.00GB 3.00GB 3.19GB
3.00GB 3.00GB 487.42kB 3.00GB 0.00B 196
[parent] 18:42:02.087341 --------- Sleeping for 1s ----------
[parent] 18:42:03.099030 Your lucky bit is: 1
[parent] 18:42:03.099049 --------- Before Forced GC ----------
[parent] 18:42:03.099059 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[parent] 18:42:03.099409 3.71GB 3.00GB 3.00GB 3.19GB
3.00GB 3.00GB 483.33kB 3.00GB 0.00B 419
[parent] 18:42:03.099666 --------- After Forced GC ----------
[parent] 18:42:03.099699 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[parent] 18:42:03.100026 3.71GB 1.00GB 3.00GB 3.19GB
1.00GB 3.00GB 2.00GB 1.00GB 0.00B 194
[parent] 18:42:04.100254 -- Running child : ./go-consumememory --
[!child] 18:42:04.142488 --------- Program start ----------
[!child] 18:42:04.142545 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[!child] 18:42:04.142885 3.71GB 345.27kB 359.68kB 2.63MB
345.27kB 1.05MB 585.73kB 462.85kB 0.00B 148
[!child] 18:42:04.318438 --------- After allocation 0 ----------
[!child] 18:42:04.318506 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[!child] 18:42:04.318879 2.70GB 1.00GB 1.00GB 1.07GB
1.00GB 1.00GB 512.00kB 1.00GB 0.00B 177
[!child] 18:42:04.494097 --------- After allocation 1 ----------
[!child] 18:42:04.494137 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[!child] 18:42:04.494513 1.70GB 2.00GB 2.00GB 2.13GB
2.00GB 2.00GB 475.14kB 2.00GB 0.00B 573
[!child] 18:42:04.670291 --------- After allocation 2 ----------
[!child] 18:42:04.670318 SysFree Alloc Total Sys |
Heap-> | Alloc Sys Idle Inuse Relsd N
[!child] 18:42:04.670682 695.81MB 3.00GB 3.00GB 3.19GB
3.00GB 3.00GB 487.42kB 3.00GB 0.00B 192
[!child] 18:42:04.671242 Ran out of memory; 695.81MB < 1.00GB
panic: exit status 1
goroutine 1 [running]:
main.main()
/home/pwaller/Projects/go-consumememory/main.go:106 +0x954
goroutine 2 [syscall]:
created by runtime.main
.../go/src/pkg/runtime/proc.c:220
goroutine 3 [timer goroutine (idle)]:
created by addtimer
.../go/src/pkg/runtime/ztime_linux_amd64.c:72
real 0m3.239s
user 0m0.148s
sys 0m1.082s