[enhancement] Refactor to improve the usability of MemTracker (step2) (#10823)

This commit is contained in:
Xinyi Zou
2022-07-21 17:11:28 +08:00
committed by GitHub
parent 5f6f35e886
commit 4960043f5e
316 changed files with 2145 additions and 4369 deletions

View File

@ -45,7 +45,7 @@ void SystemAllocator::free(uint8_t* ptr, size_t length) {
LOG(ERROR) << "fail to free memory via munmap, errno=" << errno
<< ", errmsg=" << strerror_r(errno, buf, 64);
} else {
RELEASE_THREAD_LOCAL_MEM_TRACKER(length);
RELEASE_THREAD_MEM_TRACKER(length);
}
} else {
::free(ptr);
@ -66,14 +66,14 @@ uint8_t* SystemAllocator::allocate_via_malloc(size_t length) {
}
uint8_t* SystemAllocator::allocate_via_mmap(size_t length) {
CONSUME_THREAD_LOCAL_MEM_TRACKER(length);
CONSUME_THREAD_MEM_TRACKER(length);
auto ptr = (uint8_t*)mmap(nullptr, length, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE,
-1, 0);
if (ptr == MAP_FAILED) {
char buf[64];
LOG(ERROR) << "fail to allocate memory via mmap, errno=" << errno
<< ", errmsg=" << strerror_r(errno, buf, 64);
RELEASE_THREAD_LOCAL_MEM_TRACKER(length);
RELEASE_THREAD_MEM_TRACKER(length);
return nullptr;
}
return ptr;