From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id C1F89BC6B for ; Wed, 28 Nov 2007 19:32:53 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAPhCTUfUGyokimdsb2JhbACPPgEBAQgCCBERBw X-IronPort-AV: E=Sophos;i="4.23,225,1194217200"; d="scan'208";a="19779850" Received: from smtp6-g19.free.fr ([212.27.42.36]) by mail4-smtp-sop.national.inria.fr with ESMTP; 28 Nov 2007 19:32:53 +0100 Received: from smtp6-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp6-g19.free.fr (Postfix) with ESMTP id 3A3725FF84; Wed, 28 Nov 2007 19:32:53 +0100 (CET) Received: from [192.168.1.3] (che78-2-82-237-71-191.fbx.proxad.net [82.237.71.191]) by smtp6-g19.free.fr (Postfix) with ESMTP id E20075FF6C; Wed, 28 Nov 2007 19:32:52 +0100 (CET) Message-ID: <474DB454.9060507@inria.fr> Date: Wed, 28 Nov 2007 19:32:52 +0100 From: Xavier Leroy User-Agent: Thunderbird 2.0.0.4 (X11/20070620) MIME-Version: 1.0 To: Raj Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Disabling the OCaml garbage collector References: <474C48C5.708@starynkevitch.net> <474DADF7.5020204@rice.edu> In-Reply-To: <474DADF7.5020204@rice.edu> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ocaml:01 ocaml:01 compiler:01 'make:01 compactor:01 suitably:01 run-time:01 indirection:01 bindings:01 mighty:98 irritable:98 garbage:01 garbage:01 compile:01 heap:01 > Well, I decided to go ahead and hack some C code to build a custom OCaml > compiler. These are the steps I followed: [...] > However, when I compile this code with 'make world' I get the following > error while linking: That's a classic bootstrapping issue, and "make bootstrap; make all" might solve it. But you are on the wrong tracks anyway. What your C code does is disable the compactor, which runs from time to time to eliminate fragmentation in the major heap by moving objects around. You can disable it by using Gc.set with the "max_overhead" field set to a suitably high value, as documented in the Gc module. There is no need to hack the run-time system. However, what you will never be able to disable is the minor collector, which moves blocks from the minor heap to the major heap. The reason it cannot be disabled is that the minor heap is of fixed size, so if it gets full and the minor GC isn't executed to empty it, your program cannot proceed. You see, the Caml garbage collector is like a god from ancient mythology: mighty, but very irritable. If you mess with it, it'll make you suffer in surprising ways. The solution to your problem is to play nice with the Caml GC: on the C/Python side, handle Caml "values" through an indirection via a malloc-ed block, and register the Caml value contained within this block with the Caml GC using register_global_roots(), as Thomas Fischbacher outlined. Members of this list can probably point you to some existing C/Caml bindings that does just this and that you could use as inspiration. Hope this helps, - Xavier Leroy