From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19166 invoked by alias); 18 Oct 2016 16:46:21 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 18793 invoked by uid 89); 18 Oct 2016 16:46:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_NEUTRAL autolearn=no version=3.3.2 spammy=online, concluded X-HELO: homiemail-a57.g.dreamhost.com Reply-To: siddhesh@sourceware.org Subject: Re: [PATCH 2/2] Document the M_ARENA_* mallopt parameters References: <1476120388-26662-1-git-send-email-siddhesh@sourceware.org> <1476120388-26662-2-git-send-email-siddhesh@sourceware.org> <8183dc36-7d6a-bbfc-b6ff-568a2de8af28@redhat.com> <33f30947-9f11-363e-3f35-6c593632f000@sourceware.org> To: "Michael Kerrisk (man-pages)" , Carlos O'Donell Cc: libc-alpha From: Siddhesh Poyarekar Message-ID: <968422de-27f2-3359-6a76-61c152c253dd@sourceware.org> Date: Tue, 18 Oct 2016 16:46:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-10/txt/msg00310.txt.bz2 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