Skip to content

Commit 97fef01

Browse files
Revert "use spin lock in auto growth allocator (#34910)" (#35069)
This reverts commit 6bacfb0.
1 parent 4ce272e commit 97fef01

File tree

4 files changed

+3
-280
lines changed

4 files changed

+3
-280
lines changed

paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ AutoGrowthBestFitAllocator::AutoGrowthBestFitAllocator(
4545
Allocation *AutoGrowthBestFitAllocator::AllocateImpl(size_t size) {
4646
size = AlignedSize(size, alignment_);
4747

48-
std::lock_guard<SpinLock> guard(spinlock_);
48+
std::lock_guard<std::mutex> guard(mtx_);
4949
auto iter = free_blocks_.lower_bound(std::make_pair(size, nullptr));
5050
BlockIt block_it;
5151
if (iter != free_blocks_.end()) {
@@ -94,12 +94,11 @@ Allocation *AutoGrowthBestFitAllocator::AllocateImpl(size_t size) {
9494
VLOG(2) << "Not found and reallocate " << realloc_size << ", and remaining "
9595
<< remaining_size;
9696
}
97-
9897
return new BlockAllocation(block_it);
9998
}
10099

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

paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <utility>
2222

2323
#include "paddle/fluid/memory/allocation/allocator.h"
24-
#include "paddle/fluid/memory/allocation/spin_lock.h"
2524

2625
namespace paddle {
2726
namespace memory {
@@ -87,7 +86,7 @@ class AutoGrowthBestFitAllocator : public Allocator {
8786
size_t alignment_;
8887
size_t chunk_size_;
8988

90-
SpinLock spinlock_;
89+
mutable std::mutex mtx_;
9190
};
9291

9392
} // namespace allocation

paddle/fluid/memory/allocation/spin_lock.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

paddle/fluid/memory/allocation/spin_lock_c.h

Lines changed: 0 additions & 239 deletions
This file was deleted.

0 commit comments

Comments
 (0)