Skip to content

Commit

Permalink
Fix HashStringAllocator::clear (facebookincubator#10053)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebookincubator#10053

Decrement memory counters as in HashStringAllocator::freeToPool

Reviewed By: xiaoxmeng, mbasmanova

Differential Revision: D58171132

fbshipit-source-id: f87d411022b9b5cd9d996b4d999a7ab6c485171b
  • Loading branch information
arhimondr authored and facebook-github-bot committed Jun 6, 2024
1 parent efe648f commit 7fe89b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion velox/common/memory/HashStringAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ void HashStringAllocator::clear() {
freeBytes_ = 0;
std::fill(std::begin(freeNonEmpty_), std::end(freeNonEmpty_), 0);
for (auto& pair : allocationsFromPool_) {
pool()->free(pair.first, pair.second);
const auto size = pair.second;
pool()->free(pair.first, size);
sizeFromPool_ -= size;
cumulativeBytes_ -= size;
}
allocationsFromPool_.clear();
for (auto i = 0; i < kNumFreeLists; ++i) {
Expand Down
8 changes: 8 additions & 0 deletions velox/common/memory/tests/HashStringAllocatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,5 +670,13 @@ TEST_F(HashStringAllocatorTest, storeStringFast) {
allocator_->checkConsistency();
}

TEST_F(HashStringAllocatorTest, clear) {
allocator_->allocate(HashStringAllocator::kMinAlloc);
allocator_->allocate(HashStringAllocator::kMaxAlloc + 1);
EXPECT_GT(allocator_->retainedSize(), 0);
allocator_->clear();
EXPECT_EQ(allocator_->retainedSize(), 0);
}

} // namespace
} // namespace facebook::velox

0 comments on commit 7fe89b4

Please sign in to comment.