mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-29 18:33:58 +00:00
0d755fff14
Summary: By constraining the probes within cache line(s), we can improve the cache miss rate thus performance. This probably only makes sense for in-memory workload so defaults the option to off. Numbers and comparision can be found in wiki: https://our.intern.facebook.com/intern/wiki/index.php/Ljin/rocksdb_perf/2014_03_17#Bloom_Filter_Study Test Plan: benchmarked this change substantially. Will run make all check as well Reviewers: haobo, igor, dhruba, sdong, yhchiang Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D17133
51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
#include "dynamic_bloom.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include "port/port.h"
|
|
#include "rocksdb/slice.h"
|
|
#include "util/hash.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
namespace {
|
|
static uint32_t BloomHash(const Slice& key) {
|
|
return Hash(key.data(), key.size(), 0xbc9f1d34);
|
|
}
|
|
}
|
|
|
|
DynamicBloom::DynamicBloom(uint32_t total_bits,
|
|
uint32_t cl_per_block,
|
|
uint32_t num_probes,
|
|
uint32_t (*hash_func)(const Slice& key))
|
|
: kBlocked(cl_per_block > 0),
|
|
kBitsPerBlock(std::min(cl_per_block, num_probes) * CACHE_LINE_SIZE * 8),
|
|
kTotalBits((kBlocked ? (total_bits + kBitsPerBlock - 1) / kBitsPerBlock
|
|
* kBitsPerBlock :
|
|
total_bits + 7) / 8 * 8),
|
|
kNumBlocks(kBlocked ? kTotalBits / kBitsPerBlock : 1),
|
|
kNumProbes(num_probes),
|
|
hash_func_(hash_func == nullptr ? &BloomHash : hash_func) {
|
|
assert(kBlocked ? kTotalBits > 0 : kTotalBits >= kBitsPerBlock);
|
|
assert(kNumProbes > 0);
|
|
|
|
uint32_t sz = kTotalBits / 8;
|
|
if (kBlocked) {
|
|
sz += CACHE_LINE_SIZE - 1;
|
|
}
|
|
raw_ = new unsigned char[sz]();
|
|
if (kBlocked) {
|
|
data_ = raw_ + CACHE_LINE_SIZE -
|
|
reinterpret_cast<uint64_t>(raw_) % CACHE_LINE_SIZE;
|
|
} else {
|
|
data_ = raw_;
|
|
}
|
|
}
|
|
|
|
} // rocksdb
|