public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] malloc: Fix missing accounting of top chunk in malloc_info [BZ #24026]
@ 2019-08-01 12:12 Florian Weimer
  2019-08-01 15:54 ` Carlos O'Donell
  0 siblings, 1 reply; 10+ messages in thread
From: Florian Weimer @ 2019-08-01 12:12 UTC (permalink / raw)
  To: libc-alpha; +Cc: Niklas Hambüchen

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);

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-08-12  3:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 12:12 [PATCH] malloc: Fix missing accounting of top chunk in malloc_info [BZ #24026] Florian Weimer
2019-08-01 15:54 ` Carlos O'Donell
2019-08-01 16:36   ` Florian Weimer
2019-08-02 17:49     ` Carlos O'Donell
2019-08-02 19:03       ` DJ Delorie
2019-08-02 19:54       ` Joseph Myers
2019-08-02 20:35         ` DJ Delorie
2019-08-07 14:28       ` Florian Weimer
2019-08-08 18:21         ` Carlos O'Donell
2019-08-12  3:12           ` Niklas Hambüchen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).