Calls to mallinfo return an zero filled mallinfo structure... ~/cvs/valgrind-2.4.0/coregrind/vg_replace_malloc.c === LIBALIAS(struct mallinfo, mallinfo, ( void )) { /* Should really try to return something a bit more meaningful */ UInt i; struct mallinfo mi; UChar* pmi = (UChar*)(&mi); for (i = 0; i < sizeof(mi); i++) pmi[i] = 0; return mi; } === msimons@furball:~/sample/getr$ ./lx/test_mai 1 loop 1: arena 972, ordblks 1, smblks 0, hblks 0, hblkhd 0, usmblks 0, fsmblks 0, uordblks 20, fordblks 952, keepcost 952 loop 3: arena 972, ordblks 1, smblks 0, hblks 0, hblkhd 0, usmblks 0, fsmblks 0, uordblks 420, fordblks 552, keepcost 552 loop 7: arena 5068, ordblks 1, smblks 0, hblks 0, hblkhd 0, usmblks 0, fsmblks 0, uordblks 2756, fordblks 2312, keepcost 2312 loop 15: arena 17356, ordblks 1, smblks 0, hblks 0, hblkhd 0, usmblks 0, fsmblks 0, uordblks 13572, fordblks 3784, keepcost 3784 [...] msimons@furball:~/sample/getr$ ~/local/valgrind-1/bin/valgrind --error-limit=no --tool=memcheck ./lx/test_mai 1 ==1212== Memcheck, a memory error detector for x86-linux. ==1212== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al. ==1212== Using valgrind-2.4.0, a program supervision framework for x86-linux. ==1212== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al. ==1212== For more details, rerun with: -v ==1212== ==1212== Conditional jump or move depends on uninitialised value(s) ==1212== at 0x190F015F: _dl_start (do-rel.h:73) ==1212== by 0x190EFE95: (within /lib/ld-2.2.4.so) ==1212== ==1212== Conditional jump or move depends on uninitialised value(s) ==1212== at 0x190F016C: _dl_start (do-rel.h:95) ==1212== by 0x190EFE95: (within /lib/ld-2.2.4.so) ==1212== ==1212== Conditional jump or move depends on uninitialised value(s) ==1212== at 0x190F01A1: _dl_start (do-rel.h:104) ==1212== by 0x190EFE95: (within /lib/ld-2.2.4.so) loop 1: arena 0, ordblks 0, smblks 0, hblks 0, hblkhd 0, usmblks 0, fsmblks 0, uordblks 0, fordblks 0, keepcost 0 loop 3: arena 0, ordblks 0, smblks 0, hblks 0, hblkhd 0, usmblks 0, fsmblks 0, uordblks 0, fordblks 0, keepcost 0 loop 7: arena 0, ordblks 0, smblks 0, hblks 0, hblkhd 0, usmblks 0, fsmblks 0, uordblks 0, fordblks 0, keepcost 0 loop 15: arena 0, ordblks 0, smblks 0, hblks 0, hblkhd 0, usmblks 0, fsmblks 0, uordblks 0, fordblks 0, keepcost 0
Created attachment 12072 [details] program to test measure performance of mallinfo ... number of arguments influence behavior... none - only calls mallinfo in a tight loop, does nothing with result. 1 - allocate memory and print out results every so often. 2 - allocate "big chunks" of memory so mmap is used, and print out results.
As you've seen, Valgrind's mallinfo() returns all zeroes. Do you have a real program that uses mallinfo(), or did you just notice it was unimplemented? If it's just the latter, I think we can leave it unimplemented for the moment. mallinfo() is a strange function, it seems very tied to a particular implementation, for example the distinction between "small" blocks and "normal" blocks, which Valgrind's allocator does not have.
On Sat, Aug 13, 2005 at 02:44:36PM -0000, Nicholas Nethercote wrote: > As you've seen, Valgrind's mallinfo() returns all zeroes. Do you > have a real program that uses mallinfo(), or did you just notice it > was unimplemented? If it's just the latter, I think we can leave it > unimplemented for the moment. > > mallinfo() is a strange function, it seems very tied to a particular > implementation, for example the distinction between "small" blocks and > "normal" blocks, which Valgrind's allocator does not have. I have a real program (application server) that tracks it's own memory leaks from request to request using mallinfo... there should be no leaks, but at least this helps flush out transactions flows which need to be looked at. Since the server itself is stateless, it tries to exit cleanly after leaking a certain number of megs, so a replacement will be started. The call is a little strange but is very portable because it is defined in some standard, AIX/HPUX/Solaris/Tru66 all return the important information in the same way... Linux is an odd ball wrt to which fields of the structure it fills in, but the info we need is there (how much memory is being used "now").
> The call is a little strange but is very portable because it is defined in > some standard, AIX/HPUX/Solaris/Tru66 all return the important information > in the same way... Linux is an odd ball wrt to which fields of the > structure it fills in, but the info we need is there (how much memory is > being used "now"). Which fields do you use -- uordblks? /* SVID2/XPG mallinfo structure */ struct mallinfo { int arena; /* total space allocated from system */ int ordblks; /* number of non-inuse chunks */ int smblks; /* unused -- always zero */ int hblks; /* number of mmapped regions */ int hblkhd; /* total space in mmapped regions */ int usmblks; /* unused -- always zero */ int fsmblks; /* unused -- always zero */ int uordblks; /* total allocated space */ int fordblks; /* total non-inuse space */ int keepcost; /* top-most, releasable (via malloc_trim) space */ };
On Sat, Aug 13, 2005 at 05:16:02PM -0000, Nicholas Nethercote wrote: > ------- Additional Comments From njn cs utexas edu 2005-08-13 19:15 ------- > > The call is a little strange but is very portable because it is defined in > > some standard, AIX/HPUX/Solaris/Tru66 all return the important information > > in the same way... Linux is an odd ball wrt to which fields of the > > structure it fills in, but the info we need is there (how much memory is > > being used "now"). > > Which fields do you use -- uordblks? > > /* SVID2/XPG mallinfo structure */ > struct mallinfo { > int arena; /* total space allocated from system */ > int ordblks; /* number of non-inuse chunks */ > int smblks; /* unused -- always zero */ > int hblks; /* number of mmapped regions */ > int hblkhd; /* total space in mmapped regions */ > int usmblks; /* unused -- always zero */ > int fsmblks; /* unused -- always zero */ > int uordblks; /* total allocated space */ > int fordblks; /* total non-inuse space */ > int keepcost; /* top-most, releasable (via malloc_trim) space */ > }; If I remember correctly: === uordblks + hblkhd ... are the primary ones needed, on linux those represent the total allocated used bytes. === The other fields should not be required by leak tracking logic.
I've partially implemented this. The fields are all still zero, but I put the plumbing in that was necessary to connect it up to our allocator. I'm going to be away for a week or so, if you are interested in implementing it yourself then check out the latest SVN repo, and look at coregrind/m_mallocfree.c. You can see a stub version of VG_(mallinfo)() in there. You'll need to work out which of the stats you need, and add appropriate code to record how much memory is allocated/deallocated by functions like VG_(arena_malloc)() and VG_(arena_free)(). It shouldn't be too hard.
This was implemented a while ago.