Share kPageSize (and other small tweaks) (#6443)

Summary:
Make kPageSize extern const size_t (used in draft https://github.com/facebook/rocksdb/issues/6427)
Make kLitteEndian constexpr bool
Clarify a couple of comments
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6443

Test Plan: make check, CI

Differential Revision: D20044558

Pulled By: pdillinger

fbshipit-source-id: e0c5cc13229c82726280dc0ddcba4078346b8418
This commit is contained in:
Peter Dillinger 2020-02-22 07:59:38 -08:00 committed by Facebook Github Bot
parent 942eaba091
commit 43dde332cb
7 changed files with 34 additions and 25 deletions

14
env/env_test.cc vendored
View File

@ -42,14 +42,10 @@
#include "util/mutexlock.h" #include "util/mutexlock.h"
#include "util/string_util.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 { namespace ROCKSDB_NAMESPACE {
using port::kPageSize;
static const int kDelayMicros = 100000; static const int kDelayMicros = 100000;
struct Deleter { struct Deleter {
@ -881,9 +877,10 @@ TEST_F(EnvPosixTest, PositionedAppend) {
// Verify the above // Verify the above
std::unique_ptr<SequentialFile> seq_file; std::unique_ptr<SequentialFile> seq_file;
ASSERT_OK(env_->NewSequentialFile(ift.name() + "/f", &seq_file, options)); ASSERT_OK(env_->NewSequentialFile(ift.name() + "/f", &seq_file, options));
char scratch[kPageSize * 2]; size_t scratch_len = kPageSize * 2;
std::unique_ptr<char[]> scratch(new char[scratch_len]);
Slice result; 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(kPageSize + kBlockSize, result.size());
ASSERT_EQ('a', result[kBlockSize - 1]); ASSERT_EQ('a', result[kBlockSize - 1]);
ASSERT_EQ('b', result[kBlockSize]); ASSERT_EQ('b', result[kBlockSize]);
@ -977,7 +974,6 @@ TEST_P(EnvPosixTestWithParam, AllocateTest) {
// allocate 100 MB // allocate 100 MB
size_t kPreallocateSize = 100 * 1024 * 1024; size_t kPreallocateSize = 100 * 1024 * 1024;
size_t kBlockSize = 512; size_t kBlockSize = 512;
size_t kPageSize = 4096;
size_t kDataSize = 1024 * 1024; size_t kDataSize = 1024 * 1024;
auto data_ptr = NewAligned(kDataSize, 'A'); auto data_ptr = NewAligned(kDataSize, 'A');
Slice data(data_ptr.get(), kDataSize); Slice data(data_ptr.get(), kDataSize);

View File

@ -151,7 +151,6 @@ enum UpdateStatus { // Return status For inplace update callback
UPDATED = 2, // No inplace update. Merged value set UPDATED = 2, // No inplace update. Merged value set
}; };
struct AdvancedColumnFamilyOptions { struct AdvancedColumnFamilyOptions {
// The maximum number of write buffers that are built up in memory. // 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 // The default and the minimum number is 2, so that when 1 write buffer
@ -330,10 +329,9 @@ struct AdvancedColumnFamilyOptions {
std::shared_ptr<const SliceTransform> std::shared_ptr<const SliceTransform>
memtable_insert_with_hint_prefix_extractor = nullptr; memtable_insert_with_hint_prefix_extractor = nullptr;
// Control locality of bloom filter probes to improve cache miss rate. // Control locality of bloom filter probes to improve CPU cache hit rate.
// This option only applies to memtable prefix bloom and plaintable // This option now only applies to plaintable prefix bloom. This
// prefix bloom. It essentially limits every bloom checking to one cache line. // optimization is turned off when set to 0, and positive number to turn
// This optimization is turned off when set to 0, and positive number to turn
// it on. // it on.
// Default: 0 // Default: 0
uint32_t bloom_locality = 0; uint32_t bloom_locality = 0;

View File

@ -84,7 +84,8 @@ class FilterBitsReader {
}; };
// Contextual information passed to BloomFilterPolicy at filter building time. // 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 { struct FilterBuildingContext {
// This constructor is for internal use only and subject to change. // This constructor is for internal use only and subject to change.
FilterBuildingContext(const BlockBasedTableOptions& table_options); FilterBuildingContext(const BlockBasedTableOptions& table_options);

View File

@ -217,6 +217,18 @@ void cacheline_aligned_free(void *memblock) {
free(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<size_t>(v);
}
#endif
// Default assume 4KB
return 4U * 1024U;
}
const size_t kPageSize = GetPageSize();
} // namespace port } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

View File

@ -99,7 +99,7 @@ const int64_t kMaxInt64 = std::numeric_limits<int64_t>::max();
const int64_t kMinInt64 = std::numeric_limits<int64_t>::min(); const int64_t kMinInt64 = std::numeric_limits<int64_t>::min();
const size_t kMaxSizet = std::numeric_limits<size_t>::max(); const size_t kMaxSizet = std::numeric_limits<size_t>::max();
static const bool kLittleEndian = PLATFORM_IS_LITTLE_ENDIAN; constexpr bool kLittleEndian = PLATFORM_IS_LITTLE_ENDIAN;
#undef PLATFORM_IS_LITTLE_ENDIAN #undef PLATFORM_IS_LITTLE_ENDIAN
class CondVar; class CondVar;
@ -212,5 +212,7 @@ extern void Crash(const std::string& srcfile, int srcline);
extern int GetMaxOpenFiles(); extern int GetMaxOpenFiles();
extern const size_t kPageSize;
} // namespace port } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

View File

@ -262,5 +262,8 @@ void Crash(const std::string& srcfile, int srcline) {
int GetMaxOpenFiles() { return -1; } int GetMaxOpenFiles() { return -1; }
// Assume 4KB page size
const size_t kPageSize = 4U * 1024U;
} // namespace port } // namespace port
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

View File

@ -16,10 +16,6 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
// Assume that for everywhere
#undef PLATFORM_IS_LITTLE_ENDIAN
#define PLATFORM_IS_LITTLE_ENDIAN true
#include <windows.h> #include <windows.h>
#include <string> #include <string>
#include <string.h> #include <string.h>
@ -70,10 +66,6 @@ typedef SSIZE_T ssize_t;
#endif #endif
#ifndef PLATFORM_IS_LITTLE_ENDIAN
#define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
#endif
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
#define PREFETCH(addr, rw, locality) #define PREFETCH(addr, rw, locality)
@ -122,7 +114,10 @@ const size_t kMaxSizet = std::numeric_limits<size_t>::max();
#endif //_MSC_VER #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; class CondVar;
@ -270,6 +265,8 @@ inline void cacheline_aligned_free(void *memblock) {
#endif #endif
} }
extern const size_t kPageSize;
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 for MINGW32 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991 for MINGW32
// could not be worked around with by -mno-ms-bitfields // could not be worked around with by -mno-ms-bitfields
#ifndef __MINGW32__ #ifndef __MINGW32__