MCPcopy Create free account
hub / github.com/bytedance/bolt / allocateFixed

Method allocateFixed

bolt/common/memory/AllocationPool.cpp:64–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64char* AllocationPool::allocateFixed(uint64_t bytes, int32_t alignment) {
65 BOLT_CHECK_GT(bytes, 0, "Cannot allocate zero bytes");
66 if (freeAddressableBytes() >= bytes && alignment == 1) {
67 auto* result = startOfRun_ + currentOffset_;
68 currentOffset_ += bytes;
69 if (currentOffset_ > endOfReservedRun()) {
70 growLastAllocation();
71 }
72 return result;
73 }
74 BOLT_CHECK_EQ(
75 __builtin_popcount(alignment), 1, "Alignment can only be power of 2");
76
77 auto numPages = AllocationTraits::numPages(bytes + alignment - 1);
78
79 if (freeAddressableBytes() == 0) {
80 newRunImpl(numPages);
81 } else {
82 auto alignedBytes = bytes + alignmentPadding(firstFreeInRun(), alignment);
83 if (freeAddressableBytes() < alignedBytes) {
84 newRunImpl(numPages);
85 }
86 }
87 currentOffset_ += alignmentPadding(firstFreeInRun(), alignment);
88 BOLT_CHECK_LE(bytes + currentOffset_, bytesInRun_);
89 auto* result = startOfRun_ + currentOffset_;
90 BOLT_CHECK_EQ(reinterpret_cast<uintptr_t>(result) % alignment, 0);
91 currentOffset_ += bytes;
92 if (currentOffset_ > endOfReservedRun()) {
93 growLastAllocation();
94 }
95 return result;
96}
97
98void AllocationPool::growLastAllocation() {
99 BOLT_CHECK_GT(bytesInRun_, AllocationTraits::kHugePageSize);

Callers 8

appendMethod · 0.45
allocateMethod · 0.45
allocateGroupsMethod · 0.45
newRowMethod · 0.45
newSlabMethod · 0.45
TEST_FFunction · 0.45
TEST_PFunction · 0.45

Calls 1

alignmentPaddingFunction · 0.85

Tested by 2

TEST_FFunction · 0.36
TEST_PFunction · 0.36