[Openmcl-devel] process-run-function and mach ports usage

Willem Rein Oudshoorn woudshoo at xs4all.nl
Tue Feb 22 00:29:43 PST 2011


Gary Byers <gb at clozure.com> writes:

> At this point, I'd probably say that it -looks- like there's a net loss
> of ~1 port every time a thread is created and destroyed, but that isn't
> entirely predictable.

After a bit of experimentation, it seems that it always loses 1 port.
(The first time it might not appear this way because doing a garbage
collect immediately after booting the lisp image it will recover some
ports already.)

After some debugging, it turns out that the mach_thread port is not
freed.  I think I know at least one reason why this is the case, but
that can not be the whole story.  (The mach port business is all
completely new for me, so it takes a bit of time figuring this out.)

The reason this matters:

    (time (ccl:process-run-function "test" (lambda ())))

    returns on my machine values around the follwoing:

During that period, 304 microseconds (0.000304 seconds) were spent in user mode
                    325 microseconds (0.000325 seconds) were spent in system mode


However after
        
    (loop :repeat 10000 :do    
        (ccl:process-run-function "test" (lambda ())))

doing

    (time (ccl:process-run-function "test" (lambda ())))

    returns values in the range of:

During that period, 315 microseconds (0.000315 seconds) were spent in user mode
                    528 microseconds (0.000528 seconds) were spent in system mode


And it is getting progressively worse.  After about 150000 thread
creations,  the same function takes about 10ms.  

>   I haven't looked at things over a long enough
> period of time to have a sense of whether things are transient or whether
> there's a true leak there.

There is a true leak, and I will try to hunt it down.  

> (In the face of all this ignorance, I take comfort in the old adage that
> says that "Mach sucks, but no one understands how.")

I do not know Mach, so I cannot really comment on it.  However it is
hard to find clear unambiguous documentation about the mach kernel
in Mac OS X.

Wim Oudshoorn.

P.S.:  sbcl also loses 1 port per thread creation.
P.S.:  Sorry for replying late, I am a bit swamped
       at the moment and quite a few time consuming obligations
       I can not move around.





More information about the Openmcl-devel mailing list