20 #include <glog/logging.h>
40 stop_requested_(false),
43 reclaimed_pages_(nullptr),
44 reclaimed_pages_count_(0) {
55 LOG(INFO) <<
"Initializing Snapshot Cache in Node-" <<
engine_->
get_soc_id() <<
"...";
72 uint64_t initial_allocations
108 LOG(INFO) <<
"Uninitializing Snapshot Cache... " <<
describe();
120 LOG(INFO) <<
"Here we go. Cleaner thread: " <<
describe();
122 const uint32_t kIntervalMs = 5;
124 DVLOG(2) <<
"Cleaner thread came in: " <<
describe();
130 VLOG(0) <<
"Time to evict: " <<
describe();
151 VLOG(0) <<
"We are in urgent lack of free pages, let's advance epoch right now";
156 const uint64_t interval_microsec = 100000ULL;
162 ASSERT_ND(reclaimed_pages_epoch < current_epoch);
163 VLOG(0) <<
"Okay! reclaimed_pages_epoch_=" << reclaimed_pages_epoch
164 <<
", current_epoch=" << current_epoch;
171 LOG(INFO) <<
"Wtf, we couldn't collect any pages? that's weird...: " <<
describe();
175 LOG(INFO) <<
"Umm, still severely lacking free pages. This might mean"
176 " that the cleaner thread is getting behind or the pool is too small: " <<
describe();
179 DVLOG(2) <<
"Still enough free pages. do nothing";
183 std::this_thread::sleep_for(std::chrono::milliseconds(kIntervalMs));
187 LOG(INFO) <<
"Quiting... Cleaner thread: " <<
describe();
199 bool original =
false;
200 bool changed =
stop_requested_.compare_exchange_strong(original,
true);
203 LOG(INFO) <<
"Requesting Cache Cleaner to stop...";
207 LOG(INFO) <<
"Cache Cleaner seems already stop-requested";
214 if (
pool_ ==
nullptr) {
215 return "<SnapshotCacheManager />";
218 std::stringstream str;
uint64_t allocated_pages_
numa_alloc_onnode() and numa_free().
memory::PagePoolOffset * reclaimed_pages_
This buffers pages being reclaimed.
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
uint32_t private_page_pool_initial_grab_
How many pages each NumaCoreMemory initially grabs when it is initialized.
Epoch get_current_global_epoch() const
Returns the current global epoch, the epoch a newly started transaction will be in.
void release_block()
Releases the memory block.
CacheHashtable * hashtable_
The cache hashtable (SnapshotPageId -> offset in pool) on top of the page pool.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
PagePool * get_snapshot_pool()
bool is_initialized() const override
Returns whether the object has been already initialized or not.
uint32_t PagePoolOffset
Offset in PagePool that compactly represents the page address (unlike 8 bytes pointer).
ErrorStack stop_cleaner()
0x0005 : "GENERAL: A dependent module is not initialized yet. This implies a wrong initialization ord...
Brings error stacktrace information as return value of functions.
std::string describe() const
void alloc(uint64_t size, uint64_t alignment, AllocType alloc_type, int numa_node) noexcept
Allocate a memory, releasing the current memory if exists.
std::atomic< bool > stop_requested_
to stop cleaner_
uint64_t urgent_threshold_
the number of allocated pages above which cleaner advances epoch to release pages ...
CacheManagerPimpl()=delete
memory::PagePool * pool_
The SOC-local snapshot page pool in this SOC engine.
const EngineOptions & get_options() const
ErrorStack uninitialize_once() override
bool is_master() const
Returns if this engine object is a master instance.
uint64_t evicted_count_
[Out] Number of entries that were actually evicted
memory::AlignedMemory reclaimed_pages_memory_
The memory backing reclaimed_pages_.
void handle_cleaner_evict_pages(uint64_t target_count)
Evicts pages up to about target_count (maybe a bit more or less).
memory::MemoryOptions memory_
void evict(EvictArgs *args)
Evict some entries from the hashtable.
std::thread cleaner_
The only cleaner thread in this SOC engine.
Database engine object that holds all resources and provides APIs.
float snapshot_cache_urgent_threshold_
When the cache eviction performs in an urgent mode, which immediately advances the current epoch to r...
Repository of memories dynamically acquired and shared within one NUMA node (socket).
uint64_t stop()
Take another current time tick.
float snapshot_cache_eviction_threshold_
When to start evicting pages in fraction of snapshot page pool capacity.
Xct Manager class that provides API to begin/abort/commit transaction.
Set of options for snapshot cache manager.
void * get_block() const
Returns the memory block.
void release(uint32_t desired_release_count, PagePoolOffsetChunk *chunk)
Returns the specified number of free pages from the chunk.
Used to point to an already existing array.
xct::XctManager * get_xct_manager() const
See Transaction Manager.
double elapsed_us() const
cache::CacheHashtable * get_snapshot_cache_table()
void wait_for_current_global_epoch(Epoch target_epoch, int64_t wait_microseconds=-1)
Passively wait until the current global epoch becomes the given value.
thread::ThreadOptions thread_
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
NumaNodeMemory * get_local_memory() const
const ErrorStack kRetOk
Normal return value for no-error case.
void advance_current_global_epoch()
Requests to advance the current global epoch as soon as possible and blocks until it actually does...
uint64_t reclaimed_pages_count_
Number of pages buffered so far.
void handle_cleaner()
Main routine of cleaner_.
uint64_t cleaner_threshold_
the number of allocated pages above which cleaner starts cleaning
ThreadId get_total_thread_count() const
void memory_fence_acquire()
Equivalent to std::atomic_thread_fence(std::memory_order_acquire).
ErrorStack initialize_once() override
soc::SocId get_soc_id() const
If this is a child instance, returns its SOC ID (NUMA node).
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
A high-resolution stop watch.
memory::EngineMemory * get_memory_manager() const
See Memory Manager.
bool is_initialized() const override final
Returns whether the object has been already initialized or not.
cache::CacheOptions cache_