casseopea2 / gperftools

Automatically exported from code.google.com/p/gperftools
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Enhancement: memory allocation size introspection #110

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Many malloc implementations include different ways to determine the actual
size of allocated blocks.  Mac OS X (BSD?) includes malloc_size and
malloc_good_size, Linux (ptmalloc) includes malloc_usable_size, etc. 
Perftools in fact provides implementations of these on some platforms.

Perftools does not include an easy, portable way to do this however, even
though the info is easily determined inside tcmalloc.  The attached patch
proposes one way to do this elegantly.  The patch adds two optional
GetAllocatedSize methods to the MallocExtension interface.  One variation
returns the actual size of a previously allocated block, and the other
returns the estimated actual size of an allocated block, given the
requested size.  (These correspond to the BSD malloc_size and
malloc_good_size, respectively.)

The patch also modifies tcmalloc to provide implementations of these.

Original issue reported on code.google.com by roger.a....@gmail.com on 24 Feb 2009 at 5:59

Attachments:

GoogleCodeExporter commented 9 years ago
This seems like a good idea to me -- given so many other malloc implementations
provide this, it seems like there's likely to be demand in tcmalloc going 
forward. 
I'll check with some of the other tcmalloc folks here, but assuming no 
objections,
this functionality will make it into the next perftools release.

btw, nice patch! -- "elegantly" does really fit here.

Original comment by csilv...@gmail.com on 24 Feb 2009 at 8:05

GoogleCodeExporter commented 9 years ago
Thanks!  I didn't want to invent a new mechanism when MallocExtension fits 
perfectly.

FWIW, I (obviously) have a need for this, so I can vouch for its usefulness.  
It's
not commonly needed, but when it is it's best to get the info straight from the
malloc library itself -- if it's available.  Solaris, for instance, has nothing 
of
the sort in its default malloc library.  Consistent cross-platform behavior is 
the
main reason I'm interested in tcmalloc, and the performance improvement is a 
nice bonus.

Of course if the team decides not to adopt it I'll still be able to maintain my 
fork,
so no worries there.

Original comment by roger.a....@gmail.com on 24 Feb 2009 at 8:16

GoogleCodeExporter commented 9 years ago
This is implemented in perftools 1.1, just released.  Two new functions have 
been
addded to MallocExtension.

Original comment by csilv...@gmail.com on 11 Mar 2009 at 9:21