casseopea2 / gperftools

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

Suggestion: need an option(s) forcing tcmalloc.so to use mmap 'only' or 'sbrk' only #92

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is very useful while debugging some memory problems like
fragmentation, etc.

Maybe such option exists, but due to the lack of documentation I can't find
it? Code like 'allocators[i++] = new (sbrk_space) SbrkSysAllocator();'
definitely suggests that 'sbrk' can be used as allocator.

Conventional malloc accepts options via environment variable
MALLOC_OPTIONS. For example 'dM' forces it to use 'mmap' only and Dm forces
it to use 'sbrk' only. 'DM' is also available. I propose that 'tcmalloc'
does the same.

Also allocation by 'sbrk' and 'mmap' may exhibit different tendencies.
'sbrk' for example has to keep all addresses as low as possible to keep
memory space smaller. 'mmap' doesn't have to do this. It's very
advantageous to give user a choice which one is used.

Original issue reported on code.google.com by visa_des...@yahoo.com on 7 Jan 2009 at 10:00

GoogleCodeExporter commented 9 years ago
} Maybe such option exists, but due to the lack of documentation I can't find
} it?

It is documented here, under "Modifying runtime behavior".
   http://google-perftools.googlecode.com/svn/trunk/doc/tcmalloc.html

} TCMALLOC_SKIP_MMAP    default: false       If true, do not try to use mmap to 
obtain
memory from the kernel. 

If you set this to true, tcmalloc will use sbrk only.  If you set it to false, 
it
will use mmap if possible, and fall back to sbrk if mmap has a problem.  There 
is no
way to use mmap only (and have the malloc fail if the mmap fails?), but it 
sounds
like these two behaviors are sufficient for what you have in mind.

craig

Original comment by csilv...@gmail.com on 7 Jan 2009 at 6:42

GoogleCodeExporter commented 9 years ago
Debugging a bit I found that on 32-bit machine 'mmap' is a fallback for 'sbrk' 
and
not the other way around. This is because SbrkSysAllocator is added to 
allocators
before MmapSysAllocator and therefore takes priority over mmap.

So there is actually no way to force to use only 'mmap' as of 1.0-rc2.

I still believe that it's nicer to add TCMALLOC_SKIP_SBRK with 0 as default to 
leave
user fuller control.

Original comment by visa_des...@yahoo.com on 7 Jan 2009 at 11:55

GoogleCodeExporter commented 9 years ago

Original comment by csilv...@gmail.com on 8 Jan 2009 at 12:13

GoogleCodeExporter commented 9 years ago
} I still believe that it's nicer to add TCMALLOC_SKIP_SBRK with 0 as default 
to leave
} user fuller control.

That makes sense to me.  We'll have this flag (environment var) in the next 
release.

Original comment by csilv...@gmail.com on 9 Jan 2009 at 10:09

GoogleCodeExporter commented 9 years ago
This was added in perftools 1.1, just released.  I'm closing the bug, but feel 
free
to reopen if it does not address your needs.

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