From patchwork Tue Nov 14 18:08:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 24243 Received: (qmail 14111 invoked by alias); 14 Nov 2017 18:08:37 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 14059 invoked by uid 89); 14 Nov 2017 18:08:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Date: Tue, 14 Nov 2017 19:08:33 +0100 To: libc-alpha@sourceware.org Subject: [PATCH] malloc: Account for all heaps in an arena in malloc_info [BZ #22439] User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20171114180833.5FA9E423CD593@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) This commit adds a "subheads" statistics to the malloc_info output. 2017-11-14 Florian Weimer [BZ #22408] * malloc/malloc.c (__malloc_info): Count all heaps in an arena, not just the top one. Output a new "subheaps" statistic. Reviewed-by: Siddhesh Poyarekar diff --git a/NEWS b/NEWS index b7281621f4..520db40982 100644 --- a/NEWS +++ b/NEWS @@ -63,6 +63,9 @@ Deprecated and removed features, and other changes affecting compatibility: * The res_hnok, res_dnok, res_mailok and res_ownok functions now check that the specified string can be parsed as a domain name. +* In the malloc_info output, the element may contain another + element, "subheaps", which contains the number of sub-heaps. + Changes to build and runtime requirements: [Add changes to build and runtime requirements here] diff --git a/malloc/malloc.c b/malloc/malloc.c index 0494e8c39f..2999ac4d2f 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -5457,11 +5457,19 @@ __malloc_info (int options, FILE *fp) size_t heap_size = 0; size_t heap_mprotect_size = 0; + size_t heap_count = 0; if (ar_ptr != &main_arena) { + /* Iterate over the arena heaps from back to front. */ heap_info *heap = heap_for_ptr (top (ar_ptr)); - heap_size = heap->size; - heap_mprotect_size = heap->mprotect_size; + do + { + heap_size += heap->size; + heap_mprotect_size += heap->mprotect_size; + heap = heap->prev; + ++heap_count; + } + while (heap != NULL); } __libc_lock_unlock (ar_ptr->mutex); @@ -5499,8 +5507,9 @@ __malloc_info (int options, FILE *fp) { fprintf (fp, "\n" - "\n", - heap_size, heap_mprotect_size); + "\n" + "\n", + heap_size, heap_mprotect_size, heap_count); total_aspace += heap_size; total_aspace_mprotect += heap_mprotect_size; }