Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove tiny range from StreamArena #12506

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions velox/common/memory/HashStringAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,6 @@ class HashStringAllocator : public StreamArena {
/// Allocates a new range of at least 'bytes' size.
void newContiguousRange(int32_t bytes, ByteRange* range);

void newTinyRange(int32_t bytes, ByteRange* lastRange, ByteRange* range)
override {
newRange(bytes, lastRange, range);
}

/// Returns the total memory footprint of 'this'.
int64_t retainedSize() const {
return state_.pool().allocatedBytes() + state_.sizeFromPool();
Expand Down
12 changes: 0 additions & 12 deletions velox/common/memory/StreamArena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,13 @@ void StreamArena::newRange(
}
}

void StreamArena::newTinyRange(
int32_t bytes,
ByteRange* /*lastRange*/,
ByteRange* range) {
VELOX_CHECK_GT(bytes, 0, "StreamArena::newTinyRange can't be zero length");
tinyRanges_.emplace_back();
tinyRanges_.back().resize(bytes);
range->position = 0;
range->buffer = reinterpret_cast<uint8_t*>(tinyRanges_.back().data());
range->size = bytes;
}
void StreamArena::clear() {
allocations_.clear();
pool_->freeNonContiguous(allocation_);
currentRun_ = 0;
currentOffset_ = 0;
largeAllocations_.clear();
size_ = 0;
tinyRanges_.clear();
}

} // namespace facebook::velox
13 changes: 4 additions & 9 deletions velox/common/memory/StreamArena.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,11 @@ class StreamArena {
/// its last 8 bytes. When extending, we need to update the entry so
/// that the next pointer is not seen when reading the content and
/// is also not counted in the payload size of the multipart entry.
///
/// NOTE: The method does not guarantee returned 'range' has size of 'bytes',
/// it is caller's responsibility to check.
virtual void newRange(int32_t bytes, ByteRange* lastRange, ByteRange* range);

/// sets 'range' to point to a small piece of memory owned by this. These
/// always come from the heap. The use case is for headers that may change
/// length based on data properties, not for bulk data. See 'newRange' for the
/// meaning of 'lastRange'.
virtual void
newTinyRange(int32_t bytes, ByteRange* lastRange, ByteRange* range);

/// Returns the Total size in bytes held by all Allocations.
virtual size_t size() const {
return size_;
Expand All @@ -68,6 +64,7 @@ class StreamArena {

private:
memory::MemoryPool* const pool_;

const memory::MachinePageCount allocationQuantum_{2};

// All non-contiguous allocations.
Expand All @@ -88,8 +85,6 @@ class StreamArena {

// Tracks all the contiguous and non-contiguous allocations in bytes.
size_t size_ = 0;

std::vector<std::string> tinyRanges_;
};

} // namespace facebook::velox
10 changes: 9 additions & 1 deletion velox/serializers/VectorStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ class VectorStream {
}

void initializeHeader(std::string_view name, StreamArena& streamArena) {
streamArena.newTinyRange(50, nullptr, &header_);
// Allocations from stream arena must be aligned size.
const auto headerSize = 64;
streamArena.newRange(headerSize, nullptr, &header_);
if (header_.size < headerSize) {
// StreamArena::newRange() does not guarantee the size. If returned range
// does not have enough space, allocate a new one.
streamArena.newRange(headerSize, nullptr, &header_);
VELOX_CHECK_EQ(header_.size, headerSize);
}
header_.size = name.size() + sizeof(int32_t);
folly::storeUnaligned<int32_t>(header_.buffer, name.size());
::memcpy(header_.buffer + sizeof(int32_t), &name[0], name.size());
Expand Down
Loading