From dbb2fbcdd54197c7689f4a5670b2834d8c24bb17 Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Thu, 29 Oct 2020 22:52:12 +0300 Subject: [PATCH] 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. --- src/Common/Arena.h | 1 + src/Common/StringSearcher.h | 3 ++- src/Common/getPageSize.cpp | 7 +++++++ src/Common/getPageSize.h | 4 ++++ src/Common/ya.make | 1 + src/IO/MMapReadBufferFromFileDescriptor.cpp | 3 ++- utils/iotest/iotest.cpp | 3 ++- utils/iotest/iotest_aio.cpp | 3 ++- 8 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/Common/getPageSize.cpp create mode 100644 src/Common/getPageSize.h diff --git a/src/Common/Arena.h b/src/Common/Arena.h index 44a9b444ff2..7e436a03273 100644 --- a/src/Common/Arena.h +++ b/src/Common/Arena.h @@ -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; } diff --git a/src/Common/StringSearcher.h b/src/Common/StringSearcher.h index a4da499837b..671aa93a7d2 100644 --- a/src/Common/StringSearcher.h +++ b/src/Common/StringSearcher.h @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -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 { diff --git a/src/Common/getPageSize.cpp b/src/Common/getPageSize.cpp new file mode 100644 index 00000000000..01c5f792ec2 --- /dev/null +++ b/src/Common/getPageSize.cpp @@ -0,0 +1,7 @@ +#include "getPageSize.h" + +#include + +long getPageSize() { + return sysconf(_SC_PAGESIZE); +} diff --git a/src/Common/getPageSize.h b/src/Common/getPageSize.h new file mode 100644 index 00000000000..7c8c4b4f559 --- /dev/null +++ b/src/Common/getPageSize.h @@ -0,0 +1,4 @@ +#pragma once + +/// Get memory page size +long getPageSize(); diff --git a/src/Common/ya.make b/src/Common/ya.make index e515741a272..7c36455c19f 100644 --- a/src/Common/ya.make +++ b/src/Common/ya.make @@ -99,6 +99,7 @@ SRCS( getMappedArea.cpp getMultipleKeysFromConfig.cpp getNumberOfPhysicalCPUCores.cpp + getPageSize.cpp hasLinuxCapability.cpp hex.cpp isLocalAddress.cpp diff --git a/src/IO/MMapReadBufferFromFileDescriptor.cpp b/src/IO/MMapReadBufferFromFileDescriptor.cpp index 655ae6c0525..7f881d6550b 100644 --- a/src/IO/MMapReadBufferFromFileDescriptor.cpp +++ b/src/IO/MMapReadBufferFromFileDescriptor.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -39,7 +40,7 @@ void MMapReadBufferFromFileDescriptor::init(int fd_, size_t offset, size_t lengt BufferBase::set(static_cast(buf), length, 0); - int page_size = ::getpagesize(); + int page_size = ::getPageSize(); ReadBuffer::padded = (length % page_size) > 0 && (length % page_size) <= (page_size - 15); } } diff --git a/utils/iotest/iotest.cpp b/utils/iotest/iotest.cpp index e578a539bcd..a4a9f504981 100644 --- a/utils/iotest/iotest.cpp +++ b/utils/iotest/iotest.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -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 simple_buf(block_size); char * buf; diff --git a/utils/iotest/iotest_aio.cpp b/utils/iotest/iotest_aio.cpp index 24508c1dd9f..24f7a849573 100644 --- a/utils/iotest/iotest_aio.cpp +++ b/utils/iotest/iotest_aio.cpp @@ -14,6 +14,7 @@ int main(int, char **) { return 0; } #include #include #include +#include #include #include #include @@ -52,7 +53,7 @@ void thread(int fd, int mode, size_t min_offset, size_t max_offset, size_t block std::vector> 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());