This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] malloc: Fix missing accounting of top chunk in malloc_info [BZ #24026]
- From: Carlos O'Donell <carlos at redhat dot com>
- To: Florian Weimer <fweimer at redhat dot com>, libc-alpha at sourceware dot org
- Cc: Niklas Hambüchen <mail at nh2 dot me>
- Date: Thu, 1 Aug 2019 11:54:16 -0400
- Subject: Re: [PATCH] malloc: Fix missing accounting of top chunk in malloc_info [BZ #24026]
- References: <87blx9hyo7.fsf@oldenburg2.str.redhat.com>
On 8/1/19 8:12 AM, Florian Weimer wrote:
Author: Niklas Hambüchen <mail@nh2.me>
Fixes `<total type="rest" size="..."> incorrectly showing as 0 most
of the time.
The rest value being wrong is significant because to compute the
actual amount of memory handed out via malloc, the user must subtract
it from <system type="current" size="...">. That result being wrong
makes investigating memory fragmentation issues like
https://bugzilla.redhat.com/show_bug.cgi?id=843478 close to
impossible.
[Patch from Bugzilla. Reformatted for GNU style.]
2019-08-01 Niklas Hambüchen <mail@nh2.me>
[BZ #24026]
* malloc/malloc.c (__malloc_info): Account for top chunk.
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 00ce48cf58..1083cd3ef2 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -5406,6 +5406,10 @@ __malloc_info (int options, FILE *fp)
__libc_lock_lock (ar_ptr->mutex);
+ /* Account for top chunk. */
+ avail = chunksize (ar_ptr->top);
+ nblocks = 1; /* Top always exists. */
+
for (size_t i = 0; i < NFASTBINS; ++i)
{
mchunkptr p = fastbin (ar_ptr, i);
The malloc accounting is quiet complex.
To review this I'd basically have to do a bunch of debugging on
my own to prove this is correct since your proposed patch doesn't
have the required details to validate the change.
Can you post some analysis of a trivial heap and show how this is
a correct fix with before and after numbers?
Can we get a test case that has a trivial setup that shows the fix
is working and in place?
--
Cheers,
Carlos.