@@ -76,10 +76,13 @@ char* AllocationPool::allocateFixed(uint64_t bytes, int32_t alignment) {
7676 return result;
7777}
7878
79- char * AllocationPool::allocateFixedWithPageSize (
79+ char * AllocationPool::allocateFixedTest (
8080 int64_t bytes,
8181 int32_t alignment,
82- uint64_t pageSize) {
82+ uint64_t pageSize,
83+ int32_t minPages,
84+ int64_t hugePageThreshold,
85+ int32_t hugePageNums) {
8386 VELOX_CHECK_GT (bytes, 0 , " Cannot allocate zero bytes" );
8487 if (freeAddressableBytes () >= bytes && alignment == 1 ) {
8588 auto * result = startOfRun_ + currentOffset_;
@@ -99,11 +102,13 @@ char* AllocationPool::allocateFixedWithPageSize(
99102 auto numPages = bits::roundUp (bytes + alignment - 1 , pageSize) / pageSize;
100103
101104 if (freeAddressableBytes () == 0 ) {
102- newRunImplWithPageSize (numPages, pageSize);
105+ newRunImplWithPageSize (
106+ numPages, pageSize, minPages, hugePageThreshold, hugePageNums);
103107 } else {
104108 auto alignedBytes = bytes + alignmentPadding (firstFreeInRun (), alignment);
105109 if (freeAddressableBytes () < alignedBytes) {
106- newRunImplWithPageSize (numPages, pageSize);
110+ newRunImplWithPageSize (
111+ numPages, pageSize, minPages, hugePageThreshold, hugePageNums);
107112 }
108113 }
109114 currentOffset_ += alignmentPadding (firstFreeInRun (), alignment);
@@ -180,8 +185,11 @@ void AllocationPool::newRunImpl(MachinePageCount numPages) {
180185
181186void AllocationPool::newRunImplWithPageSize (
182187 memory::MachinePageCount numPages,
183- uint64_t pageSize) {
184- if (usedBytes_ >= hugePageThreshold_ ||
188+ const uint64_t pageSize,
189+ int32_t minPages,
190+ int64_t hugePageThreshold,
191+ int32_t hugePageNum) {
192+ if (usedBytes_ >= hugePageThreshold ||
185193 numPages > pool_->sizeClasses ().back ()) {
186194 // At least 16 huge pages, no more than kMaxMmapBytes. The next is
187195 // double the previous. Because the previous is a hair under the
@@ -190,7 +198,7 @@ void AllocationPool::newRunImplWithPageSize(
190198 int64_t nextSize = std::min (
191199 kMaxMmapBytes ,
192200 std::max<int64_t >(
193- 16 * AllocationTraits::kHugePageSize ,
201+ hugePageNum * AllocationTraits::kHugePageSize ,
194202 bits::nextPowerOfTwo (
195203 usedBytes_ + AllocationTraits::kHugePageSize )));
196204 // Round 'numPages' to no of pages in huge page. Allocating this plus an
@@ -220,9 +228,7 @@ void AllocationPool::newRunImplWithPageSize(
220228 }
221229
222230 Allocation allocation;
223- const auto roundedBytes = std::max<uint64_t >(
224- kMinPages * AllocationTraits::kPageSize , numPages * pageSize);
225- const auto roundedPages = bits::roundUp (roundedBytes, pageSize) / pageSize;
231+ const auto roundedPages = std::max<int32_t >(minPages, numPages);
226232 const auto standardPages =
227233 (roundedPages * pageSize) / AllocationTraits::kPageSize ;
228234 pool_->allocateNonContiguous (standardPages, allocation, standardPages);
0 commit comments