This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 2/2] Document the M_ARENA_* mallopt parameters


On Tuesday 18 October 2016 09:33 PM, Michael Kerrisk (man-pages) wrote:
>>> I don't think you're correct here. 'arena_max' is a field in a static
>>> structure that is not otherwise initialized, AFAICT. So, it has the
>>> value zero. (Some dirty hacking with a program that uses
>>> malloc_get_state() and inspects the internal data structure seems
>>> to confirm this.)
>>>
>>> And then in malloc/arena.c we have
>>>
>>>           if (mp_.arena_max != 0)
>>>             narenas_limit = mp_.arena_max;
>>>           else if (narenas > mp_.arena_test)
>>>             {
>>>               int n = __get_nprocs ();
>>>               
>>>               if (n >= 1)
>>>                 narenas_limit = NARENAS_FROM_NCORES (n);
>>>               else
>>>                 /* We have no information about the system.  Assume two
>>>                    cores.  */ 
>>>                 narenas_limit = NARENAS_FROM_NCORES (2);
>>>
>>> So, I believe my original statement about M_ARENA_MAX is correct.
>>> Have I missed something?
>>
>> You're right in that the variable arena_max is initialized to 0.
> 
> Okay.
> 
>> However you also concluded that there is no limit to the number of
>> arenas that can be created when arena_max is 0, which is incorrect.  As
>> the code snippet you pasted above shows that if arena_max is 0, once we
>> cross arena_test arenas, the narenas_limit static variable is set to a
>> default upper limit based on the number of cores.  That acts as the
>> upper limit to the number of arenas that can be created when arena_max is 0.
> 
> D'oh!  Yes, of course. Thanks for that. Not sure how I managed to 
> misread that code :-}. So a better formulation would be something like:
> 
>     The default value of this parameter is 0, meaning that the limit on 
>     the number of arenas is determined according to the setting of
>     M_ARENA_TEST.

No, it is not the value of M_ARENA_TEST :)

M_ARENA_TEST is set by default to NARENAS_FROM_CORES(1).  The limit on
the number of arenas is decided after M_ARENA_TEST number of arenas have
already created, but it is actually set to NARENAS_FROM_CORES(n), where
n is the number of cores.  If we can't find the number of cores for some
reason, then we set the limit to NARENAS_FROM_CORES(2).

So something like this is more accurate:

    The default value of this parameter is 0, meaning that the limit on
    the number of arenas is determined by the number of CPU cores
    online and the size of the '''long''' datatype.  For 32-bit systems
    the limit of on the number of arenas is 2 * '''number of CPU cores
    online''' while 64-bit systems, the limit on the number of arenas
    is 8 * '''number of CPU cores online'''.  If information on CPU
    cores is not available, it is assumed that there are 2 CPU cores
    online.

I have implicitly stated here that 32-bit long == 32-bit pointers since
I don't think there are Unix systems that have 32-bit long and 64-bit
pointers and also because the choice of multipliers for cores (2 and 8)
correlates better to the size of the address space than to size of long.

Siddhesh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]