From f0879e4c396ab8ffd6246afea9f6400c5098bc12 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 21 Feb 2017 16:33:54 -0800 Subject: [PATCH] Page size isn't always 4k on linux Summary: Some places autodetected. These are the two places that didn't. closes #1498 Still unsure if the following instances of 4 * 1024 need fixing in: util/io_posix.h include/rocksdb/table.h (appears to be blocksize and different) utilities/persistent_cache/block_cache_tier.cc utilities/persistent_cache/persistent_cache_test.h include/rocksdb/env.h util/env_posix.cc db/column_family.cc Closes https://github.com/facebook/rocksdb/pull/1499 Differential Revision: D4593640 Pulled By: yiwu-arbug fbshipit-source-id: efc48de --- util/env_test.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/util/env_test.cc b/util/env_test.cc index 643a94e94..c38babd1f 100644 --- a/util/env_test.cc +++ b/util/env_test.cc @@ -48,6 +48,12 @@ #include "util/testharness.h" #include "util/testutil.h" +#ifdef OS_LINUX +static const size_t kPageSize = sysconf(_SC_PAGESIZE); +#else +static const size_t kPageSize = 4 * 1024; +#endif + namespace rocksdb { static const int kDelayMicros = 100000; @@ -67,12 +73,12 @@ struct Deleter { std::unique_ptr NewAligned(const size_t size, const char ch) { char* ptr = nullptr; #ifdef OS_WIN - if (!(ptr = reinterpret_cast(_aligned_malloc(size, 4 * 1024)))) { + if (!(ptr = reinterpret_cast(_aligned_malloc(size, kPageSize)))) { return std::unique_ptr(nullptr, Deleter(_aligned_free)); } std::unique_ptr uptr(ptr, Deleter(_aligned_free)); #else - if (posix_memalign(reinterpret_cast(&ptr), 4 * 1024, size) != 0) { + if (posix_memalign(reinterpret_cast(&ptr), kPageSize, size) != 0) { return std::unique_ptr(nullptr, Deleter(free)); } std::unique_ptr uptr(ptr, Deleter(free));