]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/utilities/sim_cache.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
11 #include "rocksdb/cache.h"
12 #include "rocksdb/env.h"
13 #include "rocksdb/slice.h"
14 #include "rocksdb/statistics.h"
15 #include "rocksdb/status.h"
21 // For instrumentation purpose, use NewSimCache instead of NewLRUCache API
22 // NewSimCache is a wrapper function returning a SimCache instance that can
23 // have additional interface provided in Simcache class besides Cache interface
24 // to predict block cache hit rate without actually allocating the memory. It
25 // can help users tune their current block cache size, and determine how
26 // efficient they are using the memory.
28 // Since GetSimCapacity() returns the capacity for simulutation, it differs from
29 // actual memory usage, which can be estimated as:
30 // sim_capacity * entry_size / (entry_size + block_size),
31 // where 76 <= entry_size <= 104,
32 // BlockBasedTableOptions.block_size = 4096 by default but is configurable,
33 // Therefore, generally the actual memory overhead of SimCache is Less than
35 extern std::shared_ptr
<SimCache
> NewSimCache(std::shared_ptr
<Cache
> cache
,
39 class SimCache
: public Cache
{
43 ~SimCache() override
{}
45 const char* Name() const override
{ return "SimCache"; }
47 // returns the maximum configured capacity of the simcache for simulation
48 virtual size_t GetSimCapacity() const = 0;
50 // simcache doesn't provide internal handler reference to user, so always
51 // PinnedUsage = 0 and the behavior will be not exactly consistent the
53 // returns the memory size for the entries residing in the simcache.
54 virtual size_t GetSimUsage() const = 0;
56 // sets the maximum configured capacity of the simcache. When the new
57 // capacity is less than the old capacity and the existing usage is
58 // greater than new capacity, the implementation will purge old entries
59 // to fit new capapicty.
60 virtual void SetSimCapacity(size_t capacity
) = 0;
62 // returns the lookup times of simcache
63 virtual uint64_t get_miss_counter() const = 0;
64 // returns the hit times of simcache
65 virtual uint64_t get_hit_counter() const = 0;
66 // reset the lookup and hit counters
67 virtual void reset_counter() = 0;
68 // String representation of the statistics of the simcache
69 virtual std::string
ToString() const = 0;
71 // Start storing logs of the cache activity (Add/Lookup) into
72 // a file located at activity_log_file, max_logging_size option can be used to
73 // stop logging to the file automatically after reaching a specific size in
74 // bytes, a values of 0 disable this feature
75 virtual Status
StartActivityLogging(const std::string
& activity_log_file
,
77 uint64_t max_logging_size
= 0) = 0;
79 // Stop cache activity logging if any
80 virtual void StopActivityLogging() = 0;
82 // Status of cache logging happening in background
83 virtual Status
GetActivityLoggingStatus() = 0;
86 SimCache(const SimCache
&);
87 SimCache
& operator=(const SimCache
&);
90 } // namespace rocksdb