| 104 | } |
| 105 | |
| 106 | void AllocationPool::newRunImpl(MachinePageCount numPages) { |
| 107 | if (usedBytes_ >= hugePageThreshold_ || |
| 108 | numPages > pool_->sizeClasses().back()) { |
| 109 | // At least 16 huge pages, no more than kMaxMmapBytes. The next is |
| 110 | // double the previous. Because the previous is a hair under the |
| 111 | // power of two because of fractional pages at ends of allocation, |
| 112 | // add an extra huge page size. |
| 113 | int64_t nextSize = std::min( |
| 114 | kMaxMmapBytes, |
| 115 | std::max<int64_t>( |
| 116 | 16 * AllocationTraits::kHugePageSize, |
| 117 | bits::nextPowerOfTwo( |
| 118 | usedBytes_ + AllocationTraits::kHugePageSize))); |
| 119 | // Round 'numPages' to no of pages in huge page. Allocating this plus an |
| 120 | // extra huge page guarantees that 'numPages' worth of contiguous aligned |
| 121 | // huge pages will be founfd in the allocation. |
| 122 | numPages = bits::roundUp(numPages, AllocationTraits::numPagesInHugePage()); |
| 123 | if (AllocationTraits::pageBytes(numPages) + |
| 124 | AllocationTraits::kHugePageSize > |
| 125 | nextSize) { |
| 126 | // Extra large single request. |
| 127 | nextSize = AllocationTraits::pageBytes(numPages) + |
| 128 | AllocationTraits::kHugePageSize; |
| 129 | } |
| 130 | |
| 131 | ContiguousAllocation largeAlloc; |
| 132 | const MachinePageCount pagesToAlloc = |
| 133 | AllocationTraits::numPagesInHugePage(); |
| 134 | pool_->allocateContiguous( |
| 135 | pagesToAlloc, largeAlloc, AllocationTraits::numPages(nextSize)); |
| 136 | |
| 137 | auto range = largeAlloc.hugePageRange().value(); |
| 138 | startOfRun_ = range.data(); |
| 139 | bytesInRun_ = range.size(); |
| 140 | largeAllocations_.emplace_back(std::move(largeAlloc)); |
| 141 | currentOffset_ = 0; |
| 142 | usedBytes_ += AllocationTraits::pageBytes(pagesToAlloc); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | Allocation allocation; |
| 147 | auto roundedPages = std::max<int32_t>(kMinPages, numPages); |
| 148 | pool_->allocateNonContiguous(roundedPages, allocation, roundedPages); |
| 149 | BOLT_CHECK_EQ(allocation.numRuns(), 1); |
| 150 | startOfRun_ = allocation.runAt(0).data<char>(); |
| 151 | bytesInRun_ = allocation.runAt(0).numBytes(); |
| 152 | currentOffset_ = 0; |
| 153 | allocations_.push_back(std::move(allocation)); |
| 154 | usedBytes_ += bytesInRun_; |
| 155 | } |
| 156 | |
| 157 | void AllocationPool::newRun(int64_t preferredSize) { |
| 158 | newRunImpl(AllocationTraits::numPages(preferredSize)); |
nothing calls this directly
no test coverage detected