From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 Date: Sat, 5 Sep 2015 16:03:55 +0200 Message-ID: From: Giacomo Tesio To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=f46d04428802ac93b8051f007c74 Subject: [9fans] Privalloc(2) and rfork(RFPROC|RFMEM) (was: a pair nec bugs) Topicbox-Message-UUID: 68b6a8d8-ead9-11e9-9d60-3106f5b1d025 --f46d04428802ac93b8051f007c74 Content-Type: text/plain; charset=UTF-8 2011-05-20 3:30 GMT+02:00 erik quanstrom : > one note is that while i'm aware of privalloc(2), i didn't use it. the > implementation doesn't appear correct for shared-memory procs. > i think there are two issues > - locking is unnecessary. the only preemptable unit of execution is > a process and each process is guarenteed to have its own instance > of _privates and _nprivates. > - for shared-memory procs, we will run out of privates because > the static privinit will be falsely shared. privinit should be replaced > by using a private entry. > In a set of processes that share memory, I need a single per-process location to store the address of structure (which is in turn allocated in the global memory space). Privalloc(2) seemed what I need, but seem that I can't use it properly. In the parent process I do: 1) initialialize a global variable p = (MyStruct **)privalloc(); 2) allocate a MyStruct for every process I'm going to spawn 3) spawn processes with rfork(RFMEM|RFPROC) The spawn() function that call rfork takes a MyStruct* as argument and assign it to *p in the new process. For extra safety I added an assert(*p == nil) just after rfork, and after a few (apparently?) successful spawns, the assert fails. What I need is a sort of thread-local storage for the MyStruct*, so that each child process can find it's own dedicated MyStruct. I know that could get this with an hashtable based on the pid, but I'd prefer to avoid the book keeping if possible. Giacomo --f46d04428802ac93b8051f007c74 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
2011-05-20 3:30 GMT+02:00 erik quanstrom <quanstro@qu= anstro.net>:
one note is that while i'm awar= e of privalloc(2), i didn't use it.=C2=A0 the
implementation doesn't appear correct for shared-memory procs.
i think there are two issues
- locking is unnecessary.=C2=A0 the only preemptable unit of execution is a process and each process is guarenteed to have its own instance
of _privates and _nprivates.
- for shared-memory procs, we will run out of privates because
the static privinit will be falsely shared.=C2=A0 privinit should be replac= ed
by using a private entry.

In a set of p= rocesses that share memory, I need a single per-process location to store t= he address of structure (which is in turn allocated in the global memory sp= ace).

Privalloc(2) seemed what I need, but seem that I ca= n't use it properly.

In the parent process I do:
<= br>
1) initialialize a global variable p =3D (MyStruct **)privall= oc();
2) allocate a MyStruct for every process I'm going = to spawn
3) spawn processes with rfork(RFMEM|RFPROC)

=
The spawn() function that call rfork takes a MyStruct* as argume= nt and assign it to *p in the new process.
For extra safety I added an a= ssert(*p =3D=3D nil) just after rfork, and after a few (apparently?) succes= sful spawns, the assert fails.

What I need is a sort of t= hread-local storage for the MyStruct*, so that each child process can find = it's own dedicated MyStruct.
I know that could get this w= ith an hashtable based on the pid, but I'd prefer to avoid the book kee= ping if possible.


Giacomo
--f46d04428802ac93b8051f007c74--