Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Dec 2005 17:20:29 +0100
From:      Johan Bucht <bucht@acc.umu.se>
To:        Daniel Eischen <deischen@freebsd.org>
Cc:        current@freebsd.org
Subject:   Re: New libc malloc patch
Message-ID:  <439DA34D.7040407@acc.umu.se>
In-Reply-To: <Pine.GSO.4.43.0512121026370.24514-100000@sea.ntplx.net>
References:  <Pine.GSO.4.43.0512121026370.24514-100000@sea.ntplx.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Daniel Eischen wrote:

>On Sun, 11 Dec 2005, Jason Evans wrote:
>  
>
>>>>As for supporting recursive spinlocks, I doubt that the overhead
>>>>would be acceptable in general.  If I could get rid of the need for
>>>>the one recursive lock in malloc.c, I certainly would. =)
>>>>        
>>>>
>>>Why do we need a recursive mutex?  Can you not restructure the
>>>code so that it is not needed?
>>>      
>>>
>>There is an internal arena that the malloc code uses for allocating
>>internal data structures.  In some cases, the internal arena has to
>>recursively allocate.  If there were no object caching, it might be
>>possible to pre-allocate, such that recursion never happens, but
>>given the object caching, it's difficult to reason about precisely
>>what will occur internally for a single malloc/free operation.  There
>>are some other possibilities, but nothing I've thought of so far is
>>simple or elegant.
>>    
>>
>
>Well, just lock around the external functions and remove all locking
>from the internal and recursive functions.  Can't all recursion
>be replaced with loops anyways ;-)
>
>  
>
Simple description of the issues following.

First ideal case, no recursive locking needed:

1. Lock the local arena to allocate memory
2. If we need to allocate internal data structures lock the base arena
2.1. Allocate memory from the base arena
2.2. Unlock base arena
3. Unlock local arena

The ideal case assumes that the base arena have everything it needs and 
don't have to set up internal data structures to handle the allocations.

Actual case:

0. From malloc(3) friends get a local arena and pass that into the 
internal functions
1. Lock the supplied arena
2. If we need to allocate internal data structure goto step 1, using the 
base arena instead of one of the local arenas
2.1 Allocate memory from base arena
2.2 Unlock base arena
3. Unlock arena

This means that we can lock the base arena recursivly, should the 
allocation of memory from the base arena need to allocate memory. 
Solving this would need some special handling for the base arena (avoid 
using the same interface as the other arenas or statically allocate the 
base arena).

/Johan Bucht



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?439DA34D.7040407>