caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Mastering the garbage collector
@ 2009-06-25 14:57 Tiphaine Turpin
  2009-06-25 15:14 ` Sylvain Le Gall
  2009-06-25 15:53 ` [Caml-list] " Julien Signoles
  0 siblings, 2 replies; 7+ messages in thread
From: Tiphaine Turpin @ 2009-06-25 14:57 UTC (permalink / raw)
  To: caml-list

Hi,

I have difficulties with the garbage colloector. I have a program that
use a lot of memory to build a small result, before doing something
else. I expected all the memory but the result to be collected when
doing a full_major, but this is not the case. I have tried to
encapsulate all references to the large intermediate data in a function,
compiling with -inline 0, but it does not work. Any idea ? More
generally, is there a specification of the notion of root used by the
garbage collector somewhere ?

Thanks,

Tiphaine


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Mastering the garbage collector
  2009-06-25 14:57 Mastering the garbage collector Tiphaine Turpin
@ 2009-06-25 15:14 ` Sylvain Le Gall
  2009-06-25 15:37   ` [Caml-list] " Tiphaine Turpin
  2009-06-25 15:53 ` [Caml-list] " Julien Signoles
  1 sibling, 1 reply; 7+ messages in thread
From: Sylvain Le Gall @ 2009-06-25 15:14 UTC (permalink / raw)
  To: caml-list

On 25-06-2009, Tiphaine Turpin <Tiphaine.Turpin@irisa.fr> wrote:
> Hi,
>
> I have difficulties with the garbage colloector. I have a program that
> use a lot of memory to build a small result, before doing something
> else. I expected all the memory but the result to be collected when
> doing a full_major, but this is not the case. I have tried to
> encapsulate all references to the large intermediate data in a function,
> compiling with -inline 0, but it does not work. Any idea ? More
> generally, is there a specification of the notion of root used by the
> garbage collector somewhere ?
>

You need to do a "Gc.compact" to size down. A full_major will collect but I
am not sure it will free allocated page.

Regards,
Sylvain Le Gall


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Re: Mastering the garbage collector
  2009-06-25 15:14 ` Sylvain Le Gall
@ 2009-06-25 15:37   ` Tiphaine Turpin
  2009-06-25 18:12     ` Christophe Raffalli
  0 siblings, 1 reply; 7+ messages in thread
From: Tiphaine Turpin @ 2009-06-25 15:37 UTC (permalink / raw)
  To: Sylvain Le Gall, caml-list

Sylvain Le Gall a écrit :
> You need to do a "Gc.compact" to size down. A full_major will collect but I
> am not sure it will free allocated page.
>   
But if it is just a matter of compaction, then

(Gc.stat ()).Gc.live_words

should give me a correct (small) result, no ?

Tiphaine


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Mastering the garbage collector
  2009-06-25 14:57 Mastering the garbage collector Tiphaine Turpin
  2009-06-25 15:14 ` Sylvain Le Gall
@ 2009-06-25 15:53 ` Julien Signoles
  1 sibling, 0 replies; 7+ messages in thread
From: Julien Signoles @ 2009-06-25 15:53 UTC (permalink / raw)
  To: caml-list

Hello,

More
> generally, is there a specification of the notion of root used by the
> garbage collector somewhere ?

I recommend you the following article. You should find what you want inside.

@inproceedings{DBLP:conf/ml/CuoqD08,
   author    = {Pascal Cuoq and
                Damien Doligez},
   title     = {Hashconsing in an incrementally garbage-collected system:
                a story of weak pointers and hashconsing in ocaml 3.10.2},
   booktitle = {ML},
   year      = {2008},
   pages     = {13-22},
   ee        = {http://doi.acm.org/10.1145/1411304.1411308},
   crossref  = {DBLP:conf/ml/2008},
   bibsource = {DBLP, http://dblp.uni-trier.de}
}

Hope this helps,
Julien Signoles
-- 
Researcher-engineer
CEA LIST, Software Reliability Lab
91191 Gif-Sur-Yvette Cedex
tel:(+33)1.69.08.71.83  fax:(+33)1.69.08.83.95  Julien.Signoles@cea.fr


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Re: Mastering the garbage collector
  2009-06-25 15:37   ` [Caml-list] " Tiphaine Turpin
@ 2009-06-25 18:12     ` Christophe Raffalli
  2009-06-26  7:28       ` Tiphaine Turpin
  0 siblings, 1 reply; 7+ messages in thread
From: Christophe Raffalli @ 2009-06-25 18:12 UTC (permalink / raw)
  To: Tiphaine Turpin; +Cc: Sylvain Le Gall, caml-list


[-- Attachment #1.1: Type: text/plain, Size: 1955 bytes --]

Tiphaine Turpin a écrit :
> Sylvain Le Gall a écrit :
>   
>> You need to do a "Gc.compact" to size down. A full_major will collect but I
>> am not sure it will free allocated page.
>>   
>>     
> But if it is just a matter of compaction, then
>
> (Gc.stat ()).Gc.live_words
>
> should give me a correct (small) result, no ?
>
> Tiphaine
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>   
You need to make sure that a complete GC cycle has run after producing
your result, before

(Gc.stat ()).Gc.live_words gives you what you want.

The function you need is that one :

val full_major : unit -> unit

Do a minor collection, finish the current major collection cycle, and perform a complete new cycle. This 
will collect all currently unreachable blocks.

You should make sure that variables with values holding large objects
are not syntactically in the scope of any piece of code that can still
be evaluated (I am not sure I am very clear). Here is a small example :


let x = ... in
(* here you are not sure x is collected even if the variable does not
appear after this comment *)
let y = 3 in
...


Cheers,
Christophe

-- 
Christophe Raffalli
Universite de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tel: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution 
can check this signature. The public key is
stored on www.keyserver.net
---------------------------------------------


[-- Attachment #1.2: Christophe_Raffalli.vcf --]
[-- Type: text/x-vcard, Size: 310 bytes --]

begin:vcard
fn:Christophe Raffalli
n:Raffalli;Christophe
org:LAMA (UMR 5127)
email;internet:christophe.raffalli@univ-savoie.fr
title;quoted-printable:Ma=C3=AEtre de conf=C3=A9rences
tel;work:+33 4 79 75 81 03
note:http://www.lama.univ-savoie.fr/~raffalli
x-mozilla-html:TRUE
version:2.1
end:vcard


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Re: Mastering the garbage collector
  2009-06-25 18:12     ` Christophe Raffalli
@ 2009-06-26  7:28       ` Tiphaine Turpin
  2009-06-27  7:51         ` Christophe Raffalli
  0 siblings, 1 reply; 7+ messages in thread
From: Tiphaine Turpin @ 2009-06-26  7:28 UTC (permalink / raw)
  To: Christophe Raffalli, caml-list

Christophe Raffalli a écrit :
> You need to make sure that a complete GC cycle has run after producing
> your result, before
>
> (Gc.stat ()).Gc.live_words gives you what you want.
>
> The function you need is that one :
>
> val full_major : unit -> unit
>   
I already do that before querying the live words count.
> let x = ... in
> (* here you are not sure x is collected even if the variable does not
> appear after this comment *)
>   
Thanks for making this clear. I was indeed thinking that collecting x 
here could require some sort of variable liveness analysis, and that the
GC might not be that smart, and this is why I tried to put x in a
function and prevent inlining, but I don't know if it is enough to make
x definitely unreachable.
> let y = 3 in
> ...
>
>
> Cheers,
> Christophe
>
>   
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>   


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Re: Mastering the garbage collector
  2009-06-26  7:28       ` Tiphaine Turpin
@ 2009-06-27  7:51         ` Christophe Raffalli
  0 siblings, 0 replies; 7+ messages in thread
From: Christophe Raffalli @ 2009-06-27  7:51 UTC (permalink / raw)
  To: Tiphaine Turpin; +Cc: Christophe Raffalli, caml-list


>> let x = ... in
>> (* here you are not sure x is collected even if the variable does not
>> appear after this comment *)
>>   
>>     
> Thanks for making this clear. I was indeed thinking that collecting x 
> here could require some sort of variable liveness analysis, and that the
> GC might not be that smart, and this is why I tried to put x in a
> function and prevent inlining, but I don't know if it is enough to make
> x definitely unreachable.
>   
If your problem is still not solved, may be you should post your code or 
an example reproducing the problem.

Cheers,
Christophe


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-06-27  7:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-25 14:57 Mastering the garbage collector Tiphaine Turpin
2009-06-25 15:14 ` Sylvain Le Gall
2009-06-25 15:37   ` [Caml-list] " Tiphaine Turpin
2009-06-25 18:12     ` Christophe Raffalli
2009-06-26  7:28       ` Tiphaine Turpin
2009-06-27  7:51         ` Christophe Raffalli
2009-06-25 15:53 ` [Caml-list] " Julien Signoles

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).