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

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

Issue 9320005: [NOT TO COMMIT!] Replace third_party/tcmalloc/chromium with tcmalloc r136 (the latest). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 11 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/system-alloc.h ('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..ea718b3990f60531b267410d1b075aad4f3a190c 100644
--- a/third_party/tcmalloc/chromium/src/system-alloc.cc
+++ b/third_party/tcmalloc/chromium/src/system-alloc.cc
@@ -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,7 +114,8 @@ union MemoryAligner {
static SpinLock spinlock(SpinLock::LINKER_INITIALIZED);
-#ifdef HAVE_GETPAGESIZE
+#if defined(HAVE_MMAP) || defined(MADV_FREE)
+// Page size is initialized on demand (only needed for mmap-based allocators)
static size_t pagesize = 0;
#endif
@@ -132,7 +144,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 +152,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 +160,6 @@ public:
DevMemSysAllocator() : SysAllocator() {
}
void* Alloc(size_t size, size_t *actual_size, size_t alignment);
- void FlagsInitialized() {}
};
class DefaultSysAllocator : public SysAllocator {
@@ -171,7 +180,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;
@@ -187,6 +195,7 @@ static const char mmap_name[] = "MmapSysAllocator";
void* SbrkSysAllocator::Alloc(size_t size, size_t *actual_size,
size_t alignment) {
#ifndef HAVE_SBRK
+ failed_ = true;
return NULL;
#else
// Check if we should use sbrk allocation.
@@ -201,7 +210,7 @@ void* SbrkSysAllocator::Alloc(size_t size, size_t *actual_size,
// sbrk will release memory if passed a negative number, so we do
// a strict check here
- if (static_cast<std::ptrdiff_t>(size + alignment) < 0) return NULL;
+ if (static_cast<ptrdiff_t>(size + alignment) < 0) return NULL;
// This doesn't overflow because TCMalloc_SystemAlloc has already
// tested for overflow at the alignment boundary.
@@ -258,6 +267,7 @@ void* SbrkSysAllocator::Alloc(size_t size, size_t *actual_size,
void* MmapSysAllocator::Alloc(size_t size, size_t *actual_size,
size_t alignment) {
#ifndef HAVE_MMAP
+ failed_ = true;
return NULL;
#else
// Check if we should use mmap allocation.
@@ -326,6 +336,7 @@ void* MmapSysAllocator::Alloc(size_t size, size_t *actual_size,
void* DevMemSysAllocator::Alloc(size_t size, size_t *actual_size,
size_t alignment) {
#ifndef HAVE_MMAP
+ failed_ = true;
return NULL;
#else
static bool initialized = false;
@@ -420,7 +431,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;
}
}
@@ -483,26 +493,11 @@ void* TCMalloc_SystemAlloc(size_t size, size_t *actual_size,
return result;
}
-size_t TCMalloc_SystemAddGuard(void* start, size_t size) {
-#ifdef HAVE_GETPAGESIZE
- if (pagesize == 0)
- pagesize = getpagesize();
-
- if (size < pagesize || (reinterpret_cast<size_t>(start) % pagesize) != 0)
- return 0;
-
- if (!mprotect(start, pagesize, PROT_NONE))
- return pagesize;
-#endif
-
- return 0;
-}
-
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,16 +521,10 @@ 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
}
}
#endif
}
-
-void TCMalloc_SystemCommit(void* start, size_t length) {
- // Nothing to do here. TCMalloc_SystemRelease does not alter pages
- // such that they need to be re-committed before they can be used by the
- // application.
-}
« no previous file with comments | « third_party/tcmalloc/chromium/src/system-alloc.h ('k') | third_party/tcmalloc/chromium/src/tcmalloc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698