| Index: third_party/tcmalloc/chromium/src/system-alloc.cc
|
| diff --git a/third_party/tcmalloc/chromium/src/system-alloc.cc b/third_party/tcmalloc/chromium/src/system-alloc.cc
|
| index 03fc9340ec9334e4d8eef20c4a653586d2e192c7..511990c654c95a85eb713e4a557781cbd0dff192 100644
|
| --- a/third_party/tcmalloc/chromium/src/system-alloc.cc
|
| +++ b/third_party/tcmalloc/chromium/src/system-alloc.cc
|
| @@ -48,7 +48,7 @@
|
| #include <unistd.h> // for sbrk, getpagesize, off_t
|
| #endif
|
| #include <new> // for operator new
|
| -#include <google/malloc_extension.h>
|
| +#include <gperftools/malloc_extension.h>
|
| #include "base/basictypes.h"
|
| #include "base/commandlineflags.h"
|
| #include "base/spinlock.h" // for SpinLockHolder, SpinLock, etc
|
| @@ -61,6 +61,13 @@
|
| # define MAP_ANONYMOUS MAP_ANON
|
| #endif
|
|
|
| +// MADV_FREE is specifically designed for use by malloc(), but only
|
| +// FreeBSD supports it; in linux we fall back to the somewhat inferior
|
| +// MADV_DONTNEED.
|
| +#if !defined(MADV_FREE) && defined(MADV_DONTNEED)
|
| +# define MADV_FREE MADV_DONTNEED
|
| +#endif
|
| +
|
| // Solaris has a bug where it doesn't declare madvise() for C++.
|
| // http://www.opensolaris.org/jive/thread.jspa?threadID=21035&tstart=0
|
| #if defined(__sun) && defined(__SVR4)
|
| @@ -76,6 +83,10 @@ static const bool kDebugMode = false;
|
| static const bool kDebugMode = true;
|
| #endif
|
|
|
| +// TODO(sanjay): Move the code below into the tcmalloc namespace
|
| +using tcmalloc::kLog;
|
| +using tcmalloc::Log;
|
| +
|
| // Anonymous namespace to avoid name conflicts on "CheckAddressBits".
|
| namespace {
|
|
|
| @@ -103,9 +114,11 @@ union MemoryAligner {
|
|
|
| static SpinLock spinlock(SpinLock::LINKER_INITIALIZED);
|
|
|
| +#if defined(HAVE_MMAP) || defined(MADV_FREE)
|
| #ifdef HAVE_GETPAGESIZE
|
| static size_t pagesize = 0;
|
| #endif
|
| +#endif
|
|
|
| // The current system allocator
|
| SysAllocator* sys_alloc = NULL;
|
| @@ -132,7 +145,6 @@ public:
|
| SbrkSysAllocator() : SysAllocator() {
|
| }
|
| void* Alloc(size_t size, size_t *actual_size, size_t alignment);
|
| - void FlagsInitialized() {}
|
| };
|
| static char sbrk_space[sizeof(SbrkSysAllocator)];
|
|
|
| @@ -141,7 +153,6 @@ public:
|
| MmapSysAllocator() : SysAllocator() {
|
| }
|
| void* Alloc(size_t size, size_t *actual_size, size_t alignment);
|
| - void FlagsInitialized() {}
|
| };
|
| static char mmap_space[sizeof(MmapSysAllocator)];
|
|
|
| @@ -150,7 +161,6 @@ public:
|
| DevMemSysAllocator() : SysAllocator() {
|
| }
|
| void* Alloc(size_t size, size_t *actual_size, size_t alignment);
|
| - void FlagsInitialized() {}
|
| };
|
|
|
| class DefaultSysAllocator : public SysAllocator {
|
| @@ -171,7 +181,6 @@ class DefaultSysAllocator : public SysAllocator {
|
| }
|
| }
|
| void* Alloc(size_t size, size_t *actual_size, size_t alignment);
|
| - void FlagsInitialized() {}
|
|
|
| private:
|
| static const int kMaxAllocators = 2;
|
| @@ -420,7 +429,6 @@ void* DefaultSysAllocator::Alloc(size_t size, size_t *actual_size,
|
| if (result != NULL) {
|
| return result;
|
| }
|
| - TCMalloc_MESSAGE(__FILE__, __LINE__, "%s failed.\n", names_[i]);
|
| failed_[i] = true;
|
| }
|
| }
|
| @@ -499,10 +507,10 @@ size_t TCMalloc_SystemAddGuard(void* start, size_t size) {
|
| }
|
|
|
| void TCMalloc_SystemRelease(void* start, size_t length) {
|
| -#ifdef MADV_DONTNEED
|
| +#ifdef MADV_FREE
|
| if (FLAGS_malloc_devmem_start) {
|
| - // It's not safe to use MADV_DONTNEED if we've been mapping
|
| - // /dev/mem for heap memory
|
| + // It's not safe to use MADV_FREE/MADV_DONTNEED if we've been
|
| + // mapping /dev/mem for heap memory.
|
| return;
|
| }
|
| if (pagesize == 0) pagesize = getpagesize();
|
| @@ -526,7 +534,7 @@ void TCMalloc_SystemRelease(void* start, size_t length) {
|
| // Note -- ignoring most return codes, because if this fails it
|
| // doesn't matter...
|
| while (madvise(reinterpret_cast<char*>(new_start), new_end - new_start,
|
| - MADV_DONTNEED) == -1 &&
|
| + MADV_FREE) == -1 &&
|
| errno == EAGAIN) {
|
| // NOP
|
| }
|
|
|