| 100 | |
| 101 | protected: |
| 102 | void SetupWithParameters(Cache::MemoryType mem_type, |
| 103 | Cache::EvictionPolicy eviction_policy, |
| 104 | ShardingPolicy sharding_policy) { |
| 105 | // Disable approximate tracking of cache memory since we make specific |
| 106 | // assertions on the MemTracker in this test. |
| 107 | FLAGS_cache_memtracker_approximation_ratio = 0; |
| 108 | |
| 109 | // Using single shard makes the logic of scenarios simple for capacity- |
| 110 | // and eviction-related behavior. |
| 111 | FLAGS_cache_force_single_shard = |
| 112 | (sharding_policy == ShardingPolicy::SingleShard); |
| 113 | |
| 114 | if (google::GetCommandLineFlagInfoOrDie("nvm_cache_path").is_default) { |
| 115 | FLAGS_nvm_cache_path = GetTestPath("nvm-cache"); |
| 116 | ASSERT_OK(Env::Default()->CreateDir(FLAGS_nvm_cache_path)); |
| 117 | } |
| 118 | |
| 119 | switch (eviction_policy) { |
| 120 | case Cache::EvictionPolicy::FIFO: |
| 121 | if (mem_type != Cache::MemoryType::DRAM) { |
| 122 | FAIL() << "FIFO cache can only be of DRAM type"; |
| 123 | } |
| 124 | cache_.reset(NewCache<Cache::EvictionPolicy::FIFO, |
| 125 | Cache::MemoryType::DRAM>(cache_size(), |
| 126 | "cache_test")); |
| 127 | MemTracker::FindTracker("cache_test-sharded_fifo_cache", &mem_tracker_); |
| 128 | break; |
| 129 | case Cache::EvictionPolicy::LRU: |
| 130 | switch (mem_type) { |
| 131 | case Cache::MemoryType::DRAM: |
| 132 | cache_.reset(NewCache<Cache::EvictionPolicy::LRU, |
| 133 | Cache::MemoryType::DRAM>(cache_size(), |
| 134 | "cache_test")); |
| 135 | break; |
| 136 | case Cache::MemoryType::NVM: |
| 137 | if (CanUseNVMCacheForTests()) { |
| 138 | cache_.reset(NewCache<Cache::EvictionPolicy::LRU, |
| 139 | Cache::MemoryType::NVM>(cache_size(), |
| 140 | "cache_test")); |
| 141 | } |
| 142 | break; |
| 143 | default: |
| 144 | FAIL() << mem_type << ": unrecognized cache memory type"; |
| 145 | break; |
| 146 | } |
| 147 | MemTracker::FindTracker("cache_test-sharded_lru_cache", &mem_tracker_); |
| 148 | break; |
| 149 | default: |
| 150 | FAIL() << "unrecognized cache eviction policy"; |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | // Since nvm cache does not have memtracker due to the use of |
| 155 | // tcmalloc for this we only check for it in the DRAM case. |
| 156 | if (mem_type == Cache::MemoryType::DRAM) { |
| 157 | ASSERT_TRUE(mem_tracker_.get()); |
| 158 | } |
| 159 |
nothing calls this directly
no test coverage detected