[enhancement] Refactor to improve the usability of MemTracker (step2) (#10823)
This commit is contained in:
@ -77,11 +77,11 @@ Status SystemAllocator::AllocateViaMMap(int64_t len, uint8_t** buffer_mem) {
|
||||
// Map an extra huge page so we can fix up the alignment if needed.
|
||||
map_len += HUGE_PAGE_SIZE;
|
||||
}
|
||||
CONSUME_THREAD_LOCAL_MEM_TRACKER(map_len);
|
||||
CONSUME_THREAD_MEM_TRACKER(map_len);
|
||||
uint8_t* mem = reinterpret_cast<uint8_t*>(
|
||||
mmap(nullptr, map_len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0));
|
||||
if (mem == MAP_FAILED) {
|
||||
RELEASE_THREAD_LOCAL_MEM_TRACKER(map_len);
|
||||
RELEASE_THREAD_MEM_TRACKER(map_len);
|
||||
return Status::BufferAllocFailed("mmap failed");
|
||||
}
|
||||
|
||||
@ -93,12 +93,12 @@ Status SystemAllocator::AllocateViaMMap(int64_t len, uint8_t** buffer_mem) {
|
||||
if (misalignment != 0) {
|
||||
uintptr_t fixup = HUGE_PAGE_SIZE - misalignment;
|
||||
munmap(mem, fixup);
|
||||
RELEASE_THREAD_LOCAL_MEM_TRACKER(fixup);
|
||||
RELEASE_THREAD_MEM_TRACKER(fixup);
|
||||
mem += fixup;
|
||||
map_len -= fixup;
|
||||
}
|
||||
munmap(mem + len, map_len - len);
|
||||
RELEASE_THREAD_LOCAL_MEM_TRACKER(map_len - len);
|
||||
RELEASE_THREAD_MEM_TRACKER(map_len - len);
|
||||
DCHECK_EQ(reinterpret_cast<uintptr_t>(mem) % HUGE_PAGE_SIZE, 0) << mem;
|
||||
// Mark the buffer as a candidate for promotion to huge pages. The Linux Transparent
|
||||
// Huge Pages implementation will try to back the memory with a huge page if it is
|
||||
@ -147,7 +147,7 @@ Status SystemAllocator::AllocateViaMalloc(int64_t len, uint8_t** buffer_mem) {
|
||||
void SystemAllocator::Free(BufferPool::BufferHandle&& buffer) {
|
||||
if (config::mmap_buffers) {
|
||||
int rc = munmap(buffer.data(), buffer.len());
|
||||
RELEASE_THREAD_LOCAL_MEM_TRACKER(buffer.len());
|
||||
RELEASE_THREAD_MEM_TRACKER(buffer.len());
|
||||
DCHECK_EQ(rc, 0) << "Unexpected munmap() error: " << errno;
|
||||
} else {
|
||||
bool use_huge_pages = buffer.len() % HUGE_PAGE_SIZE == 0 && config::madvise_huge_pages;
|
||||
|
||||
Reference in New Issue
Block a user