Red Hat Bugzilla – Bug 1460043
malloc_stats() should correctly represent large (>4GB) arenas.
Last modified: 2017-07-20 04:50:50 EDT
Description of problem:
In __malloc_stats(), mi.arena (defined as size_t) is cast to unsigned int, causing incorrect values to be displayed for > 4GB.
fprintf (stderr, "system bytes = %10u\n", (unsigned int) mi.arena);
fprintf (stderr, "in use bytes = %10u\n", (unsigned int) mi.uordblks);
Version-Release number of selected component (if applicable):
Linux XXXXXX 2.6.32-573.12.1.el6.x86_64 #1 SMP Mon Nov 23 12:55:32 EST 2015 x86_64 x86_64 x86_64 GNU/Linux
LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 6.7 (Santiago)
The above problem also exists in glib 2.25.
Red Hat Enterprise Linux 6 is a production stage 3 OS and the kind of change you are suggesting is not suitable for this release. Instead I'm moving this bug to RHEL 7 where the problem is still present.
The public API which is relevant is malloc_stats(), and the result is cast to (int) because it's using mallinfo() internally and it only returns int sized results.
DJ Delorie (on the glibc team) is looking at mallinfo() (https://sourceware.org/ml/libc-alpha/2016-10/msg00142.html) to make it saturing. In the case of mallinfo we have a published API which only has type 'int' so we can't do any real fixes for mallinfo(). However, we might be able to get 'unsigned int' out of the interface e.g. up to 4GB (right now signed int is 2GB).
An even better solution for malloc_stats() exists, and that is to use size_t internally and print the values as correctly as possible, avoiding the use of mallinfo() internally.