Skip to content

Commit

Permalink
Minimally intrusive conservative cache tuning (#1269)
Browse files Browse the repository at this point in the history
* Minimally intrusive conservative cache tuning

* Update txdb.h

* Update dbwrapper.cpp

* Tune to use powers of 2

* Update dbwrapper.cpp

* Add casts

* Update dbwrapper.cpp

* Update dbwrapper.cpp
  • Loading branch information
prasannavl authored May 24, 2022
1 parent 95908f6 commit 120282a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/dbwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,18 @@ static void SetMaxOpenFiles(leveldb::Options *options) {

static leveldb::Options GetOptions(size_t nCacheSize)
{
const auto ceil_power_of_two = [](size_t v) {
v--;
for (const size_t i: {1, 2, 4, 6, 16}) v |= v >> i;
v++;
return v;
};

leveldb::Options options;
options.block_cache = leveldb::NewLRUCache(nCacheSize / 2);
options.write_buffer_size = nCacheSize / 4; // up to two write buffers may be held in memory simultaneously
options.filter_policy = leveldb::NewBloomFilterPolicy(10);
options.write_buffer_size = ceil_power_of_two(std::min(static_cast<size_t>(64)
<< 20, nCacheSize / 4)); // Max of 64mb -more is not useful
options.filter_policy = leveldb::NewBloomFilterPolicy(16);
options.compression = leveldb::kNoCompression;
options.info_log = new CDefiLevelDBLogger();
if (leveldb::kMajorVersion > 1 || (leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16)) {
Expand Down
4 changes: 2 additions & 2 deletions src/txdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class uint256;
//! No need to periodic flush if at least this much space still available.
static constexpr int MAX_BLOCK_COINSDB_USAGE = 10;
//! -dbcache default (MiB)
static const int64_t nDefaultDbCache = 450;
static const int64_t nDefaultDbCache = 512;
//! -dbbatchsize default (bytes)
static const int64_t nDefaultDbBatchSize = 16 << 20;
//! max. -dbcache (MiB)
static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
//! min. -dbcache (MiB)
static const int64_t nMinDbCache = 4;
//! Max memory allocated to block tree DB specific cache, if no -txindex (MiB)
static const int64_t nMaxBlockDBCache = 2;
static const int64_t nMaxBlockDBCache = 4;
//! Max memory allocated to block tree DB specific cache, if -txindex (MiB)
// Unlike for the UTXO database, for the txindex scenario the leveldb cache make
// a meaningful difference: https://github.com/bitcoin/bitcoin/pull/8273#issuecomment-229601991
Expand Down

0 comments on commit 120282a

Please sign in to comment.