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

Unified Diff: third_party/tcmalloc/chromium/src/memfs_malloc.cc

Issue 7430007: Merge tcmalloc r111 (perftools v. 1.8) with the chromium/ branch. Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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
Index: third_party/tcmalloc/chromium/src/memfs_malloc.cc
===================================================================
--- third_party/tcmalloc/chromium/src/memfs_malloc.cc (revision 94429)
+++ third_party/tcmalloc/chromium/src/memfs_malloc.cc (working copy)
@@ -58,7 +58,6 @@
#include "base/basictypes.h"
#include "base/googleinit.h"
#include "base/sysinfo.h"
-#include "system-alloc.h"
#include "internal_logging.h"
using std::string;
@@ -86,7 +85,7 @@
class HugetlbSysAllocator: public SysAllocator {
public:
explicit HugetlbSysAllocator(SysAllocator* fallback)
- : failed_(true), // Unusable until FlagsInitialized() is called
+ : failed_(true), // To disable allocator until Initialize() is called.
big_page_size_(0),
hugetlb_fd_(-1),
hugetlb_base_(0),
@@ -94,10 +93,10 @@
}
void* Alloc(size_t size, size_t *actual_size, size_t alignment);
+ bool Initialize();
- void FlagsInitialized();
+ bool failed_; // Whether failed to allocate memory.
- bool failed_; // Whether failed to allocate memory.
private:
void* AllocInternal(size_t size, size_t *actual_size, size_t alignment);
@@ -212,49 +211,53 @@
return reinterpret_cast<void*>(ptr);
}
-void HugetlbSysAllocator::FlagsInitialized() {
- if (FLAGS_memfs_malloc_path.length()) {
- char path[PATH_MAX];
- 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");
- }
+bool HugetlbSysAllocator::Initialize() {
+ char path[PATH_MAX];
+ 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;
+ }
- int hugetlb_fd = mkstemp(path);
- if (hugetlb_fd == -1) {
- TCMalloc_MESSAGE(__FILE__, __LINE__,
- "warning: unable to create memfs_malloc_path %s: %s\n",
- path, strerror(errno));
- return;
- }
+ int hugetlb_fd = mkstemp(path);
+ if (hugetlb_fd == -1) {
+ 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) {
- CRASH("fatal: error unlinking memfs_malloc_path %s: %s\n",
- path, strerror(errno));
- }
+ // Cleanup memory on process exit
+ if (unlink(path) == -1) {
+ 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) {
- CRASH("fatal: error fstatfs of memfs_malloc_path: %s\n",
- strerror(errno));
- }
- int64 page_size = sfs.f_bsize;
-
- hugetlb_fd_ = hugetlb_fd;
- big_page_size_ = page_size;
- failed_ = false;
+ // Use fstatfs to figure out the default page size for memfs
+ struct statfs sfs;
+ if (fstatfs(hugetlb_fd, &sfs) == -1) {
+ CRASH("fatal: error fstatfs of memfs_malloc_path: %s\n",
+ strerror(errno));
+ return false;
}
-}
+ int64 page_size = sfs.f_bsize;
-static void InitSystemAllocator() {
- SysAllocator *alloc = MallocExtension::instance()->GetSystemAllocator();
- HugetlbSysAllocator *hugetlb = new (hugetlb_space) HugetlbSysAllocator(alloc);
- MallocExtension::instance()->SetSystemAllocator(hugetlb);
+ hugetlb_fd_ = hugetlb_fd;
+ big_page_size_ = page_size;
+ failed_ = false;
+ return true;
}
-REGISTER_MODULE_INITIALIZER(memfs_malloc, { InitSystemAllocator(); });
+REGISTER_MODULE_INITIALIZER(memfs_malloc, {
+ if (FLAGS_memfs_malloc_path.length()) {
+ SysAllocator* alloc = MallocExtension::instance()->GetSystemAllocator();
+ HugetlbSysAllocator* hp = new (hugetlb_space) HugetlbSysAllocator(alloc);
+ if (hp->Initialize()) {
+ MallocExtension::instance()->SetSystemAllocator(hp);
+ }
+ }
+});
#endif /* ifdef __linux */

Powered by Google App Engine
This is Rietveld 408576698