libfoedus-core
FOEDUS Core Library
foedus::memory::EngineMemory Class Referencefinal

Repository of all memories dynamically acquired and shared within one database engine. More...

Detailed Description

Repository of all memories dynamically acquired and shared within one database engine.

Overview
This is the top-level memory repository in our engine. All other memory types are contained in this object.
List of engine-wide memories
  • List of NumaNodeMemory, one for each NUMA socket in the machine.
  • Page pool for volatile read/write store (VolatilePage) and the read-only bufferpool (SnapshotPage).

Definition at line 52 of file engine_memory.hpp.

#include <engine_memory.hpp>

Inheritance diagram for foedus::memory::EngineMemory:
Collaboration diagram for foedus::memory::EngineMemory:

Public Member Functions

 EngineMemory ()=delete
 
 EngineMemory (Engine *engine)
 
ErrorStack initialize_once () override
 
ErrorStack uninitialize_once () override
 
void * get_shared_user_memory () const
 As part of the global shared memory, we reserve this size of 'user memory' that can be used for arbitrary purporses by the user to communicate between SOCs. More...
 
uint64_t get_shared_user_memory_size () const
 
NumaNodeMemoryget_local_memory () const
 
NumaNodeMemoryRefget_node_memory (foedus::thread::ThreadGroupId group) const
 
std::string dump_free_memory_stat () const
 Report rough statistics of free memory. More...
 
const GlobalVolatilePageResolverget_global_volatile_page_resolver () const
 Returns the page resolver to convert volatile page ID to page pointer. More...
 
ErrorStack grab_one_volatile_page (foedus::thread::ThreadGroupId node, storage::VolatilePagePointer *pointer, storage::Page **page)
 A convenience function to grab one free volatile page from the given node. More...
 
ErrorStack load_one_volatile_page (cache::SnapshotFileSet *fileset, storage::SnapshotPagePointer snapshot_pointer, storage::VolatilePagePointer *pointer, storage::Page **page)
 Another convenience method that also reads an existing snapshot page to the volatile page. More...
 
- Public Member Functions inherited from foedus::DefaultInitializable
 DefaultInitializable ()
 
virtual ~DefaultInitializable ()
 
 DefaultInitializable (const DefaultInitializable &)=delete
 
DefaultInitializableoperator= (const DefaultInitializable &)=delete
 
ErrorStack initialize () override final
 Typical implementation of Initializable::initialize() that provides initialize-once semantics. More...
 
ErrorStack uninitialize () override final
 Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics. More...
 
bool is_initialized () const override final
 Returns whether the object has been already initialized or not. More...
 
- Public Member Functions inherited from foedus::Initializable
virtual ~Initializable ()
 

Constructor & Destructor Documentation

foedus::memory::EngineMemory::EngineMemory ( )
delete
foedus::memory::EngineMemory::EngineMemory ( Engine engine)
inlineexplicit

Definition at line 55 of file engine_memory.hpp.

55 : engine_(engine), local_memory_(CXX11_NULLPTR) {}
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132

Member Function Documentation

std::string foedus::memory::EngineMemory::dump_free_memory_stat ( ) const

Report rough statistics of free memory.

Definition at line 121 of file engine_memory.cpp.

References foedus::memory::NumaNodeMemoryRef::dump_free_memory_stat(), foedus::Engine::get_options(), foedus::thread::ThreadOptions::group_count_, and foedus::EngineOptions::thread_.

121  {
122  std::stringstream ret;
123  ret << " == Free memory stat ==" << std::endl;
124  thread::ThreadGroupId numa_nodes = engine_->get_options().thread_.group_count_;
125  for (thread::ThreadGroupId node = 0; node < numa_nodes; ++node) {
126  NumaNodeMemoryRef* memory = node_memories_[node];
127  ret << " - Node_" << static_cast<int>(node) << " -" << std::endl;
128  ret << memory->dump_free_memory_stat();
129  if (node + 1U < numa_nodes) {
130  ret << std::endl;
131  }
132  }
133  return ret.str();
134 }
const EngineOptions & get_options() const
Definition: engine.cpp:39
uint16_t group_count_
Number of ThreadGroup in the engine.
thread::ThreadOptions thread_
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38

Here is the call graph for this function:

const GlobalVolatilePageResolver& foedus::memory::EngineMemory::get_global_volatile_page_resolver ( ) const
inline

Returns the page resolver to convert volatile page ID to page pointer.

Any code can get the global page resolver from engine memory. Note that this is only for volatile pages. As snapshot cache is per-node, there is no global snapshot page resolver (just the node-local one should be enough).

See also
thread::Thread::get_global_volatile_page_resolver()

Definition at line 90 of file engine_memory.hpp.

Referenced by foedus::storage::hash::HashStoragePimpl::debugout_single_thread(), foedus::storage::hash::HashStoragePimpl::debugout_single_thread_data(), foedus::storage::masstree::MasstreeStoragePimpl::debugout_single_thread_follow(), foedus::storage::hash::HashStoragePimpl::debugout_single_thread_intermediate(), foedus::storage::array::ArrayPartitioner::design_partition(), foedus::storage::masstree::MasstreePartitioner::design_partition(), foedus::storage::masstree::design_partition_first_parallel(), foedus::storage::hash::HashPartitioner::design_partition_task(), foedus::storage::array::ArrayStorage::drop(), foedus::storage::masstree::MasstreeStoragePimpl::drop(), foedus::storage::hash::HashStoragePimpl::drop(), foedus::storage::Composer::DropVolatilesArguments::drop(), foedus::storage::sequential::SequentialStoragePimpl::get_head_pointer(), foedus::storage::sequential::SequentialStoragePimpl::get_tail_pointer(), foedus::storage::hash::HashStoragePimpl::hcc_reset_all_temperature_stat_data(), foedus::storage::masstree::MasstreeStoragePimpl::hcc_reset_all_temperature_stat_follow(), foedus::storage::array::ArrayStoragePimpl::hcc_reset_all_temperature_stat_intermediate(), foedus::storage::hash::HashStoragePimpl::hcc_reset_all_temperature_stat_intermediate(), foedus::xct::Xct::initialize(), foedus::thread::ThreadPimpl::initialize_once(), foedus::storage::masstree::MasstreeStoragePimpl::peek_volatile_page_boundaries(), foedus::storage::StorageManagerPimpl::reinitialize_for_recovered_snapshot(), foedus::storage::hash::HashIntermediatePage::release_pages_recursive_parallel(), foedus::storage::masstree::release_parallel(), foedus::storage::hash::release_parallel(), foedus::storage::masstree::MasstreeBorderPage::track_moved_record(), foedus::storage::masstree::MasstreeBorderPage::track_moved_record_next_layer(), foedus::storage::hash::HashStoragePimpl::track_moved_record_search(), foedus::storage::hash::HashStoragePimpl::verify_single_thread(), foedus::storage::hash::HashStoragePimpl::verify_single_thread_data(), and foedus::storage::hash::HashStoragePimpl::verify_single_thread_intermediate().

90  {
91  return global_volatile_page_resolver_;
92  }

Here is the caller graph for this function:

NumaNodeMemory* foedus::memory::EngineMemory::get_local_memory ( ) const
inline
void * foedus::memory::EngineMemory::get_shared_user_memory ( ) const

As part of the global shared memory, we reserve this size of 'user memory' that can be used for arbitrary purporses by the user to communicate between SOCs.

See also
get_shared_user_memory_size()

Definition at line 113 of file engine_memory.cpp.

References foedus::soc::SocManager::get_shared_user_memory(), and foedus::Engine::get_soc_manager().

113  {
114  return engine_->get_soc_manager()->get_shared_user_memory();
115 }
void * get_shared_user_memory() const
Shortcut for get_shared_memory_repo()->get_global_user_memory()
Definition: soc_manager.cpp:40
soc::SocManager * get_soc_manager() const
See SOC and IPC.
Definition: engine.cpp:59

Here is the call graph for this function:

uint64_t foedus::memory::EngineMemory::get_shared_user_memory_size ( ) const
Returns
the byte size of shared user-controlled memory. Equivalent to SocOptions.shared_user_memory_size_kb_ << 10.
See also
get_shared_user_memory()

Definition at line 117 of file engine_memory.cpp.

References foedus::soc::SocManager::get_shared_user_memory_size(), and foedus::Engine::get_soc_manager().

117  {
118  return engine_->get_soc_manager()->get_shared_user_memory_size();
119 }
uint64_t get_shared_user_memory_size() const
Definition: soc_manager.cpp:43
soc::SocManager * get_soc_manager() const
See SOC and IPC.
Definition: engine.cpp:59

Here is the call graph for this function:

ErrorStack foedus::memory::EngineMemory::grab_one_volatile_page ( foedus::thread::ThreadGroupId  node,
storage::VolatilePagePointer pointer,
storage::Page **  page 
)

A convenience function to grab one free volatile page from the given node.

DO NOT USE THIS METHOD in a frequently invoked place. You should use the batched interface to avoid mutex each time. This method is used only where performance doesn't matter.

Definition at line 136 of file engine_memory.cpp.

References get_node_memory(), foedus::memory::PagePool::get_resolver(), foedus::memory::NumaNodeMemoryRef::get_volatile_pool(), foedus::memory::PagePool::grab_one(), foedus::kRetOk, foedus::memory::LocalPageResolver::resolve_offset_newpage(), foedus::storage::VolatilePagePointer::set(), and WRAP_ERROR_CODE.

Referenced by foedus::storage::array::ArrayStoragePimpl::load_empty(), and load_one_volatile_page().

139  {
140  PagePool* pool = get_node_memory(node)->get_volatile_pool();
141  PagePoolOffset offset;
142  WRAP_ERROR_CODE(pool->grab_one(&offset));
143  *page = pool->get_resolver().resolve_offset_newpage(offset);
144  pointer->set(node, offset);
145  return kRetOk;
146 }
uint32_t PagePoolOffset
Offset in PagePool that compactly represents the page address (unlike 8 bytes pointer).
Definition: memory_id.hpp:44
NumaNodeMemoryRef * get_node_memory(foedus::thread::ThreadGroupId group) const
const ErrorStack kRetOk
Normal return value for no-error case.
#define WRAP_ERROR_CODE(x)
Same as CHECK_ERROR(x) except it receives only an error code, thus more efficient.

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::memory::EngineMemory::initialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 43 of file engine_memory.cpp.

References ASSERT_ND, foedus::memory::LocalPageResolver::begin_, CHECK_ERROR, foedus::memory::LocalPageResolver::end_, ERROR_STACK, foedus::memory::PagePool::get_base(), foedus::Engine::get_debug(), foedus::Engine::get_options(), foedus::memory::PagePool::get_resolver(), foedus::Engine::get_soc_id(), foedus::memory::NumaNodeMemoryRef::get_volatile_pool(), foedus::thread::ThreadOptions::group_count_, foedus::DefaultInitializable::initialize(), foedus::DefaultInitializable::is_initialized(), foedus::Engine::is_master(), foedus::kErrorCodeDepedentModuleUnavailableInit, foedus::kRetOk, numa_available(), and foedus::EngineOptions::thread_.

43  {
44  LOG(INFO) << "Initializing EngineMemory..";
45  if (!engine_->get_debug()->is_initialized()) {
47  } else if (::numa_available() < 0) {
48  LOG(WARNING) << "WARNING, this machine is not a NUMA machine. FOEDUS still works fine,"
49  << " but it is mainly designed for large servers with many sockets and cores";
50  // Even if the kernel is built without NUMA (eg ARMv8), we keep running.
51  // return ERROR_STACK(kErrorCodeMemoryNumaUnavailable);
52  }
53 
54  ASSERT_ND(node_memories_.empty());
55  const EngineOptions& options = engine_->get_options();
56  const thread::ThreadGroupId numa_nodes = options.thread_.group_count_;
58  uint64_t pool_begin = 0, pool_end = 0;
59  for (thread::ThreadGroupId node = 0; node < numa_nodes; ++node) {
60  NumaNodeMemoryRef* ref = new NumaNodeMemoryRef(engine_, node);
61  node_memories_.push_back(ref);
62  bases[node] = ref->get_volatile_pool()->get_base();
63  pool_begin = ref->get_volatile_pool()->get_resolver().begin_;
64  pool_end = ref->get_volatile_pool()->get_resolver().end_;
65  }
66  global_volatile_page_resolver_ = GlobalVolatilePageResolver(
67  bases,
68  numa_nodes,
69  pool_begin,
70  pool_end);
71 
72  // Initialize local memory.
73  if (!engine_->is_master()) {
74  soc::SocId node = engine_->get_soc_id();
75  local_memory_ = new NumaNodeMemory(engine_, node);
76  CHECK_ERROR(local_memory_->initialize());
77  LOG(INFO) << "Node memory-" << node << " was initialized!";
78  } else {
79  if (options.memory_.rigorous_memory_boundary_check_) {
80  LOG(WARNING) << "CAUTION: memory_.rigorous_memory_boundary_check_ is ON. We will"
81  << " put mprotect-ed pages between memory regions for debugging. It will be SLOW!";
82  }
83  if (options.memory_.rigorous_page_boundary_check_) {
84  LOG(WARNING) << "CAUTION: memory_.rigorous_page_boundary_check_ is ON. We will"
85  << " put mprotect-ed pages between every single page for debugging. It will be SLOOOW!";
86  }
87  }
88  return kRetOk;
89 }
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
0x0005 : "GENERAL: A dependent module is not initialized yet. This implies a wrong initialization ord...
Definition: error_code.hpp:109
const EngineOptions & get_options() const
Definition: engine.cpp:39
bool is_master() const
Returns if this engine object is a master instance.
Definition: engine.cpp:68
int numa_available(void)
ErrorStack initialize() override final
Typical implementation of Initializable::initialize() that provides initialize-once semantics...
uint16_t SocId
Represents an ID of an SOC, or NUMA node.
Definition: soc_id.hpp:41
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
soc::SocId get_soc_id() const
If this is a child instance, returns its SOC ID (NUMA node).
Definition: engine.cpp:73
debugging::DebuggingSupports * get_debug() const
See Debug-Support functionalities.
Definition: engine.cpp:48
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38
bool is_initialized() const override final
Returns whether the object has been already initialized or not.

Here is the call graph for this function:

ErrorStack foedus::memory::EngineMemory::load_one_volatile_page ( cache::SnapshotFileSet fileset,
storage::SnapshotPagePointer  snapshot_pointer,
storage::VolatilePagePointer pointer,
storage::Page **  page 
)

Another convenience method that also reads an existing snapshot page to the volatile page.

Again, its performance is not optimized at all. Do not abuse. In fact, this is used only for one-time initialization code.

Definition at line 148 of file engine_memory.cpp.

References ASSERT_ND, CHECK_ERROR, foedus::storage::extract_numa_node_from_snapshot_pointer(), grab_one_volatile_page(), foedus::kRetOk, foedus::cache::SnapshotFileSet::read_page(), foedus::storage::VolatilePagePointer::word, and WRAP_ERROR_CODE.

Referenced by foedus::storage::array::ArrayStoragePimpl::load(), foedus::storage::masstree::MasstreeStoragePimpl::load(), and foedus::storage::hash::HashStoragePimpl::load().

152  {
153  ASSERT_ND(snapshot_pointer != 0);
155  CHECK_ERROR(grab_one_volatile_page(node, pointer, page));
156  WRAP_ERROR_CODE(fileset->read_page(snapshot_pointer, *page));
157  (*page)->get_header().snapshot_ = false;
158  (*page)->get_header().page_id_ = pointer->word;
159  return kRetOk;
160 }
ErrorStack grab_one_volatile_page(foedus::thread::ThreadGroupId node, storage::VolatilePagePointer *pointer, storage::Page **page)
A convenience function to grab one free volatile page from the given node.
uint8_t extract_numa_node_from_snapshot_pointer(SnapshotPagePointer pointer)
Definition: storage_id.hpp:95
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
const ErrorStack kRetOk
Normal return value for no-error case.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
#define WRAP_ERROR_CODE(x)
Same as CHECK_ERROR(x) except it receives only an error code, thus more efficient.
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::memory::EngineMemory::uninitialize_once ( )
overridevirtual

Implements foedus::DefaultInitializable.

Definition at line 91 of file engine_memory.cpp.

References foedus::ErrorStackBatch::emprace_back(), ERROR_STACK, foedus::Engine::get_debug(), foedus::Engine::get_soc_id(), foedus::DefaultInitializable::is_initialized(), foedus::Engine::is_master(), foedus::kErrorCodeDepedentModuleUnavailableUninit, SUMMARIZE_ERROR_BATCH, and foedus::DefaultInitializable::uninitialize().

91  {
92  LOG(INFO) << "Uninitializing EngineMemory..";
93  ErrorStackBatch batch;
94  if (!engine_->get_debug()->is_initialized()) {
96  }
97  for (auto* ref : node_memories_) {
98  delete ref;
99  }
100  node_memories_.clear();
101 
102  // Uninitialize local memory.
103  if (!engine_->is_master() && local_memory_) {
104  soc::SocId node = engine_->get_soc_id();
105  batch.emprace_back(local_memory_->uninitialize());
106  delete local_memory_;
107  local_memory_ = nullptr;
108  LOG(INFO) << "Node memory-" << node << " was uninitialized!";
109  }
110  return SUMMARIZE_ERROR_BATCH(batch);
111 }
#define ERROR_STACK(e)
Instantiates ErrorStack with the given foedus::error_code, creating an error stack with the current f...
ErrorStack uninitialize() override final
Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics...
bool is_master() const
Returns if this engine object is a master instance.
Definition: engine.cpp:68
#define SUMMARIZE_ERROR_BATCH(x)
This macro calls ErrorStackBatch::summarize() with automatically provided parameters.
uint16_t SocId
Represents an ID of an SOC, or NUMA node.
Definition: soc_id.hpp:41
soc::SocId get_soc_id() const
If this is a child instance, returns its SOC ID (NUMA node).
Definition: engine.cpp:73
debugging::DebuggingSupports * get_debug() const
See Debug-Support functionalities.
Definition: engine.cpp:48
0x0006 : "GENERAL: A dependent module is already uninitialized. This implies a wrong uninitialization...
Definition: error_code.hpp:110
bool is_initialized() const override final
Returns whether the object has been already initialized or not.

Here is the call graph for this function:


The documentation for this class was generated from the following files: