2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2013-10-16 21:59:46 +00:00
|
|
|
//
|
2011-03-18 22:37:00 +00:00
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
//
|
|
|
|
// See port_example.h for documentation for the following types/functions.
|
|
|
|
|
2015-02-24 06:05:06 +00:00
|
|
|
#pragma once
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2017-02-06 22:43:55 +00:00
|
|
|
#include <thread>
|
2020-02-20 20:07:53 +00:00
|
|
|
|
remove dependency on options.h for port_posix.h andport_win.h (#11214)
Summary:
The files in `port/`, such as `port_posix.h`, are layering over the system libraries, so shouldn't include the DB-specific files like `options.h`. This PR remove this dependency.
# How
The reason that `port_posix.h` (or `port_win.h`) include `options.h` is to use `CpuPriority`, as there is a method `SetCpuPriority()` in `port_posix.h` that uses `CpuPriority.`
- I think `SetCpuPriority()` make sense to exist in `port_posix.h` as it provides has platform-dependent implementation
- `CpuPriority` enum is defined in `env.h`, but used in `rocksdb/include` and `port/`.
Hence, let us define `CpuPriority` enum in a common file, say `port_defs.h`, such that both directories `rocksdb/include` and `port/` can include.
When we remove this dependency, some other files have compile errors because they can't find definitions, so add header files to resolve
# Test
make all check -j
Pull Request resolved: https://github.com/facebook/rocksdb/pull/11214
Reviewed By: pdillinger
Differential Revision: D43196910
Pulled By: guowentian
fbshipit-source-id: 70deccb72844cfb08fcc994f76c6ef6df5d55ab9
2023-02-13 10:21:38 +00:00
|
|
|
#include "rocksdb/port_defs.h"
|
2020-02-20 20:07:53 +00:00
|
|
|
#include "rocksdb/rocksdb_namespace.h"
|
|
|
|
|
2015-07-13 19:11:05 +00:00
|
|
|
// size_t printf formatting named in the manner of C99 standard formatting
|
|
|
|
// strings such as PRIu64
|
2015-07-01 23:13:49 +00:00
|
|
|
// in fact, we could use that one
|
|
|
|
#define ROCKSDB_PRIszt "zu"
|
|
|
|
|
2016-01-13 22:51:58 +00:00
|
|
|
#define __declspec(S)
|
|
|
|
|
2012-08-27 06:45:35 +00:00
|
|
|
#undef PLATFORM_IS_LITTLE_ENDIAN
|
2012-03-05 18:35:46 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2022-10-24 23:56:01 +00:00
|
|
|
#include <machine/endian.h>
|
|
|
|
#if defined(__DARWIN_LITTLE_ENDIAN) && defined(__DARWIN_BYTE_ORDER)
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN \
|
|
|
|
(__DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN)
|
|
|
|
#endif
|
2011-06-29 00:30:50 +00:00
|
|
|
#elif defined(OS_SOLARIS)
|
2022-10-24 23:56:01 +00:00
|
|
|
#include <sys/isa_defs.h>
|
|
|
|
#ifdef _LITTLE_ENDIAN
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN true
|
|
|
|
#else
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN false
|
|
|
|
#endif
|
|
|
|
#include <alloca.h>
|
2017-04-22 03:41:37 +00:00
|
|
|
#elif defined(OS_AIX)
|
2022-10-24 23:56:01 +00:00
|
|
|
#include <arpa/nameser_compat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN (BYTE_ORDER == LITTLE_ENDIAN)
|
|
|
|
#include <alloca.h>
|
2015-11-16 20:56:21 +00:00
|
|
|
#elif defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_NETBSD) || \
|
|
|
|
defined(OS_DRAGONFLYBSD) || defined(OS_ANDROID)
|
2022-10-24 23:56:01 +00:00
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN (_BYTE_ORDER == _LITTLE_ENDIAN)
|
2011-06-29 00:30:50 +00:00
|
|
|
#else
|
2022-10-24 23:56:01 +00:00
|
|
|
#include <endian.h>
|
2011-06-29 00:30:50 +00:00
|
|
|
#endif
|
2011-03-18 22:37:00 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <stdint.h>
|
2012-06-28 06:41:33 +00:00
|
|
|
#include <string.h>
|
2022-10-24 23:56:01 +00:00
|
|
|
|
support for concurrent adds to memtable
Summary:
This diff adds support for concurrent adds to the skiplist memtable
implementations. Memory allocation is made thread-safe by the addition of
a spinlock, with small per-core buffers to avoid contention. Concurrent
memtable writes are made via an additional method and don't impose a
performance overhead on the non-concurrent case, so parallelism can be
selected on a per-batch basis.
Write thread synchronization is an increasing bottleneck for higher levels
of concurrency, so this diff adds --enable_write_thread_adaptive_yield
(default off). This feature causes threads joining a write batch
group to spin for a short time (default 100 usec) using sched_yield,
rather than going to sleep on a mutex. If the timing of the yield calls
indicates that another thread has actually run during the yield then
spinning is avoided. This option improves performance for concurrent
situations even without parallel adds, although it has the potential to
increase CPU usage (and the heuristic adaptation is not yet mature).
Parallel writes are not currently compatible with
inplace updates, update callbacks, or delete filtering.
Enable it with --allow_concurrent_memtable_write (and
--enable_write_thread_adaptive_yield). Parallel memtable writes
are performance neutral when there is no actual parallelism, and in
my experiments (SSD server-class Linux and varying contention and key
sizes for fillrandom) they are always a performance win when there is
more than one thread.
Statistics are updated earlier in the write path, dropping the number
of DB mutex acquisitions from 2 to 1 for almost all cases.
This diff was motivated and inspired by Yahoo's cLSM work. It is more
conservative than cLSM: RocksDB's write batch group leader role is
preserved (along with all of the existing flush and write throttling
logic) and concurrent writers are blocked until all memtable insertions
have completed and the sequence number has been advanced, to preserve
linearizability.
My test config is "db_bench -benchmarks=fillrandom -threads=$T
-batch_size=1 -memtablerep=skip_list -value_size=100 --num=1000000/$T
-level0_slowdown_writes_trigger=9999 -level0_stop_writes_trigger=9999
-disable_auto_compactions --max_write_buffer_number=8
-max_background_flushes=8 --disable_wal --write_buffer_size=160000000
--block_size=16384 --allow_concurrent_memtable_write" on a two-socket
Xeon E5-2660 @ 2.2Ghz with lots of memory and an SSD hard drive. With 1
thread I get ~440Kops/sec. Peak performance for 1 socket (numactl
-N1) is slightly more than 1Mops/sec, at 16 threads. Peak performance
across both sockets happens at 30 threads, and is ~900Kops/sec, although
with fewer threads there is less performance loss when the system has
background work.
Test Plan:
1. concurrent stress tests for InlineSkipList and DynamicBloom
2. make clean; make check
3. make clean; DISABLE_JEMALLOC=1 make valgrind_check; valgrind db_bench
4. make clean; COMPILE_WITH_TSAN=1 make all check; db_bench
5. make clean; COMPILE_WITH_ASAN=1 make all check; db_bench
6. make clean; OPT=-DROCKSDB_LITE make check
7. verify no perf regressions when disabled
Reviewers: igor, sdong
Reviewed By: sdong
Subscribers: MarkCallaghan, IslamAbdelRahman, anthony, yhchiang, rven, sdong, guyg8, kradhakrishnan, dhruba
Differential Revision: https://reviews.facebook.net/D50589
2015-08-14 23:59:07 +00:00
|
|
|
#include <limits>
|
|
|
|
#include <string>
|
2011-06-29 00:30:50 +00:00
|
|
|
|
2012-08-27 06:45:35 +00:00
|
|
|
#ifndef PLATFORM_IS_LITTLE_ENDIAN
|
|
|
|
#define PLATFORM_IS_LITTLE_ENDIAN (__BYTE_ORDER == __LITTLE_ENDIAN)
|
2011-06-29 00:30:50 +00:00
|
|
|
#endif
|
|
|
|
|
2022-10-24 23:56:01 +00:00
|
|
|
#if defined(OS_MACOSX) || defined(OS_SOLARIS) || defined(OS_FREEBSD) || \
|
|
|
|
defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_DRAGONFLYBSD) || \
|
2017-04-22 03:41:37 +00:00
|
|
|
defined(OS_ANDROID) || defined(CYGWIN) || defined(OS_AIX)
|
2012-03-05 18:35:46 +00:00
|
|
|
// Use fread/fwrite/fflush on platforms without _unlocked variants
|
2011-06-29 00:30:50 +00:00
|
|
|
#define fread_unlocked fread
|
|
|
|
#define fwrite_unlocked fwrite
|
|
|
|
#define fflush_unlocked fflush
|
|
|
|
#endif
|
|
|
|
|
2022-10-24 23:56:01 +00:00
|
|
|
#if defined(OS_MACOSX) || defined(OS_FREEBSD) || defined(OS_OPENBSD) || \
|
|
|
|
defined(OS_DRAGONFLYBSD)
|
2012-03-05 18:35:46 +00:00
|
|
|
// Use fsync() on platforms without fdatasync()
|
2011-06-29 00:30:50 +00:00
|
|
|
#define fdatasync fsync
|
|
|
|
#endif
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2012-08-27 06:45:35 +00:00
|
|
|
#if defined(OS_ANDROID) && __ANDROID_API__ < 9
|
|
|
|
// fdatasync() was only introduced in API level 9 on Android. Use fsync()
|
2015-12-10 16:54:48 +00:00
|
|
|
// when targeting older platforms.
|
2012-08-27 06:45:35 +00:00
|
|
|
#define fdatasync fsync
|
|
|
|
#endif
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2019-03-20 19:24:57 +00:00
|
|
|
|
|
|
|
extern const bool kDefaultToAdaptiveMutex;
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
namespace port {
|
2020-02-22 15:59:38 +00:00
|
|
|
constexpr bool kLittleEndian = PLATFORM_IS_LITTLE_ENDIAN;
|
2012-08-27 06:45:35 +00:00
|
|
|
#undef PLATFORM_IS_LITTLE_ENDIAN
|
2011-03-18 22:37:00 +00:00
|
|
|
|
|
|
|
class CondVar;
|
|
|
|
|
|
|
|
class Mutex {
|
|
|
|
public:
|
2022-06-17 20:08:45 +00:00
|
|
|
static const char* kName() { return "pthread_mutex_t"; }
|
|
|
|
|
2019-03-20 19:24:57 +00:00
|
|
|
explicit Mutex(bool adaptive = kDefaultToAdaptiveMutex);
|
2019-09-12 01:07:12 +00:00
|
|
|
// No copying
|
|
|
|
Mutex(const Mutex&) = delete;
|
|
|
|
void operator=(const Mutex&) = delete;
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
~Mutex();
|
|
|
|
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
2021-09-24 23:52:30 +00:00
|
|
|
|
|
|
|
bool TryLock();
|
|
|
|
|
2014-04-23 01:38:10 +00:00
|
|
|
// this will assert if the mutex is not locked
|
|
|
|
// it does NOT verify that mutex is held by a calling thread
|
2014-03-26 18:24:52 +00:00
|
|
|
void AssertHeld();
|
2011-03-18 22:37:00 +00:00
|
|
|
|
2022-06-17 20:08:45 +00:00
|
|
|
// Also implement std Lockable
|
|
|
|
inline void lock() { Lock(); }
|
|
|
|
inline void unlock() { Unlock(); }
|
|
|
|
inline bool try_lock() { return TryLock(); }
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
private:
|
|
|
|
friend class CondVar;
|
|
|
|
pthread_mutex_t mu_;
|
2014-03-26 18:24:52 +00:00
|
|
|
#ifndef NDEBUG
|
2020-06-04 22:32:29 +00:00
|
|
|
bool locked_ = false;
|
2014-03-26 18:24:52 +00:00
|
|
|
#endif
|
2011-03-18 22:37:00 +00:00
|
|
|
};
|
|
|
|
|
2012-10-02 04:58:36 +00:00
|
|
|
class RWMutex {
|
|
|
|
public:
|
|
|
|
RWMutex();
|
2019-09-12 01:07:12 +00:00
|
|
|
// No copying allowed
|
|
|
|
RWMutex(const RWMutex&) = delete;
|
|
|
|
void operator=(const RWMutex&) = delete;
|
|
|
|
|
2012-10-02 04:58:36 +00:00
|
|
|
~RWMutex();
|
|
|
|
|
|
|
|
void ReadLock();
|
|
|
|
void WriteLock();
|
2014-06-16 22:41:46 +00:00
|
|
|
void ReadUnlock();
|
|
|
|
void WriteUnlock();
|
2022-10-24 23:56:01 +00:00
|
|
|
void AssertHeld() {}
|
2012-10-02 04:58:36 +00:00
|
|
|
|
|
|
|
private:
|
2022-10-24 23:56:01 +00:00
|
|
|
pthread_rwlock_t mu_; // the underlying platform mutex
|
2012-10-02 04:58:36 +00:00
|
|
|
};
|
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
class CondVar {
|
|
|
|
public:
|
|
|
|
explicit CondVar(Mutex* mu);
|
|
|
|
~CondVar();
|
|
|
|
void Wait();
|
2014-07-03 17:22:08 +00:00
|
|
|
// Timed condition wait. Returns true if timeout occurred.
|
|
|
|
bool TimedWait(uint64_t abs_time_us);
|
2011-03-18 22:37:00 +00:00
|
|
|
void Signal();
|
|
|
|
void SignalAll();
|
2022-10-24 23:56:01 +00:00
|
|
|
|
2011-03-18 22:37:00 +00:00
|
|
|
private:
|
|
|
|
pthread_cond_t cv_;
|
|
|
|
Mutex* mu_;
|
|
|
|
};
|
|
|
|
|
2017-02-06 22:43:55 +00:00
|
|
|
using Thread = std::thread;
|
|
|
|
|
support for concurrent adds to memtable
Summary:
This diff adds support for concurrent adds to the skiplist memtable
implementations. Memory allocation is made thread-safe by the addition of
a spinlock, with small per-core buffers to avoid contention. Concurrent
memtable writes are made via an additional method and don't impose a
performance overhead on the non-concurrent case, so parallelism can be
selected on a per-batch basis.
Write thread synchronization is an increasing bottleneck for higher levels
of concurrency, so this diff adds --enable_write_thread_adaptive_yield
(default off). This feature causes threads joining a write batch
group to spin for a short time (default 100 usec) using sched_yield,
rather than going to sleep on a mutex. If the timing of the yield calls
indicates that another thread has actually run during the yield then
spinning is avoided. This option improves performance for concurrent
situations even without parallel adds, although it has the potential to
increase CPU usage (and the heuristic adaptation is not yet mature).
Parallel writes are not currently compatible with
inplace updates, update callbacks, or delete filtering.
Enable it with --allow_concurrent_memtable_write (and
--enable_write_thread_adaptive_yield). Parallel memtable writes
are performance neutral when there is no actual parallelism, and in
my experiments (SSD server-class Linux and varying contention and key
sizes for fillrandom) they are always a performance win when there is
more than one thread.
Statistics are updated earlier in the write path, dropping the number
of DB mutex acquisitions from 2 to 1 for almost all cases.
This diff was motivated and inspired by Yahoo's cLSM work. It is more
conservative than cLSM: RocksDB's write batch group leader role is
preserved (along with all of the existing flush and write throttling
logic) and concurrent writers are blocked until all memtable insertions
have completed and the sequence number has been advanced, to preserve
linearizability.
My test config is "db_bench -benchmarks=fillrandom -threads=$T
-batch_size=1 -memtablerep=skip_list -value_size=100 --num=1000000/$T
-level0_slowdown_writes_trigger=9999 -level0_stop_writes_trigger=9999
-disable_auto_compactions --max_write_buffer_number=8
-max_background_flushes=8 --disable_wal --write_buffer_size=160000000
--block_size=16384 --allow_concurrent_memtable_write" on a two-socket
Xeon E5-2660 @ 2.2Ghz with lots of memory and an SSD hard drive. With 1
thread I get ~440Kops/sec. Peak performance for 1 socket (numactl
-N1) is slightly more than 1Mops/sec, at 16 threads. Peak performance
across both sockets happens at 30 threads, and is ~900Kops/sec, although
with fewer threads there is less performance loss when the system has
background work.
Test Plan:
1. concurrent stress tests for InlineSkipList and DynamicBloom
2. make clean; make check
3. make clean; DISABLE_JEMALLOC=1 make valgrind_check; valgrind db_bench
4. make clean; COMPILE_WITH_TSAN=1 make all check; db_bench
5. make clean; COMPILE_WITH_ASAN=1 make all check; db_bench
6. make clean; OPT=-DROCKSDB_LITE make check
7. verify no perf regressions when disabled
Reviewers: igor, sdong
Reviewed By: sdong
Subscribers: MarkCallaghan, IslamAbdelRahman, anthony, yhchiang, rven, sdong, guyg8, kradhakrishnan, dhruba
Differential Revision: https://reviews.facebook.net/D50589
2015-08-14 23:59:07 +00:00
|
|
|
static inline void AsmVolatilePause() {
|
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
|
|
|
asm volatile("pause");
|
|
|
|
#elif defined(__aarch64__)
|
2022-06-15 20:08:11 +00:00
|
|
|
asm volatile("isb");
|
support for concurrent adds to memtable
Summary:
This diff adds support for concurrent adds to the skiplist memtable
implementations. Memory allocation is made thread-safe by the addition of
a spinlock, with small per-core buffers to avoid contention. Concurrent
memtable writes are made via an additional method and don't impose a
performance overhead on the non-concurrent case, so parallelism can be
selected on a per-batch basis.
Write thread synchronization is an increasing bottleneck for higher levels
of concurrency, so this diff adds --enable_write_thread_adaptive_yield
(default off). This feature causes threads joining a write batch
group to spin for a short time (default 100 usec) using sched_yield,
rather than going to sleep on a mutex. If the timing of the yield calls
indicates that another thread has actually run during the yield then
spinning is avoided. This option improves performance for concurrent
situations even without parallel adds, although it has the potential to
increase CPU usage (and the heuristic adaptation is not yet mature).
Parallel writes are not currently compatible with
inplace updates, update callbacks, or delete filtering.
Enable it with --allow_concurrent_memtable_write (and
--enable_write_thread_adaptive_yield). Parallel memtable writes
are performance neutral when there is no actual parallelism, and in
my experiments (SSD server-class Linux and varying contention and key
sizes for fillrandom) they are always a performance win when there is
more than one thread.
Statistics are updated earlier in the write path, dropping the number
of DB mutex acquisitions from 2 to 1 for almost all cases.
This diff was motivated and inspired by Yahoo's cLSM work. It is more
conservative than cLSM: RocksDB's write batch group leader role is
preserved (along with all of the existing flush and write throttling
logic) and concurrent writers are blocked until all memtable insertions
have completed and the sequence number has been advanced, to preserve
linearizability.
My test config is "db_bench -benchmarks=fillrandom -threads=$T
-batch_size=1 -memtablerep=skip_list -value_size=100 --num=1000000/$T
-level0_slowdown_writes_trigger=9999 -level0_stop_writes_trigger=9999
-disable_auto_compactions --max_write_buffer_number=8
-max_background_flushes=8 --disable_wal --write_buffer_size=160000000
--block_size=16384 --allow_concurrent_memtable_write" on a two-socket
Xeon E5-2660 @ 2.2Ghz with lots of memory and an SSD hard drive. With 1
thread I get ~440Kops/sec. Peak performance for 1 socket (numactl
-N1) is slightly more than 1Mops/sec, at 16 threads. Peak performance
across both sockets happens at 30 threads, and is ~900Kops/sec, although
with fewer threads there is less performance loss when the system has
background work.
Test Plan:
1. concurrent stress tests for InlineSkipList and DynamicBloom
2. make clean; make check
3. make clean; DISABLE_JEMALLOC=1 make valgrind_check; valgrind db_bench
4. make clean; COMPILE_WITH_TSAN=1 make all check; db_bench
5. make clean; COMPILE_WITH_ASAN=1 make all check; db_bench
6. make clean; OPT=-DROCKSDB_LITE make check
7. verify no perf regressions when disabled
Reviewers: igor, sdong
Reviewed By: sdong
Subscribers: MarkCallaghan, IslamAbdelRahman, anthony, yhchiang, rven, sdong, guyg8, kradhakrishnan, dhruba
Differential Revision: https://reviews.facebook.net/D50589
2015-08-14 23:59:07 +00:00
|
|
|
#elif defined(__powerpc64__)
|
|
|
|
asm volatile("or 27,27,27");
|
2023-01-13 16:42:44 +00:00
|
|
|
#elif defined(__loongarch64)
|
|
|
|
asm volatile("dbar 0");
|
support for concurrent adds to memtable
Summary:
This diff adds support for concurrent adds to the skiplist memtable
implementations. Memory allocation is made thread-safe by the addition of
a spinlock, with small per-core buffers to avoid contention. Concurrent
memtable writes are made via an additional method and don't impose a
performance overhead on the non-concurrent case, so parallelism can be
selected on a per-batch basis.
Write thread synchronization is an increasing bottleneck for higher levels
of concurrency, so this diff adds --enable_write_thread_adaptive_yield
(default off). This feature causes threads joining a write batch
group to spin for a short time (default 100 usec) using sched_yield,
rather than going to sleep on a mutex. If the timing of the yield calls
indicates that another thread has actually run during the yield then
spinning is avoided. This option improves performance for concurrent
situations even without parallel adds, although it has the potential to
increase CPU usage (and the heuristic adaptation is not yet mature).
Parallel writes are not currently compatible with
inplace updates, update callbacks, or delete filtering.
Enable it with --allow_concurrent_memtable_write (and
--enable_write_thread_adaptive_yield). Parallel memtable writes
are performance neutral when there is no actual parallelism, and in
my experiments (SSD server-class Linux and varying contention and key
sizes for fillrandom) they are always a performance win when there is
more than one thread.
Statistics are updated earlier in the write path, dropping the number
of DB mutex acquisitions from 2 to 1 for almost all cases.
This diff was motivated and inspired by Yahoo's cLSM work. It is more
conservative than cLSM: RocksDB's write batch group leader role is
preserved (along with all of the existing flush and write throttling
logic) and concurrent writers are blocked until all memtable insertions
have completed and the sequence number has been advanced, to preserve
linearizability.
My test config is "db_bench -benchmarks=fillrandom -threads=$T
-batch_size=1 -memtablerep=skip_list -value_size=100 --num=1000000/$T
-level0_slowdown_writes_trigger=9999 -level0_stop_writes_trigger=9999
-disable_auto_compactions --max_write_buffer_number=8
-max_background_flushes=8 --disable_wal --write_buffer_size=160000000
--block_size=16384 --allow_concurrent_memtable_write" on a two-socket
Xeon E5-2660 @ 2.2Ghz with lots of memory and an SSD hard drive. With 1
thread I get ~440Kops/sec. Peak performance for 1 socket (numactl
-N1) is slightly more than 1Mops/sec, at 16 threads. Peak performance
across both sockets happens at 30 threads, and is ~900Kops/sec, although
with fewer threads there is less performance loss when the system has
background work.
Test Plan:
1. concurrent stress tests for InlineSkipList and DynamicBloom
2. make clean; make check
3. make clean; DISABLE_JEMALLOC=1 make valgrind_check; valgrind db_bench
4. make clean; COMPILE_WITH_TSAN=1 make all check; db_bench
5. make clean; COMPILE_WITH_ASAN=1 make all check; db_bench
6. make clean; OPT=-DROCKSDB_LITE make check
7. verify no perf regressions when disabled
Reviewers: igor, sdong
Reviewed By: sdong
Subscribers: MarkCallaghan, IslamAbdelRahman, anthony, yhchiang, rven, sdong, guyg8, kradhakrishnan, dhruba
Differential Revision: https://reviews.facebook.net/D50589
2015-08-14 23:59:07 +00:00
|
|
|
#endif
|
|
|
|
// it's okay for other platforms to be no-ops
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns -1 if not available on this platform
|
|
|
|
extern int PhysicalCoreID();
|
|
|
|
|
2021-09-07 18:31:12 +00:00
|
|
|
using OnceType = pthread_once_t;
|
2012-08-27 06:45:35 +00:00
|
|
|
#define LEVELDB_ONCE_INIT PTHREAD_ONCE_INIT
|
|
|
|
extern void InitOnce(OnceType* once, void (*initializer)());
|
|
|
|
|
2017-05-08 23:04:19 +00:00
|
|
|
#ifndef CACHE_LINE_SIZE
|
2019-09-16 23:15:18 +00:00
|
|
|
// To test behavior with non-native cache line size, e.g. for
|
|
|
|
// Bloom filters, set TEST_CACHE_LINE_SIZE to the desired test size.
|
|
|
|
// This disables ALIGN_AS to keep it from failing compilation.
|
|
|
|
#ifdef TEST_CACHE_LINE_SIZE
|
|
|
|
#define CACHE_LINE_SIZE TEST_CACHE_LINE_SIZE
|
|
|
|
#define ALIGN_AS(n) /*empty*/
|
|
|
|
#else
|
|
|
|
#if defined(__s390__)
|
2021-12-22 20:56:45 +00:00
|
|
|
#if defined(__GNUC__) && __GNUC__ < 7
|
2021-10-22 17:12:09 +00:00
|
|
|
#define CACHE_LINE_SIZE 64U
|
|
|
|
#else
|
2019-09-16 23:15:18 +00:00
|
|
|
#define CACHE_LINE_SIZE 256U
|
2021-10-22 17:12:09 +00:00
|
|
|
#endif
|
2019-09-16 23:15:18 +00:00
|
|
|
#elif defined(__powerpc__) || defined(__aarch64__)
|
|
|
|
#define CACHE_LINE_SIZE 128U
|
|
|
|
#else
|
|
|
|
#define CACHE_LINE_SIZE 64U
|
|
|
|
#endif
|
|
|
|
#define ALIGN_AS(n) alignas(n)
|
|
|
|
#endif
|
2017-05-08 23:04:19 +00:00
|
|
|
#endif
|
2014-03-28 16:21:20 +00:00
|
|
|
|
2019-09-16 23:15:18 +00:00
|
|
|
static_assert((CACHE_LINE_SIZE & (CACHE_LINE_SIZE - 1)) == 0,
|
|
|
|
"Cache line size must be a power of 2 number of bytes");
|
2017-07-24 17:46:21 +00:00
|
|
|
|
2022-10-24 23:56:01 +00:00
|
|
|
extern void* cacheline_aligned_alloc(size_t size);
|
2017-07-24 17:46:21 +00:00
|
|
|
|
2022-10-24 23:56:01 +00:00
|
|
|
extern void cacheline_aligned_free(void* memblock);
|
2017-07-24 17:46:21 +00:00
|
|
|
|
2022-06-15 00:58:44 +00:00
|
|
|
#if defined(__aarch64__)
|
|
|
|
// __builtin_prefetch(..., 1) turns into a prefetch into prfm pldl3keep. On
|
|
|
|
// arm64 we want this as close to the core as possible to turn it into a
|
|
|
|
// L1 prefetech unless locality == 0 in which case it will be turned into a
|
|
|
|
// non-temporal prefetch
|
|
|
|
#define PREFETCH(addr, rw, locality) \
|
|
|
|
__builtin_prefetch(addr, rw, locality >= 1 ? 3 : locality)
|
|
|
|
#else
|
2014-06-12 17:06:18 +00:00
|
|
|
#define PREFETCH(addr, rw, locality) __builtin_prefetch(addr, rw, locality)
|
2022-06-15 00:58:44 +00:00
|
|
|
#endif
|
2014-06-12 17:06:18 +00:00
|
|
|
|
Move rate_limiter, write buffering, most perf context instrumentation and most random kill out of Env
Summary: We want to keep Env a think layer for better portability. Less platform dependent codes should be moved out of Env. In this patch, I create a wrapper of file readers and writers, and put rate limiting, write buffering, as well as most perf context instrumentation and random kill out of Env. It will make it easier to maintain multiple Env in the future.
Test Plan: Run all existing unit tests.
Reviewers: anthony, kradhakrishnan, IslamAbdelRahman, yhchiang, igor
Reviewed By: igor
Subscribers: leveldb, dhruba
Differential Revision: https://reviews.facebook.net/D42321
2015-07-17 23:16:11 +00:00
|
|
|
extern void Crash(const std::string& srcfile, int srcline);
|
2015-09-10 17:49:28 +00:00
|
|
|
|
|
|
|
extern int GetMaxOpenFiles();
|
|
|
|
|
2020-02-22 15:59:38 +00:00
|
|
|
extern const size_t kPageSize;
|
|
|
|
|
2020-03-29 02:05:54 +00:00
|
|
|
using ThreadId = pid_t;
|
|
|
|
|
|
|
|
extern void SetCpuPriority(ThreadId id, CpuPriority priority);
|
|
|
|
|
2021-08-25 00:45:01 +00:00
|
|
|
int64_t GetProcessID();
|
|
|
|
|
Built-in support for generating unique IDs, bug fix (#8708)
Summary:
Env::GenerateUniqueId() works fine on Windows and on POSIX
where /proc/sys/kernel/random/uuid exists. Our other implementation is
flawed and easily produces collision in a new multi-threaded test.
As we rely more heavily on DB session ID uniqueness, this becomes a
serious issue.
This change combines several individually suitable entropy sources
for reliable generation of random unique IDs, with goal of uniqueness
and portability, not cryptographic strength nor maximum speed.
Specifically:
* Moves code for getting UUIDs from the OS to port::GenerateRfcUuid
rather than in Env implementation details. Callers are now told whether
the operation fails or succeeds.
* Adds an internal API GenerateRawUniqueId for generating high-quality
128-bit unique identifiers, by combining entropy from three "tracks":
* Lots of info from default Env like time, process id, and hostname.
* std::random_device
* port::GenerateRfcUuid (when working)
* Built-in implementations of Env::GenerateUniqueId() will now always
produce an RFC 4122 UUID string, either from platform-specific API or
by converting the output of GenerateRawUniqueId.
DB session IDs now use GenerateRawUniqueId while DB IDs (not as
critical) try to use port::GenerateRfcUuid but fall back on
GenerateRawUniqueId with conversion to an RFC 4122 UUID.
GenerateRawUniqueId is declared and defined under env/ rather than util/
or even port/ because of the Env dependency.
Likely follow-up: enhance GenerateRawUniqueId to be faster after the
first call and to guarantee uniqueness within the lifetime of a single
process (imparting the same property onto DB session IDs).
Pull Request resolved: https://github.com/facebook/rocksdb/pull/8708
Test Plan:
A new mini-stress test in env_test checks the various public
and internal APIs for uniqueness, including each track of
GenerateRawUniqueId individually. We can't hope to verify anywhere close
to 128 bits of entropy, but it can at least detect flaws as bad as the
old code. Serial execution of the new tests takes about 350 ms on
my machine.
Reviewed By: zhichao-cao, mrambacher
Differential Revision: D30563780
Pulled By: pdillinger
fbshipit-source-id: de4c9ff4b2f581cf784fcedb5f39f16e5185c364
2021-08-30 22:19:39 +00:00
|
|
|
// Uses platform APIs to generate a 36-character RFC-4122 UUID. Returns
|
|
|
|
// true on success or false on failure.
|
|
|
|
bool GenerateRfcUuid(std::string* output);
|
|
|
|
|
2022-10-24 23:56:01 +00:00
|
|
|
} // namespace port
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|