mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-05 15:21:43 +00:00
Merge
This commit is contained in:
commit
7aa486e89d
@ -36,9 +36,8 @@ public:
|
||||
|
||||
if (size >= MMAP_THRESHOLD)
|
||||
{
|
||||
if (alignment > MMAP_MIN_ALIGNMENT)
|
||||
throw DB::Exception("Too large alignment: more than page size.", DB::ErrorCodes::BAD_ARGUMENTS);
|
||||
|
||||
if (alignment <= MMAP_MIN_ALIGNMENT)
|
||||
{
|
||||
buf = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (MAP_FAILED == buf)
|
||||
DB::throwFromErrno("Allocator: Cannot mmap.", DB::ErrorCodes::CANNOT_ALLOCATE_MEMORY);
|
||||
@ -48,6 +47,12 @@ public:
|
||||
DB::throwFromErrno("HashTableAllocator: Cannot madvise with MADV_HUGEPAGE.", DB::ErrorCodes::CANNOT_ALLOCATE_MEMORY);
|
||||
}
|
||||
else
|
||||
{
|
||||
/// если выравнивание больше, чем размер страницы используем posix_memalign
|
||||
buf = allocateUsingPosixMemalign(size, alignment);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alignment <= MALLOC_MIN_ALIGNMENT)
|
||||
{
|
||||
@ -58,11 +63,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
buf = nullptr;
|
||||
int res = posix_memalign(&buf, alignment, size);
|
||||
|
||||
if (0 != res)
|
||||
DB::throwFromErrno("Cannot allocate memory (posix_memalign)", DB::ErrorCodes::CANNOT_ALLOCATE_MEMORY, res);
|
||||
buf = allocateUsingPosixMemalign(size, alignment);
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,4 +122,17 @@ public:
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
private:
|
||||
void * allocateUsingPosixMemalign(size_t size, size_t alignment)
|
||||
{
|
||||
void * buf = nullptr;
|
||||
|
||||
int res = posix_memalign(&buf, alignment, size);
|
||||
|
||||
if (0 != res)
|
||||
DB::throwFromErrno("Cannot allocate memory (posix_memalign)", DB::ErrorCodes::CANNOT_ALLOCATE_MEMORY, res);
|
||||
|
||||
return buf;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user