Skip to content

Commit

Permalink
Revert "use spin lock in auto growth allocator (#34910)" (#35069)
Browse files Browse the repository at this point in the history
This reverts commit 6bacfb0.
  • Loading branch information
wanghuancoder authored Aug 23, 2021
1 parent 4ce272e commit 97fef01
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ AutoGrowthBestFitAllocator::AutoGrowthBestFitAllocator(
Allocation *AutoGrowthBestFitAllocator::AllocateImpl(size_t size) {
size = AlignedSize(size, alignment_);

std::lock_guard<SpinLock> guard(spinlock_);
std::lock_guard<std::mutex> guard(mtx_);
auto iter = free_blocks_.lower_bound(std::make_pair(size, nullptr));
BlockIt block_it;
if (iter != free_blocks_.end()) {
Expand Down Expand Up @@ -94,12 +94,11 @@ Allocation *AutoGrowthBestFitAllocator::AllocateImpl(size_t size) {
VLOG(2) << "Not found and reallocate " << realloc_size << ", and remaining "
<< remaining_size;
}

return new BlockAllocation(block_it);
}

void AutoGrowthBestFitAllocator::FreeImpl(Allocation *allocation) {
std::lock_guard<SpinLock> guard(spinlock_);
std::lock_guard<std::mutex> guard(mtx_);
auto block_it = static_cast<BlockAllocation *>(allocation)->block_it_;
auto &blocks = block_it->chunk_->blocks_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <utility>

#include "paddle/fluid/memory/allocation/allocator.h"
#include "paddle/fluid/memory/allocation/spin_lock.h"

namespace paddle {
namespace memory {
Expand Down Expand Up @@ -87,7 +86,7 @@ class AutoGrowthBestFitAllocator : public Allocator {
size_t alignment_;
size_t chunk_size_;

SpinLock spinlock_;
mutable std::mutex mtx_;
};

} // namespace allocation
Expand Down
36 changes: 0 additions & 36 deletions paddle/fluid/memory/allocation/spin_lock.h

This file was deleted.

239 changes: 0 additions & 239 deletions paddle/fluid/memory/allocation/spin_lock_c.h

This file was deleted.

0 comments on commit 97fef01

Please sign in to comment.