You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by Daniel Shahaf <da...@elego.de> on 2012/04/13 16:35:30 UTC

Re: svn commit: r1325478 - in /subversion/trunk/subversion: include/svn_pools.h libsvn_subr/pool.c

stefan2@apache.org wrote on Thu, Apr 12, 2012 at 20:02:37 -0000:
> Author: stefan2
> Date: Thu Apr 12 20:02:36 2012
> New Revision: 1325478
> 
> URL: http://svn.apache.org/viewvc?rev=1325478&view=rev
> Log:
> Introduce a new API function to create and initialize a new
> APR pool allocator. Make its thread-safety properties
> explicit in the docstring.
> 
> Will be used by the next commit to replace boilerplate code.
> 
> * subversion/include/svn_pools.h
>   (svn_pool_create_allocator): declare new API function
> * subversion/libsvn_subr/pool.c
>   (svn_pool_create_allocator): declare new API function
> 
> Modified:
>     subversion/trunk/subversion/include/svn_pools.h
>     subversion/trunk/subversion/libsvn_subr/pool.c
> 
> Modified: subversion/trunk/subversion/include/svn_pools.h
> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_pools.h?rev=1325478&r1=1325477&r2=1325478&view=diff
> ==============================================================================
> --- subversion/trunk/subversion/include/svn_pools.h (original)
> +++ subversion/trunk/subversion/include/svn_pools.h Thu Apr 12 20:02:36 2012
> @@ -30,7 +30,7 @@
>  #ifndef SVN_POOLS_H
>  #define SVN_POOLS_H
>  
> -#include <apr_pools.h>
> +#include "svn_types.h"
>  
>  #ifdef __cplusplus
>  extern "C" {
> @@ -86,6 +86,23 @@ svn_pool_create_ex_debug(pool, allocator
>   */
>  #define svn_pool_destroy apr_pool_destroy
>  
> +/** Return a new allocator.  This function limits the unused memory in the
> + * new allocator to @ref SVN_ALLOCATOR_RECOMMENDED_MAX_FREE and ensures
> + * proper synchronization if the allocator is used by multiple threads.
> + *
> + * If your application uses multiple threads, creating a separate allocator
> + * for each of these threads may not be feasible. Set the @a thread_safe
> + * parameter to @c TRUE in that case.  Pools will still not thread-safe, i.e.
> + * access to them may require explicit serialization.  Set the parameter to
> + * @c FALSE, otherwise, to maximize performance. 
> + * 
> + * To access the owner pool, which can also serve as the root pool for your
> + * sub-pools, call @c apr_allocator_get_owner().
> + *
> + * @since: New in 1.8
> + */
> +apr_allocator_t *
> +svn_pool_create_allocator(svn_boolean_t thread_safe);

Should this be an svn-private API?  Should it take a parameter
that allows overriding the SVN_ALLOCATOR_RECOMMENDED_MAX_FREE default?

Re: svn commit: r1325478 - in /subversion/trunk/subversion: include/svn_pools.h libsvn_subr/pool.c

Posted by Daniel Shahaf <da...@elego.de>.
Stefan Fuhrmann wrote on Fri, Apr 13, 2012 at 15:55:18 +0200:
> Am 13.04.2012 16:35, schrieb Daniel Shahaf:
>> stefan2@apache.org wrote on Thu, Apr 12, 2012 at 20:02:37 -0000:
>>> Author: stefan2
>>> Date: Thu Apr 12 20:02:36 2012
>>> New Revision: 1325478
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1325478&view=rev
>>> Log:
>>> Introduce a new API function to create and initialize a new
>>> APR pool allocator. Make its thread-safety properties
>>> explicit in the docstring.
>>>
>>> Will be used by the next commit to replace boilerplate code.
>>>
>>> * subversion/include/svn_pools.h
>>>    (svn_pool_create_allocator): declare new API function
>>> * subversion/libsvn_subr/pool.c
>>>    (svn_pool_create_allocator): declare new API function
>>>
>>> Modified:
>>>      subversion/trunk/subversion/include/svn_pools.h
>>>      subversion/trunk/subversion/libsvn_subr/pool.c
>>>
>>> Modified: subversion/trunk/subversion/include/svn_pools.h
>>> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_pools.h?rev=1325478&r1=1325477&r2=1325478&view=diff
>>> ==============================================================================
>>> --- subversion/trunk/subversion/include/svn_pools.h (original)
>>> +++ subversion/trunk/subversion/include/svn_pools.h Thu Apr 12 20:02:36 2012
>>> @@ -30,7 +30,7 @@
>>>   #ifndef SVN_POOLS_H
>>>   #define SVN_POOLS_H
>>>
>>> -#include<apr_pools.h>
>>> +#include "svn_types.h"
>>>
>>>   #ifdef __cplusplus
>>>   extern "C" {
>>> @@ -86,6 +86,23 @@ svn_pool_create_ex_debug(pool, allocator
>>>    */
>>>   #define svn_pool_destroy apr_pool_destroy
>>>
>>> +/** Return a new allocator.  This function limits the unused memory in the
>>> + * new allocator to @ref SVN_ALLOCATOR_RECOMMENDED_MAX_FREE and ensures
>>> + * proper synchronization if the allocator is used by multiple threads.
>>> + *
>>> + * If your application uses multiple threads, creating a separate allocator
>>> + * for each of these threads may not be feasible. Set the @a thread_safe
>>> + * parameter to @c TRUE in that case.  Pools will still not thread-safe, i.e.
>>> + * access to them may require explicit serialization.  Set the parameter to
>>> + * @c FALSE, otherwise, to maximize performance.
>>> + *
>>> + * To access the owner pool, which can also serve as the root pool for your
>>> + * sub-pools, call @c apr_allocator_get_owner().
>>> + *
>>> + * @since: New in 1.8
>>> + */
>>> +apr_allocator_t *
>>> +svn_pool_create_allocator(svn_boolean_t thread_safe);
>> Should this be an svn-private API?  Should it take a parameter
>> that allows overriding the SVN_ALLOCATOR_RECOMMENDED_MAX_FREE default?
>>
> Not too long ago, I spent a couple of days hunting
> memory corruptions. The reason turned out to be
> the allocator not being thread-safe by default while
> the default allocator was.
>
> I think this interface is useful for people writing SVN
> clients and should therefore be public. The max free
> memory parameter can be modified at any time via
> apr_allocator_max_free_set() and it is rarely necessary.
> So, I would prefer a simpler API in that case.
>

Fair enough, thanks.

> -- Stefan^2.

Re: svn commit: r1325478 - in /subversion/trunk/subversion: include/svn_pools.h libsvn_subr/pool.c

Posted by Stefan Fuhrmann <st...@alice-dsl.de>.
Am 13.04.2012 18:44, schrieb Philip Martin:
> Stefan Fuhrmann<st...@alice-dsl.de>  writes:
>
>> Am 13.04.2012 16:35, schrieb Daniel Shahaf:
>>> stefan2@apache.org wrote on Thu, Apr 12, 2012 at 20:02:37 -0000:
>>>> + * @since: New in 1.8
>>>> + */
>>>> +apr_allocator_t *
>>>> +svn_pool_create_allocator(svn_boolean_t thread_safe);
>>> Should this be an svn-private API?  Should it take a parameter
>>> that allows overriding the SVN_ALLOCATOR_RECOMMENDED_MAX_FREE default?
>>>
>> Not too long ago, I spent a couple of days hunting
>> memory corruptions. The reason turned out to be
>> the allocator not being thread-safe by default while
>> the default allocator was.
> If that's correct then this bug is present in all Subversion releases;
> does it affect threaded Apache or threaded svnserve?  Do we need to
> backport to 1.7 and 1.6?
>
I thought the same thing but in SVN, in those few places
where we use multiple threads, we actually create an
allocator per thread.

The problem only occurs if you e.g. want to use a single
allocator throughout your multi-threaded application.

-- Stefan^2.

Re: svn commit: r1325478 - in /subversion/trunk/subversion: include/svn_pools.h libsvn_subr/pool.c

Posted by Philip Martin <ph...@wandisco.com>.
Stefan Fuhrmann <st...@alice-dsl.de> writes:

> Am 13.04.2012 16:35, schrieb Daniel Shahaf:
>> stefan2@apache.org wrote on Thu, Apr 12, 2012 at 20:02:37 -0000:

>>> + * @since: New in 1.8
>>> + */
>>> +apr_allocator_t *
>>> +svn_pool_create_allocator(svn_boolean_t thread_safe);
>> Should this be an svn-private API?  Should it take a parameter
>> that allows overriding the SVN_ALLOCATOR_RECOMMENDED_MAX_FREE default?
>>
> Not too long ago, I spent a couple of days hunting
> memory corruptions. The reason turned out to be
> the allocator not being thread-safe by default while
> the default allocator was.

If that's correct then this bug is present in all Subversion releases;
does it affect threaded Apache or threaded svnserve?  Do we need to
backport to 1.7 and 1.6?

-- 
uberSVN: Apache Subversion Made Easy
http://www.uberSVN.com

Re: svn commit: r1325478 - in /subversion/trunk/subversion: include/svn_pools.h libsvn_subr/pool.c

Posted by Stefan Fuhrmann <st...@alice-dsl.de>.
Am 13.04.2012 16:35, schrieb Daniel Shahaf:
> stefan2@apache.org wrote on Thu, Apr 12, 2012 at 20:02:37 -0000:
>> Author: stefan2
>> Date: Thu Apr 12 20:02:36 2012
>> New Revision: 1325478
>>
>> URL: http://svn.apache.org/viewvc?rev=1325478&view=rev
>> Log:
>> Introduce a new API function to create and initialize a new
>> APR pool allocator. Make its thread-safety properties
>> explicit in the docstring.
>>
>> Will be used by the next commit to replace boilerplate code.
>>
>> * subversion/include/svn_pools.h
>>    (svn_pool_create_allocator): declare new API function
>> * subversion/libsvn_subr/pool.c
>>    (svn_pool_create_allocator): declare new API function
>>
>> Modified:
>>      subversion/trunk/subversion/include/svn_pools.h
>>      subversion/trunk/subversion/libsvn_subr/pool.c
>>
>> Modified: subversion/trunk/subversion/include/svn_pools.h
>> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_pools.h?rev=1325478&r1=1325477&r2=1325478&view=diff
>> ==============================================================================
>> --- subversion/trunk/subversion/include/svn_pools.h (original)
>> +++ subversion/trunk/subversion/include/svn_pools.h Thu Apr 12 20:02:36 2012
>> @@ -30,7 +30,7 @@
>>   #ifndef SVN_POOLS_H
>>   #define SVN_POOLS_H
>>
>> -#include<apr_pools.h>
>> +#include "svn_types.h"
>>
>>   #ifdef __cplusplus
>>   extern "C" {
>> @@ -86,6 +86,23 @@ svn_pool_create_ex_debug(pool, allocator
>>    */
>>   #define svn_pool_destroy apr_pool_destroy
>>
>> +/** Return a new allocator.  This function limits the unused memory in the
>> + * new allocator to @ref SVN_ALLOCATOR_RECOMMENDED_MAX_FREE and ensures
>> + * proper synchronization if the allocator is used by multiple threads.
>> + *
>> + * If your application uses multiple threads, creating a separate allocator
>> + * for each of these threads may not be feasible. Set the @a thread_safe
>> + * parameter to @c TRUE in that case.  Pools will still not thread-safe, i.e.
>> + * access to them may require explicit serialization.  Set the parameter to
>> + * @c FALSE, otherwise, to maximize performance.
>> + *
>> + * To access the owner pool, which can also serve as the root pool for your
>> + * sub-pools, call @c apr_allocator_get_owner().
>> + *
>> + * @since: New in 1.8
>> + */
>> +apr_allocator_t *
>> +svn_pool_create_allocator(svn_boolean_t thread_safe);
> Should this be an svn-private API?  Should it take a parameter
> that allows overriding the SVN_ALLOCATOR_RECOMMENDED_MAX_FREE default?
>
Not too long ago, I spent a couple of days hunting
memory corruptions. The reason turned out to be
the allocator not being thread-safe by default while
the default allocator was.

I think this interface is useful for people writing SVN
clients and should therefore be public. The max free
memory parameter can be modified at any time via
apr_allocator_max_free_set() and it is rarely necessary.
So, I would prefer a simpler API in that case.

-- Stefan^2.