caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: oliver@first.in-berlin.de
Cc: caml-list@yquem.inria.fr
Subject: Re: Threading and SharedMem (Re: [Caml-list] Re: Is OCaml fast?)
Date: Tue, 30 Nov 2010 15:09:17 +0100	[thread overview]
Message-ID: <1291126157.16005.567.camel@thinkpad> (raw)
In-Reply-To: <20101130125545.GE1637@siouxsie>

Am Dienstag, den 30.11.2010, 13:55 +0100 schrieb
oliver@first.in-berlin.de:
> On Tue, Nov 30, 2010 at 09:10:36AM +0100, Stephan Houben wrote:
> > On 11/29/2010 04:33 PM, Oliver Bandel wrote:
> > >Zitat von "Gerd Stolpmann" <info@gerd-stolpmann.de>:
> > >
> > >>Am Montag, den 29.11.2010, 17:12 +0100 schrieb Oliver Bandel:
> > >>>Zitat von "Gerd Stolpmann" <info@gerd-stolpmann.de>:
> > >>>
> > 
> > >>>You use shared mem(?), but you link only to *.ml files,
> > >>>and I see no *.c there.
> > 
> > >>>How can this be done?
> > >>>
> > >>>At least not via the libs that are shipped with OCaml?!
> > 
> > Actually it can be done using the libs that ship with OCaml
> > (Unix and Bigarray), although it is not 100% POSIX :
> > 
> > let create_shared_genarray kind layout dims =
> >   let fd = Unix.openfile "/dev/zero" [Unix.O_RDWR] 0
> >   in let ar = Bigarray.Genarray.map_file fd kind layout true dims
> >   in Unix.close fd; ar
> > 
> > 
> > The resulting bigarray object is shared among subsequent forks.
> 
> Hmhhh... we started talking about Threads and SharedMem.
> You mean even fork.... hmhhh

Independent processes are right now the only way to use several cores.
You can organize shared memory between processes, but it is tricky.
That's what I try to ease with my Netmulticore library.

> > This relies on the fact that mmap-ing /dev/zero is equivalent
> > to an anonymous mmap.
> > 
> > http://en.wikipedia.org/wiki//dev/zero
> > 
> > Well, at least it works on Linux.
> 
> In APUE it's mentioned that memory mapped regions are inherited
> by a child, when forking it. So it should work on all Unix-systems too.

Yes, but is not defined by POSIX what mapping /dev/zero means.

> There is one problem with this... when you have forked, then
> you obviously have separated processes and also in each process
> your own ocaml-program with it's own GC running...
> 
> ..with such a mem-mapping trick (never used Bigarray, so I'm astouned it uses
> mmap) 

Bigarrays can use any memory with fixed addresses. That's the essence
here: Bigarrays are not moved around by the GC.

> you then have independent processes, working on shared mem without
> synchronisation.
> 
> This is a good possibility to get corrupted data, and therefore unreliable behaviour.
> 
> So, you have somehow to create a way of communicating of these processes.

So you need inter-process synchronization primitives, like POSIX
semaphores.

> This already is easily done in the Threads-module, because synchronisation
> mechanisms are bound there to the OCaml API and can be used easily.
> 
> In the Unix module there is not much of ths IPC stuff...

But in Ocamlnet's netsys module.

> (A thread-specific GC for thread-specific variables would help here,
>  making global locks only necessary when accessing global used variables.
>  But I don't know if such a way would be possible without changing the GC-stuff
>  itself.)

The global lock does not protect user variables, but the Ocaml runtime,
e.g. the state of the memory manager/garbage collector. Also it eases
code generation - the memory image needs not be in a consistent state
all the time (i.e. all pointers meaningful), but only when the runtime
gets a hand on it. Removing this lock has far-reaching consequences.

The oc4mc (ocaml for multicore) project used a separate minor heap per
thread, which actually eases the task a lot - memory is in most cases
allocated in the minor heap anyway. Many variables keeping the state of
the runtime are then thread-local.

Gerd

> 
> 
> Ciao,
>    Oliver
> 
> _______________________________________________
> 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
> 


-- 
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------


  parent reply	other threads:[~2010-11-30 14:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <fa.sn187DUeFX1sJ62LL4s6SatUR/c@ifi.uio.no>
     [not found] ` <fa.PTndTGw0Otg08P5/YMoxmRptrPs@ifi.uio.no>
     [not found]   ` <fa.0ulojaV8bXHHiRN+1r6S98RGEsw@ifi.uio.no>
     [not found]     ` <fa.gQ7B1GYcdbBVupZowIyW2+1E/b4@ifi.uio.no>
     [not found]       ` <fa.ludbTMBmN7YGqnEwsRPwOGCpjrA@ifi.uio.no>
     [not found]         ` <fa.srfZThtnO8lApSpMeW3POD462Xg@ifi.uio.no>
2010-11-30  8:10           ` Stephan Houben
2010-11-30 12:55             ` oliver
2010-11-30 13:06               ` Eray Ozkural
2010-11-30 21:13                 ` Jon Harrop
2010-11-30 21:28                   ` Christophe Raffalli
2010-11-30 14:09               ` Gerd Stolpmann [this message]
     [not found] <fa.eehhGhbses+7RvDlflKpXQ8Uu34@ifi.uio.no>
     [not found] ` <fa.UVXWB7NnPNJbhh0Cf2OLmzYx/bQ@ifi.uio.no>
     [not found]   ` <fa.uksiRZ6fYFia4X1fXQaWa8z4Kio@ifi.uio.no>
     [not found]     ` <fa.Zv2Wkh0+DJAuXcOzq+qABiYFTP4@ifi.uio.no>
     [not found]       ` <fa.W5DnVSXs073N1X2rbtpyh7iGAcc@ifi.uio.no>
     [not found]         ` <fa.LGfjfIGKcYLW6PBxy7aMsEnvy/w@ifi.uio.no>
2010-11-30 15:30           ` Stephan Houben
2010-11-30 16:07             ` Gerd Stolpmann
2010-11-30 17:40               ` oliver
     [not found] <fa.B9mcuN46iEGhXlge41VUCLz69+Y@ifi.uio.no>
     [not found] ` <fa.D3cDWzaD9Uu03+KvekpwpBGCx7o@ifi.uio.no>
     [not found]   ` <fa.xsCCCeDYPj8J16i9UrdqxoOIQ0Y@ifi.uio.no>
     [not found]     ` <fa.SW2Swldk88Bs5ujaNHT8Yh4bXkg@ifi.uio.no>
     [not found]       ` <fa.V+M6RbukE/w/Aftpwxkx2MvkxlU@ifi.uio.no>
     [not found]         ` <fa.+OkqNL3AB4+5LA8wOnQD9WS59QQ@ifi.uio.no>
2010-11-30 14:04           ` Stephan Houben
2010-11-30 14:22             ` Gerd Stolpmann
2010-11-30 14:29             ` oliver
2010-11-30 15:17               ` Eray Ozkural
2010-11-22 17:08 [Caml-list] Is OCaml fast? David Rajchenbach-Teller
2010-11-23  2:01 ` Isaac Gouy
2010-11-23 23:27   ` [Caml-list] " oliver
2010-11-24  0:23     ` Isaac Gouy
2010-11-24  1:36       ` [Caml-list] " Eray Ozkural
2010-11-24  2:13         ` Isaac Gouy
2010-11-24  4:39           ` [Caml-list] " Jeff Meister
2010-11-25 16:59             ` Stefan Monnier
     [not found]               ` <1534555381.33107.1290723160355.JavaMail.root@zmbs4.inria.fr>
2010-11-25 22:50                 ` [Caml-list] " Fabrice Le Fessant
2010-11-28 18:14                   ` oliver
2010-11-29 14:19                     ` Gerd Stolpmann
2010-11-29 16:12                       ` Threading and SharedMem (Re: [Caml-list] Re: Is OCaml fast?) Oliver Bandel
2010-11-29 16:24                         ` Gerd Stolpmann
2010-11-29 16:33                           ` Oliver Bandel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1291126157.16005.567.camel@thinkpad \
    --to=info@gerd-stolpmann.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=oliver@first.in-berlin.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).