Index: third_party/tcmalloc/vendor/src/memfs_malloc.cc |
=================================================================== |
--- third_party/tcmalloc/vendor/src/memfs_malloc.cc (revision 126727) |
+++ third_party/tcmalloc/vendor/src/memfs_malloc.cc (working copy) |
@@ -54,16 +54,12 @@ |
#include <new> // for operator new |
#include <string> |
-#include <gperftools/malloc_extension.h> |
+#include <google/malloc_extension.h> |
#include "base/basictypes.h" |
#include "base/googleinit.h" |
#include "base/sysinfo.h" |
#include "internal_logging.h" |
-// TODO(sanjay): Move the code below into the tcmalloc namespace |
-using tcmalloc::kLog; |
-using tcmalloc::kCrash; |
-using tcmalloc::Log; |
using std::string; |
DEFINE_string(memfs_malloc_path, EnvToString("TCMALLOC_MEMFS_MALLOC_PATH", ""), |
@@ -139,11 +135,11 @@ |
if (result != NULL) { |
return result; |
} |
- Log(kLog, __FILE__, __LINE__, |
- "HugetlbSysAllocator: (failed, allocated)", failed_, hugetlb_base_); |
+ TCMalloc_MESSAGE(__FILE__, __LINE__, |
+ "HugetlbSysAllocator: failed_=%d allocated=%"PRId64"\n", |
+ failed_, static_cast<int64_t>(hugetlb_base_)); |
if (FLAGS_memfs_malloc_abort_on_fail) { |
- Log(kCrash, __FILE__, __LINE__, |
- "memfs_malloc_abort_on_fail is set"); |
+ CRASH("memfs_malloc_abort_on_fail is set\n"); |
} |
return fallback_->Alloc(size, actual_size, alignment); |
} |
@@ -161,12 +157,13 @@ |
if (limit > 0 && hugetlb_base_ + size + extra > limit) { |
// Disable the allocator when there's less than one page left. |
if (limit - hugetlb_base_ < big_page_size_) { |
- Log(kLog, __FILE__, __LINE__, "reached memfs_malloc_limit_mb"); |
+ TCMalloc_MESSAGE(__FILE__, __LINE__, "reached memfs_malloc_limit_mb\n"); |
failed_ = true; |
} |
else { |
- Log(kLog, __FILE__, __LINE__, |
- "alloc too large (size, bytes left)", size, limit-hugetlb_base_); |
+ TCMalloc_MESSAGE(__FILE__, __LINE__, "alloc size=%"PRIuS |
+ " too large while %"PRId64" bytes remain\n", |
+ size, static_cast<int64_t>(limit - hugetlb_base_)); |
} |
return NULL; |
} |
@@ -175,8 +172,8 @@ |
// hugetlbfs returns EINVAL for ftruncate. |
int ret = ftruncate(hugetlb_fd_, hugetlb_base_ + size + extra); |
if (ret != 0 && errno != EINVAL) { |
- Log(kLog, __FILE__, __LINE__, |
- "ftruncate failed", strerror(errno)); |
+ TCMalloc_MESSAGE(__FILE__, __LINE__, "ftruncate failed: %s\n", |
+ strerror(errno)); |
failed_ = true; |
return NULL; |
} |
@@ -191,8 +188,8 @@ |
hugetlb_fd_, hugetlb_base_); |
if (result == reinterpret_cast<void*>(MAP_FAILED)) { |
if (!FLAGS_memfs_malloc_ignore_mmap_fail) { |
- Log(kLog, __FILE__, __LINE__, |
- "mmap failed (size, error)", size + extra, strerror(errno)); |
+ TCMalloc_MESSAGE(__FILE__, __LINE__, "mmap of size %"PRIuS" failed: %s\n", |
+ size + extra, strerror(errno)); |
failed_ = true; |
} |
return NULL; |
@@ -216,34 +213,33 @@ |
bool HugetlbSysAllocator::Initialize() { |
char path[PATH_MAX]; |
- const int pathlen = FLAGS_memfs_malloc_path.size(); |
- if (pathlen + 8 > sizeof(path)) { |
- Log(kCrash, __FILE__, __LINE__, "XX fatal: memfs_malloc_path too long"); |
+ int rc = snprintf(path, sizeof(path), "%s.XXXXXX", |
+ FLAGS_memfs_malloc_path.c_str()); |
+ if (rc < 0 || rc >= sizeof(path)) { |
+ CRASH("XX fatal: memfs_malloc_path too long\n"); |
return false; |
} |
- memcpy(path, FLAGS_memfs_malloc_path.data(), pathlen); |
- memcpy(path + pathlen, ".XXXXXX", 8); // Also copies terminating \0 |
int hugetlb_fd = mkstemp(path); |
if (hugetlb_fd == -1) { |
- Log(kLog, __FILE__, __LINE__, |
- "warning: unable to create memfs_malloc_path", |
- path, strerror(errno)); |
+ TCMalloc_MESSAGE(__FILE__, __LINE__, |
+ "warning: unable to create memfs_malloc_path %s: %s\n", |
+ path, strerror(errno)); |
return false; |
} |
// Cleanup memory on process exit |
if (unlink(path) == -1) { |
- Log(kCrash, __FILE__, __LINE__, |
- "fatal: error unlinking memfs_malloc_path", path, strerror(errno)); |
+ CRASH("fatal: error unlinking memfs_malloc_path %s: %s\n", |
+ path, strerror(errno)); |
return false; |
} |
// Use fstatfs to figure out the default page size for memfs |
struct statfs sfs; |
if (fstatfs(hugetlb_fd, &sfs) == -1) { |
- Log(kCrash, __FILE__, __LINE__, |
- "fatal: error fstatfs of memfs_malloc_path", strerror(errno)); |
+ CRASH("fatal: error fstatfs of memfs_malloc_path: %s\n", |
+ strerror(errno)); |
return false; |
} |
int64 page_size = sfs.f_bsize; |