Unified usages of getPageSize

1. Introduced getPageSize function.
2. Replaced usages of getpagesize with getPageSize function.
3. Replaced usages of sysconf(_SG_PAGESIZE) with getPageSize function.
This commit is contained in:
Maksim Kita 2020-10-29 22:52:12 +03:00
parent 058fbd5222
commit dbb2fbcdd5
8 changed files with 21 additions and 4 deletions

View File

@ -86,6 +86,7 @@ private:
static size_t roundUpToPageSize(size_t s)
{
/// TODO: Consider to fix, better to store ::getPageSize in Arena instance
return (s + 4096 - 1) / 4096 * 4096;
}

View File

@ -3,6 +3,7 @@
#include <Common/Exception.h>
#include <Common/StringUtils/StringUtils.h>
#include <Common/UTF8Helpers.h>
#include <Common/getPageSize.h>
#include <Core/Defines.h>
#include <ext/range.h>
#include <Poco/Unicode.h>
@ -37,7 +38,7 @@ struct StringSearcherBase
{
#ifdef __SSE2__
static constexpr auto n = sizeof(__m128i);
const int page_size = getpagesize();
const int page_size = ::getPageSize();
bool pageSafe(const void * const ptr) const
{

View File

@ -0,0 +1,7 @@
#include "getPageSize.h"
#include <unistd.h>
long getPageSize() {
return sysconf(_SC_PAGESIZE);
}

4
src/Common/getPageSize.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
/// Get memory page size
long getPageSize();

View File

@ -99,6 +99,7 @@ SRCS(
getMappedArea.cpp
getMultipleKeysFromConfig.cpp
getNumberOfPhysicalCPUCores.cpp
getPageSize.cpp
hasLinuxCapability.cpp
hex.cpp
isLocalAddress.cpp

View File

@ -6,6 +6,7 @@
#include <Common/ProfileEvents.h>
#include <Common/formatReadable.h>
#include <Common/Exception.h>
#include <Common/getPageSize.h>
#include <IO/WriteHelpers.h>
#include <IO/MMapReadBufferFromFileDescriptor.h>
@ -39,7 +40,7 @@ void MMapReadBufferFromFileDescriptor::init(int fd_, size_t offset, size_t lengt
BufferBase::set(static_cast<char *>(buf), length, 0);
int page_size = ::getpagesize();
int page_size = ::getPageSize();
ReadBuffer::padded = (length % page_size) > 0 && (length % page_size) <= (page_size - 15);
}
}

View File

@ -6,6 +6,7 @@
#include <Common/Stopwatch.h>
#include <Common/ThreadPool.h>
#include <Common/randomSeed.h>
#include <Common/getPageSize.h>
#include <cstdlib>
#include <iomanip>
@ -46,7 +47,7 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
{
using namespace DB;
Memory<> direct_buf(block_size, sysconf(_SC_PAGESIZE));
Memory<> direct_buf(block_size, ::getPageSize());
std::vector<char> simple_buf(block_size);
char * buf;

View File

@ -14,6 +14,7 @@ int main(int, char **) { return 0; }
#include <Common/ThreadPool.h>
#include <Common/Stopwatch.h>
#include <Common/randomSeed.h>
#include <Common/getPageSize.h>
#include <pcg_random.hpp>
#include <IO/BufferWithOwnMemory.h>
#include <IO/ReadHelpers.h>
@ -52,7 +53,7 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block
std::vector<Memory<>> buffers(buffers_count);
for (size_t i = 0; i < buffers_count; ++i)
buffers[i] = Memory<>(block_size, sysconf(_SC_PAGESIZE));
buffers[i] = Memory<>(block_size, ::getPageSize());
pcg64_fast rng(randomSeed());