[Python-Dev] Removing the GIL (Me, not you!)

Talin talin at acm.org
Sat Sep 15 07:48:40 CEST 2007


Adam Olsen wrote:
> I'm now working on an approach that writes out refcounts in batches to
> reduce contention.  The initial cost is much higher, but it scales
> better too.  I've currently got it to just under 50% cost, meaning two
> threads is a slight net gain.

http://www.research.ibm.com/people/d/dfb/publications.html

Look at the various papers on 'Recycler'.

The way it works is that for each thread, there is an addref buffer and 
a decref buffer. The buffers are arrays of pointers. Each time a 
reference is addref'd, its appended to the addref buffer, likewise for 
decref. When a buffer gets full, it is added to a queue and then a new 
buffer is allocated.

There is a background thread that actually applies the refcounts from 
the buffers and frees the objects. Since this background thread is the 
only thread that ever touches the actual refcount field of the object, 
there's no need for locking.

-- Talin


More information about the Python-Dev mailing list