提交 e98e2d36 编写于 作者: Y Yi Wang

Update

上级 ccd83ef6
...@@ -46,7 +46,8 @@ inline size_t align(size_t size, size_t alignment) { ...@@ -46,7 +46,8 @@ inline size_t align(size_t size, size_t alignment) {
void* BuddyAllocator::Alloc(size_t unaligned_size) { void* BuddyAllocator::Alloc(size_t unaligned_size) {
// adjust allocation alignment // adjust allocation alignment
size_t size = align(unaligned_size + sizeof(Metadata), min_chunk_size_); size_t size =
align(unaligned_size + sizeof(MemoryBlock::Desc), min_chunk_size_);
// acquire the allocator lock // acquire the allocator lock
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
...@@ -103,7 +104,7 @@ void BuddyAllocator::Free(void* p) { ...@@ -103,7 +104,7 @@ void BuddyAllocator::Free(void* p) {
return; return;
} }
block->mark_as_free(cache_); block->mark_as_free(&cache_);
total_used_ -= block->total_size(cache_); total_used_ -= block->total_size(cache_);
total_free_ += block->total_size(cache_); total_free_ += block->total_size(cache_);
...@@ -122,7 +123,7 @@ void BuddyAllocator::Free(void* p) { ...@@ -122,7 +123,7 @@ void BuddyAllocator::Free(void* p) {
right_buddy)); right_buddy));
// merge its right buddy to the block // merge its right buddy to the block
block->merge(cache_, right_buddy); block->merge(&cache_, right_buddy);
} }
} }
...@@ -139,7 +140,7 @@ void BuddyAllocator::Free(void* p) { ...@@ -139,7 +140,7 @@ void BuddyAllocator::Free(void* p) {
left_buddy->total_size(cache_), left_buddy)); left_buddy->total_size(cache_), left_buddy));
// merge the block to its left buddy // merge the block to its left buddy
left_buddy->merge(cache_, block); left_buddy->merge(&cache_, block);
block = left_buddy; block = left_buddy;
} }
} }
...@@ -163,13 +164,13 @@ size_t BuddyAllocator::Used() { return total_used_; } ...@@ -163,13 +164,13 @@ size_t BuddyAllocator::Used() { return total_used_; }
void* BuddyAllocator::SystemAlloc(size_t size) { void* BuddyAllocator::SystemAlloc(size_t size) {
size_t index = 0; size_t index = 0;
void* p = system_allocator_->Alloc(index, size); void* p = system_allocator_->Alloc(&index, size);
VLOG(10) << "Allocated " << p << " from system allocator."; VLOG(10) << "Allocated " << p << " from system allocator.";
if (p == nullptr) return nullptr; if (p == nullptr) return nullptr;
static_cast<MemoryBlock*>(p)->init(cache_, MemoryBlock::HUGE_CHUNK, index, static_cast<MemoryBlock*>(p)->init(&cache_, MemoryBlock::HUGE_CHUNK, index,
size, nullptr, nullptr); size, nullptr, nullptr);
return static_cast<MemoryBlock*>(p)->data(); return static_cast<MemoryBlock*>(p)->data();
...@@ -187,7 +188,7 @@ BuddyAllocator::PoolSet::iterator BuddyAllocator::RefillPool() { ...@@ -187,7 +188,7 @@ BuddyAllocator::PoolSet::iterator BuddyAllocator::RefillPool() {
// Allocate a new maximum sized block // Allocate a new maximum sized block
size_t index = 0; size_t index = 0;
void* p = system_allocator_->Alloc(index, max_chunk_size_); void* p = system_allocator_->Alloc(&index, max_chunk_size_);
if (p == nullptr) return pool_.end(); if (p == nullptr) return pool_.end();
...@@ -238,11 +239,11 @@ void* BuddyAllocator::SplitToAlloc(BuddyAllocator::PoolSet::iterator it, ...@@ -238,11 +239,11 @@ void* BuddyAllocator::SplitToAlloc(BuddyAllocator::PoolSet::iterator it,
VLOG(10) << "Split block (" << block << ", " << block->total_size(cache_) VLOG(10) << "Split block (" << block << ", " << block->total_size(cache_)
<< ") into"; << ") into";
block->split(cache_, size); block->split(&cache_, size);
VLOG(10) << "Left block (" << block << ", " << block->total_size(cache_) VLOG(10) << "Left block (" << block << ", " << block->total_size(cache_)
<< ")"; << ")";
block->set_type(cache_, MemoryBlock::ARENA_CHUNK); block->set_type(&cache_, MemoryBlock::ARENA_CHUNK);
// the rest of memory if exist // the rest of memory if exist
if (block->has_right_buddy(cache_)) { if (block->has_right_buddy(cache_)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册