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
main
Peter Dillinger 5 years ago committed by Facebook Github Bot
parent 942eaba091
commit 43dde332cb
  1. 14
      env/env_test.cc
  2. 8
      include/rocksdb/advanced_options.h
  3. 3
      include/rocksdb/filter_policy.h
  4. 12
      port/port_posix.cc
  5. 4
      port/port_posix.h
  6. 3
      port/win/port_win.cc
  7. 15
      port/win/port_win.h

14
env/env_test.cc vendored

@ -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<SequentialFile> 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<char[]> 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);

@ -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<const SliceTransform>
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;

@ -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);

@ -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<size_t>(v);
}
#endif
// Default assume 4KB
return 4U * 1024U;
}
const size_t kPageSize = GetPageSize();
} // namespace port
} // namespace ROCKSDB_NAMESPACE

@ -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 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
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

@ -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

@ -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 <windows.h>
#include <string>
#include <string.h>
@ -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<size_t>::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__

Loading…
Cancel
Save