diff --git a/env/env_test.cc b/env/env_test.cc index a0aa08f32793efaf05d627399c83b7f8cc54d491..98f73d9a9d6c7a59aa56116aecf060ba73737b87 100644 --- a/env/env_test.cc +++ b/env/env_test.cc @@ -42,14 +42,10 @@ #include "util/mutexlock.h" #include "util/string_util.h" -#ifdef OS_LINUX -static const size_t kPageSize = sysconf(_SC_PAGESIZE); -#else -static const size_t kPageSize = 4 * 1024; -#endif - namespace ROCKSDB_NAMESPACE { +using port::kPageSize; + static const int kDelayMicros = 100000; struct Deleter { @@ -881,9 +877,10 @@ TEST_F(EnvPosixTest, PositionedAppend) { // Verify the above std::unique_ptr seq_file; ASSERT_OK(env_->NewSequentialFile(ift.name() + "/f", &seq_file, options)); - char scratch[kPageSize * 2]; + size_t scratch_len = kPageSize * 2; + std::unique_ptr scratch(new char[scratch_len]); Slice result; - ASSERT_OK(seq_file->Read(sizeof(scratch), &result, scratch)); + ASSERT_OK(seq_file->Read(scratch_len, &result, scratch.get())); ASSERT_EQ(kPageSize + kBlockSize, result.size()); ASSERT_EQ('a', result[kBlockSize - 1]); ASSERT_EQ('b', result[kBlockSize]); @@ -977,7 +974,6 @@ TEST_P(EnvPosixTestWithParam, AllocateTest) { // allocate 100 MB size_t kPreallocateSize = 100 * 1024 * 1024; size_t kBlockSize = 512; - size_t kPageSize = 4096; size_t kDataSize = 1024 * 1024; auto data_ptr = NewAligned(kDataSize, 'A'); Slice data(data_ptr.get(), kDataSize); diff --git a/include/rocksdb/advanced_options.h b/include/rocksdb/advanced_options.h index 8e4f93743e8a53a4e659b9acb0a971f6e3eb7aea..a72edbe0593b0ee72bcdd6fb26ec02d442294e56 100644 --- a/include/rocksdb/advanced_options.h +++ b/include/rocksdb/advanced_options.h @@ -151,7 +151,6 @@ enum UpdateStatus { // Return status For inplace update callback UPDATED = 2, // No inplace update. Merged value set }; - struct AdvancedColumnFamilyOptions { // The maximum number of write buffers that are built up in memory. // The default and the minimum number is 2, so that when 1 write buffer @@ -330,10 +329,9 @@ struct AdvancedColumnFamilyOptions { std::shared_ptr memtable_insert_with_hint_prefix_extractor = nullptr; - // Control locality of bloom filter probes to improve cache miss rate. - // This option only applies to memtable prefix bloom and plaintable - // prefix bloom. It essentially limits every bloom checking to one cache line. - // This optimization is turned off when set to 0, and positive number to turn + // Control locality of bloom filter probes to improve CPU cache hit rate. + // This option now only applies to plaintable prefix bloom. This + // optimization is turned off when set to 0, and positive number to turn // it on. // Default: 0 uint32_t bloom_locality = 0; diff --git a/include/rocksdb/filter_policy.h b/include/rocksdb/filter_policy.h index c7e4e720a66f943e1ffe08f84a8b431f68cbf3fa..03d6471cff2105083a9bdb5b96a48e84a578d48e 100644 --- a/include/rocksdb/filter_policy.h +++ b/include/rocksdb/filter_policy.h @@ -84,7 +84,8 @@ class FilterBitsReader { }; // Contextual information passed to BloomFilterPolicy at filter building time. -// Used in overriding FilterPolicy::GetBuilderWithContext(). +// Used in overriding FilterPolicy::GetBuilderWithContext(). References other +// structs because this is expected to be a temporary, stack-allocated object. struct FilterBuildingContext { // This constructor is for internal use only and subject to change. FilterBuildingContext(const BlockBasedTableOptions& table_options); diff --git a/port/port_posix.cc b/port/port_posix.cc index f5001411ccc2b883b2b2092ed3700cb27cef3c21..e3ea5ca6967bb5b141fdde9457dc74c4c9a9ea94 100644 --- a/port/port_posix.cc +++ b/port/port_posix.cc @@ -217,6 +217,18 @@ void cacheline_aligned_free(void *memblock) { free(memblock); } +static size_t GetPageSize() { +#if defined(OS_LINUX) || defined(_SC_PAGESIZE) + long v = sysconf(_SC_PAGESIZE); + if (v >= 1024) { + return static_cast(v); + } +#endif + // Default assume 4KB + return 4U * 1024U; +} + +const size_t kPageSize = GetPageSize(); } // namespace port } // namespace ROCKSDB_NAMESPACE diff --git a/port/port_posix.h b/port/port_posix.h index f08a4ee2205564285df51887227daa1d63e2186e..0c9c69833d1fd93e626d28cc97fd49ad783c9530 100644 --- a/port/port_posix.h +++ b/port/port_posix.h @@ -99,7 +99,7 @@ const int64_t kMaxInt64 = std::numeric_limits::max(); const int64_t kMinInt64 = std::numeric_limits::min(); const size_t kMaxSizet = std::numeric_limits::max(); -static const bool kLittleEndian = PLATFORM_IS_LITTLE_ENDIAN; +constexpr bool kLittleEndian = PLATFORM_IS_LITTLE_ENDIAN; #undef PLATFORM_IS_LITTLE_ENDIAN class CondVar; @@ -212,5 +212,7 @@ extern void Crash(const std::string& srcfile, int srcline); extern int GetMaxOpenFiles(); +extern const size_t kPageSize; + } // namespace port } // namespace ROCKSDB_NAMESPACE diff --git a/port/win/port_win.cc b/port/win/port_win.cc index 5a19c33a87098b7ba5c8f4d69432750c3415ed72..6e43b1b58f51c63a144137d371d5cd577b599d70 100644 --- a/port/win/port_win.cc +++ b/port/win/port_win.cc @@ -262,5 +262,8 @@ void Crash(const std::string& srcfile, int srcline) { int GetMaxOpenFiles() { return -1; } +// Assume 4KB page size +const size_t kPageSize = 4U * 1024U; + } // namespace port } // namespace ROCKSDB_NAMESPACE diff --git a/port/win/port_win.h b/port/win/port_win.h index 80f68bcdeeddd8e04269b5816b27168f34d4b94b..76fc8cf39fb77f98671a1e06480a6a7d8051cb06 100644 --- a/port/win/port_win.h +++ b/port/win/port_win.h @@ -16,10 +16,6 @@ #define WIN32_LEAN_AND_MEAN #endif -// Assume that for everywhere -#undef PLATFORM_IS_LITTLE_ENDIAN -#define PLATFORM_IS_LITTLE_ENDIAN true - #include #include #include @@ -70,10 +66,6 @@ typedef SSIZE_T ssize_t; #endif -#ifndef PLATFORM_IS_LITTLE_ENDIAN -#define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN) -#endif - namespace ROCKSDB_NAMESPACE { #define PREFETCH(addr, rw, locality) @@ -122,7 +114,10 @@ const size_t kMaxSizet = std::numeric_limits::max(); #endif //_MSC_VER -const bool kLittleEndian = true; +// "Windows is designed to run on little-endian computer architectures." +// https://docs.microsoft.com/en-us/windows/win32/sysinfo/registry-value-types +constexpr bool kLittleEndian = true; +#undef PLATFORM_IS_LITTLE_ENDIAN class CondVar; @@ -270,6 +265,8 @@ inline void cacheline_aligned_free(void *memblock) { #endif } +extern const size_t kPageSize; + // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 for MINGW32 // could not be worked around with by -mno-ms-bitfields #ifndef __MINGW32__