From acc718b6cc79813e4de668846a4787c0ae947756 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Sun, 9 Feb 2020 18:43:27 +0300 Subject: [PATCH 1/3] Disable cache if exlipcit memory budget=0 passed --- kvdb-rocksdb/src/lib.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 40ee0f595..8d5c0ffe7 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -325,12 +325,16 @@ fn generate_block_based_options(config: &DatabaseConfig) -> BlockBasedOptions { // Set cache size as recommended by // https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning#block-cache-size let cache_size = config.memory_budget() / 3; - block_opts.set_lru_cache(cache_size); - // "index and filter blocks will be stored in block cache, together with all other data blocks." - // See: https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB#indexes-and-filter-blocks - block_opts.set_cache_index_and_filter_blocks(true); - // Don't evict L0 filter/index blocks from the cache - block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true); + if cache_size == 0 { + block_opts.disable_cache() + } else { + block_opts.set_lru_cache(cache_size); + // "index and filter blocks will be stored in block cache, together with all other data blocks." + // See: https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB#indexes-and-filter-blocks + block_opts.set_cache_index_and_filter_blocks(true); + // Don't evict L0 filter/index blocks from the cache + block_opts.set_pin_l0_filter_and_index_blocks_in_cache(true); + } block_opts.set_bloom_filter(10, true); block_opts From 66db6d5941f9a9ad4627d266fc915e330ee6dfb9 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Sun, 9 Feb 2020 19:29:59 +0300 Subject: [PATCH 2/3] don't warn on block cache property anymore --- kvdb-rocksdb/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index 8d5c0ffe7..a47f424ef 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -236,7 +236,7 @@ impl MallocSizeOf for DBAndColumns { fn size_of(&self, ops: &mut parity_util_mem::MallocSizeOfOps) -> usize { let mut total = self.column_names.size_of(ops) // we have at least one column always, so we can call property on it - + self.static_property_or_warn(0, "rocksdb.block-cache-usage"); + + self.maybe_property(0, "rocksdb.block-cache-usage").unwrap_or(0); for v in 0..self.column_names.len() { total += self.static_property_or_warn(v, "rocksdb.estimate-table-readers-mem"); @@ -261,6 +261,10 @@ impl DBAndColumns { } } } + + fn maybe_property(&self, col: usize, prop: &str) -> Option { + self.db.property_int_value_cf(self.cf(col), prop).unwrap_or(Some(0)).map(|x| x as usize) + } } /// Key-Value database. From 5876070bddacfeb1d1cde846a32828fb4201ddf0 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Mon, 10 Feb 2020 18:13:53 +0300 Subject: [PATCH 3/3] remove onliner --- kvdb-rocksdb/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kvdb-rocksdb/src/lib.rs b/kvdb-rocksdb/src/lib.rs index a47f424ef..681883c01 100644 --- a/kvdb-rocksdb/src/lib.rs +++ b/kvdb-rocksdb/src/lib.rs @@ -236,7 +236,11 @@ impl MallocSizeOf for DBAndColumns { fn size_of(&self, ops: &mut parity_util_mem::MallocSizeOfOps) -> usize { let mut total = self.column_names.size_of(ops) // we have at least one column always, so we can call property on it - + self.maybe_property(0, "rocksdb.block-cache-usage").unwrap_or(0); + + self.db + .property_int_value_cf(self.cf(0), "rocksdb.block-cache-usage") + .unwrap_or(Some(0)) + .map(|x| x as usize) + .unwrap_or(0); for v in 0..self.column_names.len() { total += self.static_property_or_warn(v, "rocksdb.estimate-table-readers-mem"); @@ -261,10 +265,6 @@ impl DBAndColumns { } } } - - fn maybe_property(&self, col: usize, prop: &str) -> Option { - self.db.property_int_value_cf(self.cf(col), prop).unwrap_or(Some(0)).map(|x| x as usize) - } } /// Key-Value database.