mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 00:52:02 +00:00
LfAlloc more reliable choice of hint
This commit is contained in:
parent
9edbbc637a
commit
3c1e5348d1
@ -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);
|
||||
char* largeBlock;
|
||||
static constexpr size_t maxAttempts = 10;
|
||||
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