Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: memory management, allocation and collection in kernel mode.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: doligez@p...
Subject: Re: memory management, allocation and collection in kernel mode.

>From: "Sussillo, David" <sussillo@ftintl.com>

>Does anybody have an idea what would need to change in the OCaml memory   
>management system in order for an OCaml program to function properly in   
>kernel mode?

My first answer would be nothing at all if the kernel has a malloc
function.


>1.  Will someone point out to me where I might look in the compiler   
>source for all of the memory management routines, allocataion and GC? I   
>guess it's important to see how the compiler reasons about the memory   
>requirements of OCaml structures, as well as the emitted code (or   
>libraries?) that it using during runtime.

I guess you should start with the byte-code interpreter, and when
that's working, you can tackle the native code stuff.  The files to
look for are all in byterun:

alloc.[ch]
compact.[ch]
freelist.[ch]
gc.h
gc_ctrl.[ch]
major_gc.[ch]
minor_gc.[ch]
mlvalues.h
roots.[ch]
stacks.[ch]
weak.[ch]


>2. If anyone has any insight into the memory management ramifications of   
>running an OCaml program in kernel mode, might they elucidate? As I'm   
>just starting out, I'm interested in both general and specific remarks.

The memory management should be easy if you have malloc.  For the
native code system, you might have to do something for the stack.

Stefan Monnier made a very good remark:
>3 - le kernel n'est souvent pas priemptible (?), donc il faudra faire attention
>    ` appeler explicitement le yield() de temps ` autre pour ne pas perdre trop
>    d'interruptions et ne pas rendre la machine unresponsive.  O'Caml utilise
>    dij` un GC incrimental si je ne me trompe, donc c'est peut-jtre pas trop
>    difficile (famous last words).

Translation: since kernel code is never preempted, you'll have to call
yield() from time to time.

Fortunately, that is exactly what the Macintosh version does for
cooperative multi-tasking.  Look for "#if macintosh" in interp.c and
replace the call to rotatecursor_action() with yield().  That should
be enough.  For native code, I don't have an easy answer.


-- Damien