Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
More re GC hanging
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-08-15 (10:45)
From: Adrien <camaradetux@g...>
Subject: Re: [Caml-list] More re GC hanging

I recently had similar output from the GC (huge count of words) which
I noticed after my program started to exit with an out-of-memory
error. It doesn't seem to be happening anymore but I'm not sure I
"fixed" it. There are three things I thought of to get rid of it.
(btw, I'm on 64bit linux)

First, remove all non-tail-rec functions: no more, @ or
List.concat. All lists were pretty short (definitely less than 1000
elements) but maybe the amount of calls generated garbage or something
like that: I couldn't get much infos about the problem so I tried what
I could think of and being tail-rec couldn't be a bad thing anyway.
The idea was to create less values since I first suspected a memory
fragmentation issue (iirc I had thousands of fragments), so I also
memoized some functions.

Then, as Basile mentionned, call something like Gc.compact ()
regularly. The overhead is actually pretty small, especially if ran

Finally, C bindings. I created a few while not having access to the
internet and they are quite dirty. I highly doubt they play perfectly
well with the garbage collector: they seem ok but probably aren't
perfect. That's definitely something to check, even if the bindings
were written by someone else because working nicely with the GC can be
quite hard.

Now, the problem seems to be gone but I can't say for sure. One really
annoying thing was that adding a line like 'print_endline "pouet";'
would make the out-of-memory problem go away! Same when getting stats
from the GC.

As for the problem with randomize_va_space on 64bit, I thought it had
been fixed in 3.11 so I haven't looked at it (and in the absence of
internet access, I was unable to get details for that problem). I just
tried about a hundred run with VA-space-randomization on and without
Gc.compact calls and ran without problem. Hopefully everything is
tracked in git so I can get the older and non-working code if needed.

Also, on my computer, I have the following behaviour:
    11:44 ~ % sudo echo 0 > /proc/sys/kernel/randomize_va_space
    zsh: permission denied: /proc/sys/kernel/randomize_va_space
    root@jarjar:~# echo 0 > /proc/sys/kernel/randomize_va_space
I can't use sudo to write to most files in /proc or /sys: I have to
log in as root ('su -' does the job just fine).

Hope this helps.


Adrien Nader