diff --git a/cache/clock_cache.cc b/cache/clock_cache.cc index 94a86ad3185..6608ed92167 100644 --- a/cache/clock_cache.cc +++ b/cache/clock_cache.cc @@ -700,7 +700,7 @@ std::shared_ptr NewClockCache( return NewLRUCache(capacity, num_shard_bits, strict_capacity_limit, /* high_pri_pool_ratio */ 0.5, nullptr, kDefaultToAdaptiveMutex, metadata_charge_policy, - /* low_pri_pool_ratio */ 0.5); + /* low_pri_pool_ratio */ 0.0); } std::shared_ptr ExperimentalNewClockCache( diff --git a/cache/compressed_secondary_cache_test.cc b/cache/compressed_secondary_cache_test.cc index f5fb486970d..65ef5a8b45b 100644 --- a/cache/compressed_secondary_cache_test.cc +++ b/cache/compressed_secondary_cache_test.cc @@ -242,7 +242,7 @@ class CompressedSecondaryCacheTest : public testing::Test { 1024 /* capacity */, 0 /* num_shard_bits */, false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); lru_cache_opts.secondary_cache = secondary_cache; std::shared_ptr cache = NewLRUCache(lru_cache_opts); std::shared_ptr stats = CreateDBStatistics(); @@ -324,11 +324,11 @@ class CompressedSecondaryCacheTest : public testing::Test { std::shared_ptr secondary_cache = NewCompressedSecondaryCache(secondary_cache_opts); - LRUCacheOptions opts( - 1024 /* capacity */, 0 /* num_shard_bits */, - false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, - nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + LRUCacheOptions opts(1024 /* capacity */, 0 /* num_shard_bits */, + false /* strict_capacity_limit */, + 0.5 /* high_pri_pool_ratio */, + nullptr /* memory_allocator */, + kDefaultToAdaptiveMutex, kDontChargeCacheMetadata); opts.secondary_cache = secondary_cache; std::shared_ptr cache = NewLRUCache(opts); @@ -373,11 +373,11 @@ class CompressedSecondaryCacheTest : public testing::Test { std::shared_ptr secondary_cache = NewCompressedSecondaryCache(secondary_cache_opts); - LRUCacheOptions opts( - 1024 /* capacity */, 0 /* num_shard_bits */, - false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, - nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + LRUCacheOptions opts(1024 /* capacity */, 0 /* num_shard_bits */, + false /* strict_capacity_limit */, + 0.5 /* high_pri_pool_ratio */, + nullptr /* memory_allocator */, + kDefaultToAdaptiveMutex, kDontChargeCacheMetadata); opts.secondary_cache = secondary_cache; std::shared_ptr cache = NewLRUCache(opts); @@ -432,11 +432,11 @@ class CompressedSecondaryCacheTest : public testing::Test { std::shared_ptr secondary_cache = NewCompressedSecondaryCache(secondary_cache_opts); - LRUCacheOptions opts( - 1024 /* capacity */, 0 /* num_shard_bits */, - false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, - nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + LRUCacheOptions opts(1024 /* capacity */, 0 /* num_shard_bits */, + false /* strict_capacity_limit */, + 0.5 /* high_pri_pool_ratio */, + nullptr /* memory_allocator */, + kDefaultToAdaptiveMutex, kDontChargeCacheMetadata); opts.secondary_cache = secondary_cache; std::shared_ptr cache = NewLRUCache(opts); @@ -491,11 +491,11 @@ class CompressedSecondaryCacheTest : public testing::Test { std::shared_ptr secondary_cache = NewCompressedSecondaryCache(secondary_cache_opts); - LRUCacheOptions opts( - 1024 /* capacity */, 0 /* num_shard_bits */, - true /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, - nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + LRUCacheOptions opts(1024 /* capacity */, 0 /* num_shard_bits */, + true /* strict_capacity_limit */, + 0.5 /* high_pri_pool_ratio */, + nullptr /* memory_allocator */, + kDefaultToAdaptiveMutex, kDontChargeCacheMetadata); opts.secondary_cache = secondary_cache; std::shared_ptr cache = NewLRUCache(opts); diff --git a/cache/lru_cache.cc b/cache/lru_cache.cc index 015d2748eea..ceafe95b49d 100644 --- a/cache/lru_cache.cc +++ b/cache/lru_cache.cc @@ -262,7 +262,8 @@ void LRUCacheShard::LRU_Insert(LRUHandle* e) { e->SetInLowPriPool(false); high_pri_pool_usage_ += e->total_charge; MaintainPoolSize(); - } else if (low_pri_pool_ratio_ > 0 && (e->IsLowPri() || e->HasHit())) { + } else if (low_pri_pool_ratio_ > 0 && + (e->IsHighPri() || e->IsLowPri() || e->HasHit())) { // Insert "e" to the head of low-pri pool. e->next = lru_low_pri_->next; e->prev = lru_low_pri_; @@ -842,7 +843,8 @@ std::shared_ptr NewLRUCache( return nullptr; } if (low_pri_pool_ratio < 0.0 || low_pri_pool_ratio > 1.0) { - low_pri_pool_ratio = 1.0 - high_pri_pool_ratio; + // Invalid high_pri_pool_ratio + return nullptr; } if (low_pri_pool_ratio + high_pri_pool_ratio > 1.0) { // Invalid high_pri_pool_ratio and low_pri_pool_ratio combination diff --git a/cache/lru_cache_test.cc b/cache/lru_cache_test.cc index 5fe8ce742b3..9ab87f7baff 100644 --- a/cache/lru_cache_test.cc +++ b/cache/lru_cache_test.cc @@ -705,8 +705,7 @@ class TestSecondaryCache : public SecondaryCache { : num_inserts_(0), num_lookups_(0), inject_failure_(false) { cache_ = NewLRUCache(capacity, 0, false, 0.5 /* high_pri_pool_ratio */, nullptr, - kDefaultToAdaptiveMutex, kDontChargeCacheMetadata, - 0.5 /* low_pri_pool_ratio */); + kDefaultToAdaptiveMutex, kDontChargeCacheMetadata); } ~TestSecondaryCache() override { cache_.reset(); } @@ -949,7 +948,7 @@ TEST_F(LRUCacheSecondaryCacheTest, BasicTest) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache = std::make_shared(2048); opts.secondary_cache = secondary_cache; @@ -996,7 +995,7 @@ TEST_F(LRUCacheSecondaryCacheTest, BasicFailTest) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache = std::make_shared(2048); opts.secondary_cache = secondary_cache; @@ -1028,7 +1027,7 @@ TEST_F(LRUCacheSecondaryCacheTest, SaveFailTest) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache = std::make_shared(2048); opts.secondary_cache = secondary_cache; @@ -1071,7 +1070,7 @@ TEST_F(LRUCacheSecondaryCacheTest, CreateFailTest) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache = std::make_shared(2048); opts.secondary_cache = secondary_cache; @@ -1115,7 +1114,7 @@ TEST_F(LRUCacheSecondaryCacheTest, FullCapacityTest) { true /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache = std::make_shared(2048); opts.secondary_cache = secondary_cache; @@ -1167,7 +1166,7 @@ TEST_F(DBSecondaryCacheTest, TestSecondaryCacheCorrectness1) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache( new TestSecondaryCache(2048 * 1024)); opts.secondary_cache = secondary_cache; @@ -1267,7 +1266,7 @@ TEST_F(DBSecondaryCacheTest, TestSecondaryCacheCorrectness2) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache( new TestSecondaryCache(2048 * 1024)); opts.secondary_cache = secondary_cache; @@ -1363,7 +1362,7 @@ TEST_F(DBSecondaryCacheTest, NoSecondaryCacheInsertion) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache( new TestSecondaryCache(2048 * 1024)); opts.secondary_cache = secondary_cache; @@ -1420,7 +1419,7 @@ TEST_F(DBSecondaryCacheTest, SecondaryCacheIntensiveTesting) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache( new TestSecondaryCache(2048 * 1024)); opts.secondary_cache = secondary_cache; @@ -1472,7 +1471,7 @@ TEST_F(DBSecondaryCacheTest, SecondaryCacheFailureTest) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache( new TestSecondaryCache(2048 * 1024)); opts.secondary_cache = secondary_cache; @@ -1567,7 +1566,7 @@ TEST_F(LRUCacheSecondaryCacheTest, BasicWaitAllTest) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache = std::make_shared(32 * 1024); opts.secondary_cache = secondary_cache; @@ -1626,7 +1625,7 @@ TEST_F(DBSecondaryCacheTest, TestSecondaryCacheMultiGet) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache( new TestSecondaryCache(2048 * 1024)); opts.secondary_cache = secondary_cache; @@ -1760,11 +1759,11 @@ class LRUCacheWithStat : public LRUCache { #ifndef ROCKSDB_LITE TEST_F(DBSecondaryCacheTest, LRUCacheDumpLoadBasic) { - LRUCacheOptions cache_opts( - 1024 * 1024 /* capacity */, 0 /* num_shard_bits */, - false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, - nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + LRUCacheOptions cache_opts(1024 * 1024 /* capacity */, 0 /* num_shard_bits */, + false /* strict_capacity_limit */, + 0.5 /* high_pri_pool_ratio */, + nullptr /* memory_allocator */, + kDefaultToAdaptiveMutex, kDontChargeCacheMetadata); LRUCacheWithStat* tmp_cache = new LRUCacheWithStat( cache_opts.capacity, cache_opts.num_shard_bits, cache_opts.strict_capacity_limit, cache_opts.high_pri_pool_ratio, @@ -1900,11 +1899,11 @@ TEST_F(DBSecondaryCacheTest, LRUCacheDumpLoadBasic) { } TEST_F(DBSecondaryCacheTest, LRUCacheDumpLoadWithFilter) { - LRUCacheOptions cache_opts( - 1024 * 1024 /* capacity */, 0 /* num_shard_bits */, - false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, - nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + LRUCacheOptions cache_opts(1024 * 1024 /* capacity */, 0 /* num_shard_bits */, + false /* strict_capacity_limit */, + 0.5 /* high_pri_pool_ratio */, + nullptr /* memory_allocator */, + kDefaultToAdaptiveMutex, kDontChargeCacheMetadata); LRUCacheWithStat* tmp_cache = new LRUCacheWithStat( cache_opts.capacity, cache_opts.num_shard_bits, cache_opts.strict_capacity_limit, cache_opts.high_pri_pool_ratio, @@ -2080,7 +2079,7 @@ TEST_F(DBSecondaryCacheTest, TestSecondaryCacheOptionBasic) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache( new TestSecondaryCache(2048 * 1024)); opts.secondary_cache = secondary_cache; @@ -2178,7 +2177,7 @@ TEST_F(DBSecondaryCacheTest, TestSecondaryCacheOptionChange) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache( new TestSecondaryCache(2048 * 1024)); opts.secondary_cache = secondary_cache; @@ -2276,7 +2275,7 @@ TEST_F(DBSecondaryCacheTest, TestSecondaryCacheOptionTwoDB) { false /* strict_capacity_limit */, 0.5 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 0.5 /* low_pri_pool_ratio */); + kDontChargeCacheMetadata); std::shared_ptr secondary_cache( new TestSecondaryCache(2048 * 1024)); opts.secondary_cache = secondary_cache; diff --git a/db/db_block_cache_test.cc b/db/db_block_cache_test.cc index e1dcc2b1d38..6171bb5f22a 100644 --- a/db/db_block_cache_test.cc +++ b/db/db_block_cache_test.cc @@ -820,7 +820,7 @@ class MockCache : public LRUCache { MockCache() : LRUCache((size_t)1 << 25 /*capacity*/, 0 /*num_shard_bits*/, false /*strict_capacity_limit*/, 0.0 /*high_pri_pool_ratio*/, - 1.0 /*low_pri_pool_ratio*/) {} + 0.0 /*low_pri_pool_ratio*/) {} using ShardedCache::Insert; diff --git a/db/db_test2.cc b/db/db_test2.cc index 99735a7156f..60cb54709cf 100644 --- a/db/db_test2.cc +++ b/db/db_test2.cc @@ -655,7 +655,7 @@ TEST_F(DBTest2, TestWriteBufferNoLimitWithCache) { 10000000 /* capacity */, 1 /* num_shard_bits */, false /* strict_capacity_limit */, 0.0 /* high_pri_pool_ratio */, nullptr /* memory_allocator */, kDefaultToAdaptiveMutex, - kDontChargeCacheMetadata, 1.0 /* low_pri_pool_ratio */)); + kDontChargeCacheMetadata)); options.write_buffer_size = 50000; // this is never hit // Use a write buffer total size so that the soft limit is about diff --git a/include/rocksdb/cache.h b/include/rocksdb/cache.h index bef933c38b9..d38fc37c475 100644 --- a/include/rocksdb/cache.h +++ b/include/rocksdb/cache.h @@ -79,10 +79,9 @@ struct LRUCacheOptions { // the low-pri list (the midpoint) and bottom-pri entries will be first // inserted to the bottom-pri list. // - // The default value is -1.0, which means that uses (1 - high_pri_pool_ratio). // // See also high_pri_pool_ratio. - double low_pri_pool_ratio = -1.0; + double low_pri_pool_ratio = 0.0; // If non-nullptr will use this allocator instead of system allocator when // allocating memory for cache blocks. Call this method before you start using @@ -112,7 +111,7 @@ struct LRUCacheOptions { bool _use_adaptive_mutex = kDefaultToAdaptiveMutex, CacheMetadataChargePolicy _metadata_charge_policy = kDefaultCacheMetadataChargePolicy, - double _low_pri_pool_ratio = -1.0) + double _low_pri_pool_ratio = 0.0) : capacity(_capacity), num_shard_bits(_num_shard_bits), strict_capacity_limit(_strict_capacity_limit), @@ -138,7 +137,7 @@ extern std::shared_ptr NewLRUCache( bool use_adaptive_mutex = kDefaultToAdaptiveMutex, CacheMetadataChargePolicy metadata_charge_policy = kDefaultCacheMetadataChargePolicy, - double low_pri_pool_ratio = -1.0); + double low_pri_pool_ratio = 0.0); extern std::shared_ptr NewLRUCache(const LRUCacheOptions& cache_opts); @@ -166,7 +165,7 @@ struct CompressedSecondaryCacheOptions : LRUCacheOptions { CacheMetadataChargePolicy _metadata_charge_policy = kDefaultCacheMetadataChargePolicy, CompressionType _compression_type = CompressionType::kLZ4Compression, - uint32_t _compress_format_version = 2, double _low_pri_pool_ratio = -1.0) + uint32_t _compress_format_version = 2, double _low_pri_pool_ratio = 0.0) : LRUCacheOptions(_capacity, _num_shard_bits, _strict_capacity_limit, _high_pri_pool_ratio, std::move(_memory_allocator), _use_adaptive_mutex, _metadata_charge_policy, @@ -185,7 +184,7 @@ extern std::shared_ptr NewCompressedSecondaryCache( CacheMetadataChargePolicy metadata_charge_policy = kDefaultCacheMetadataChargePolicy, CompressionType compression_type = CompressionType::kLZ4Compression, - uint32_t compress_format_version = 2, double low_pri_pool_ratio = -1.0); + uint32_t compress_format_version = 2, double low_pri_pool_ratio = 0.0); extern std::shared_ptr NewCompressedSecondaryCache( const CompressedSecondaryCacheOptions& opts); diff --git a/table/block_based/block_based_table_factory.cc b/table/block_based/block_based_table_factory.cc index 6629e2e5a60..0192605afd1 100644 --- a/table/block_based/block_based_table_factory.cc +++ b/table/block_based/block_based_table_factory.cc @@ -454,7 +454,7 @@ void BlockBasedTableFactory::InitializeOptions() { // It makes little sense to pay overhead for mid-point insertion while the // block size is only 8MB. co.high_pri_pool_ratio = 0.0; - co.low_pri_pool_ratio = 1.0; + co.low_pri_pool_ratio = 0.0; table_options_.block_cache = NewLRUCache(co); } if (table_options_.block_size_deviation < 0 || diff --git a/tools/benchmark.sh b/tools/benchmark.sh index 288389845cd..5a2d358899d 100755 --- a/tools/benchmark.sh +++ b/tools/benchmark.sh @@ -192,7 +192,7 @@ if [[ $cache_index_and_filter -eq 0 ]]; then elif [[ $cache_index_and_filter -eq 1 ]]; then cache_meta_flags="\ --cache_index_and_filter_blocks=$cache_index_and_filter \ - --cache_high_pri_pool_ratio=0.5 --cache_low_pri_pool_ratio=0.5" + --cache_high_pri_pool_ratio=0.5 --cache_low_pri_pool_ratio=0" else echo CACHE_INDEX_AND_FILTER_BLOCKS was $CACHE_INDEX_AND_FILTER_BLOCKS but must be 0 or 1 exit $EXIT_INVALID_ARGS diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index 0c155223466..cd4e73340a8 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -570,7 +570,7 @@ DEFINE_double(cache_high_pri_pool_ratio, 0.0, "If > 0.0, we also enable " "cache_index_and_filter_blocks_with_high_priority."); -DEFINE_double(cache_low_pri_pool_ratio, 1.0, +DEFINE_double(cache_low_pri_pool_ratio, 0.0, "Ratio of block cache reserve for low pri blocks."); DEFINE_string(cache_type, "lru_cache", "Type of block cache."); @@ -592,7 +592,7 @@ DEFINE_double(compressed_secondary_cache_high_pri_pool_ratio, 0.0, "If > 0.0, we also enable " "cache_index_and_filter_blocks_with_high_priority."); -DEFINE_double(compressed_secondary_cache_low_pri_pool_ratio, 1.0, +DEFINE_double(compressed_secondary_cache_low_pri_pool_ratio, 0.0, "Ratio of block cache reserve for low pri blocks."); DEFINE_string(compressed_secondary_cache_compression_type, "lz4",