Skip to content

Commit 5506c84

Browse files
committed
Add more properties
1 parent 510bd74 commit 5506c84

File tree

7 files changed

+74
-19
lines changed

7 files changed

+74
-19
lines changed

velox/common/memory/AllocationPool.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

181186
void 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);

velox/common/memory/AllocationPool.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ class AllocationPool {
4040
// only be power of 2.
4141
char* allocateFixed(uint64_t bytes, int32_t alignment = 1);
4242

43-
char* allocateFixedWithPageSize(
43+
char* allocateFixedTest(
4444
int64_t bytes,
4545
int32_t alignment,
46-
uint64_t pageSize);
46+
uint64_t pageSize,
47+
int32_t minPages,
48+
int64_t hugePageThreshold,
49+
int32_t hugePageNums);
4750

4851
// Starts a new run for variable length allocation. The actual size
4952
// is at least one machine page. Throws std::bad_alloc if no space.
@@ -144,7 +147,10 @@ class AllocationPool {
144147

145148
void newRunImplWithPageSize(
146149
memory::MachinePageCount numPages,
147-
uint64_t pageSize);
150+
uint64_t pageSize,
151+
int32_t minPages,
152+
int64_t hugePageThreshold,
153+
int32_t hugePageNum);
148154

149155
memory::MemoryPool* pool_;
150156
std::vector<memory::Allocation> allocations_;

velox/core/QueryConfig.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,14 @@ class QueryConfig {
747747
/// This is an experimental property for performance tuning.
748748
static constexpr const char* kHashTablePageSize = "hashtable_page_size";
749749

750+
static constexpr const char* kHashTableMinPages = "hashtable_min_pages";
751+
752+
static constexpr const char* kHashTableHugePageThreshold =
753+
"hashtable_huge_page_threshold";
754+
755+
static constexpr const char* kHashTableHugePageNums =
756+
"hashtable_huge_page_nums";
757+
750758
enum class RowSizeTrackingMode {
751759
DISABLED = 0,
752760
EXCLUDE_DELTA_SPLITS = 1,
@@ -1339,6 +1347,20 @@ class QueryConfig {
13391347
config::CapacityUnit::BYTE);
13401348
}
13411349

1350+
int32_t hashTableMinPages() const {
1351+
return get<int32_t>(kHashTableMinPages, 16);
1352+
}
1353+
1354+
int32_t hashTableHugePageNums() const {
1355+
return get<int32_t>(kHashTableHugePageNums, 16);
1356+
}
1357+
1358+
int64_t hashTableHugePageThreshold() const {
1359+
return config::toCapacity(
1360+
get<std::string>(kHashTableHugePageThreshold, "256KB"),
1361+
config::CapacityUnit::BYTE);
1362+
}
1363+
13421364
std::string source() const {
13431365
return get<std::string>(kSource, "");
13441366
}

velox/exec/HashBuild.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,13 @@ void HashBuild::addInput(RowVectorPtr input) {
402402
input->childAt(spillProbedFlagChannel_)->asFlatVector<bool>();
403403
}
404404

405+
const auto& queryConfig = operatorCtx()->driverCtx()->queryConfig();
405406
activeRows_.applyToSelected([&](auto rowIndex) {
406407
char* newRow = rows->newRowTest(
407-
operatorCtx()->driverCtx()->queryConfig().hashTablePageSize());
408+
queryConfig.hashTablePageSize(),
409+
queryConfig.hashTableMinPages(),
410+
queryConfig.hashTableHugePageThreshold(),
411+
queryConfig.hashTableHugePageNums());
408412
if (nextOffset) {
409413
*reinterpret_cast<char**>(newRow + nextOffset) = nullptr;
410414
}

velox/exec/HashTable.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,12 @@ char* HashTable<ignoreNullKeys>::insertEntry(
332332
HashLookup& lookup,
333333
uint64_t index,
334334
vector_size_t row) {
335+
const auto& queryConfig = driverThreadContext()->driverCtx()->queryConfig();
335336
char* group = rows_->newRowTest(
336-
driverThreadContext()->driverCtx()->queryConfig().hashTablePageSize());
337+
queryConfig.hashTablePageSize(),
338+
queryConfig.hashTableMinPages(),
339+
queryConfig.hashTableHugePageThreshold(),
340+
queryConfig.hashTableHugePageNums());
337341
lookup.hits[row] = group; // NOLINT
338342
storeKeys(lookup, row);
339343
storeRowPointer(index, lookup.hashes[row], group);

velox/exec/RowContainer.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ char* RowContainer::newRow() {
283283
return initializeRow(row, false /* reuse */);
284284
}
285285

286-
char* RowContainer::newRowTest(uint64_t pageSize) {
286+
char* RowContainer::newRowTest(
287+
uint64_t pageSize,
288+
int32_t minPages,
289+
int64_t hugePageThreshold,
290+
int32_t hugePageNums) {
287291
VELOX_DCHECK(mutable_, "Can't add row into an immutable row container");
288292
++numRows_;
289293
char* row;
@@ -293,8 +297,13 @@ char* RowContainer::newRowTest(uint64_t pageSize) {
293297
firstFreeRow_ = nextFree(row);
294298
--numFreeRows_;
295299
} else {
296-
row = rows_.allocateFixedWithPageSize(
297-
fixedRowSize_ + normalizedKeySize_, alignment_, pageSize) +
300+
row = rows_.allocateFixedTest(
301+
fixedRowSize_ + normalizedKeySize_,
302+
alignment_,
303+
pageSize,
304+
minPages,
305+
hugePageThreshold,
306+
hugePageNums) +
298307
normalizedKeySize_;
299308
if (normalizedKeySize_) {
300309
++numRowsWithNormalizedKey_;

velox/exec/RowContainer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,11 @@ class RowContainer {
318318
/// Allocates a new row and initializes possible aggregates to null.
319319
char* newRow();
320320

321-
char* newRowTest(uint64_t pageSize);
321+
char* newRowTest(
322+
uint64_t pageSize,
323+
int32_t minPages = 16,
324+
int64_t hugePageThreshold = 256 * 1024,
325+
int32_t hugePageNums = 16);
322326

323327
uint32_t rowSize(const char* row) const {
324328
return fixedRowSize_ +

0 commit comments

Comments
 (0)