mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-12 10:34:21 +00:00
Merge pull request #5133 from danlark1/reliable_lfalloc
LfAlloc more reliable choice of hint
This commit is contained in:
commit
a76e504f45
@ -358,8 +358,15 @@ static char* AllocWithMMap(uintptr_t sz, EMMapMode mode) {
|
||||
}
|
||||
#if defined(USE_LFALLOC_RANDOM_HINT)
|
||||
static thread_local std::mt19937_64 generator(std::random_device{}());
|
||||
std::uniform_int_distribution<intptr_t> distr(areaStart, areaFinish / 2);
|
||||
char* largeBlock = (char*)mmap(reinterpret_cast<void*>(distr(generator)), sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
std::uniform_int_distribution<intptr_t> distr(areaStart, areaFinish - sz - 1);
|
||||
char* largeBlock;
|
||||
static constexpr size_t MaxAttempts = 100;
|
||||
size_t attempt = 0;
|
||||
do
|
||||
{
|
||||
largeBlock = (char*)mmap(reinterpret_cast<void*>(distr(generator)), sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
++attempt;
|
||||
} while (uintptr_t(((char*)largeBlock - ALLOC_START) + sz) >= areaFinish && attempt < MaxAttempts && munmap(largeBlock, sz) == 0);
|
||||
#else
|
||||
char* largeBlock = (char*)mmap(0, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user