Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: third_party/tcmalloc/chromium/src/system-alloc.cc

Issue 9311003: Update the tcmalloc chromium branch to r144 (gperftools 2.0), and merge chromium-specific changes. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebasec Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/tcmalloc/chromium/src/symbolize.cc ('k') | third_party/tcmalloc/chromium/src/tcmalloc.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
}
« no previous file with comments | « third_party/tcmalloc/chromium/src/symbolize.cc ('k') | third_party/tcmalloc/chromium/src/tcmalloc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698