libfoedus-core
FOEDUS Core Library
numa_core_memory.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_MEMORY_NUMA_CORE_MEMORY_HPP_
19 #define FOEDUS_MEMORY_NUMA_CORE_MEMORY_HPP_
20 #include <stdint.h>
21 
22 #include "foedus/cxx11.hpp"
23 #include "foedus/epoch.hpp"
24 #include "foedus/error_stack.hpp"
25 #include "foedus/fwd.hpp"
26 #include "foedus/initializable.hpp"
28 #include "foedus/memory/fwd.hpp"
32 #include "foedus/xct/fwd.hpp"
33 
34 namespace foedus {
35 namespace memory {
47  public:
57  };
58 
60  NumaCoreMemory(Engine* engine, NumaNodeMemory *node_memory, thread::ThreadId core_id);
62  ErrorStack uninitialize_once() CXX11_OVERRIDE;
63 
64  AlignedMemorySlice get_log_buffer_memory() const { return log_buffer_memory_; }
65 
67  NumaNodeMemory* get_node_memory() const { return node_memory_; }
68 
87 
88  memory::PagePool* get_volatile_pool() { return volatile_pool_; }
89  memory::PagePool* get_snapshot_pool() { return snapshot_pool_; }
91 
93  return current_lock_list_memory_;
94  }
95  uint64_t get_current_lock_list_capacity() const {
96  return current_lock_list_capacity_;
97  }
99  return retrospective_lock_list_memory_;
100  }
102  return retrospective_lock_list_capacity_;
103  }
104 
106  return small_thread_local_memory_pieces_;
107  }
108 
109  void* get_local_work_memory() const { return local_work_memory_.get_block(); }
110  uint64_t get_local_work_memory_size() const { return local_work_memory_.get_size(); }
111 
113  static uint64_t calculate_local_small_memory_size(const EngineOptions& options);
114 
115  private:
117  static ErrorCode grab_free_pages_from_node(
118  PagePoolOffsetChunk* free_chunk,
119  memory::PagePool *pool);
121  static void release_free_pages_to_node(
122  PagePoolOffsetChunk* free_chunk,
123  memory::PagePool *pool);
124 
125  Engine* const engine_;
126 
130  NumaNodeMemory* const node_memory_;
131 
135  const foedus::thread::ThreadId core_id_;
139  const foedus::thread::ThreadGroupId numa_node_;
140 
144  const thread::ThreadLocalOrdinal core_local_ordinal_;
145 
163  memory::AlignedMemory small_thread_local_memory_;
164  SmallThreadLocalMemoryPieces small_thread_local_memory_pieces_;
165 
171  memory::AlignedMemory local_work_memory_;
172 
181  PagePoolOffsetChunk* free_volatile_pool_chunk_;
183  PagePoolOffsetChunk* free_snapshot_pool_chunk_;
184 
193  PagePoolOffsetAndEpochChunk* retired_volatile_pool_chunks_;
194 
196  xct::LockEntry* current_lock_list_memory_;
197  uint64_t current_lock_list_capacity_;
199  xct::LockEntry* retrospective_lock_list_memory_;
200  uint64_t retrospective_lock_list_capacity_;
201 
203  PagePool* volatile_pool_;
205  PagePool* snapshot_pool_;
206 
208  AlignedMemorySlice log_buffer_memory_;
209 };
210 
222  : memory_(memory), offset_(offset), released_(false) {}
224  if (!released_) {
226  released_ = true;
227  }
228  }
229  void set_released() {
230  released_ = true;
231  }
234  bool released_;
235 };
236 
237 } // namespace memory
238 } // namespace foedus
239 #endif // FOEDUS_MEMORY_NUMA_CORE_MEMORY_HPP_
ErrorStack uninitialize_once() override
ErrorStack initialize_once() override
void release_free_volatile_page(PagePoolOffset offset)
Returns one free volatile page to local page pool.
uint8_t ThreadLocalOrdinal
Typedef for a local ID of Thread (core), which is NOT unique across NUMA nodes.
Definition: thread_id.hpp:58
PagePoolOffset grab_free_volatile_page()
Acquires one free volatile page from local page pool.
Definitions of IDs in this package and a few related constant values.
Page pool for volatile read/write store (VolatilePage) and the read-only bufferpool (SnapshotPage)...
Definition: page_pool.hpp:173
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
uint32_t PagePoolOffset
Offset in PagePool that compactly represents the page address (unlike 8 bytes pointer).
Definition: memory_id.hpp:44
Typedefs of ID types used in thread package.
Forward declarations of classes in transaction package.
Represents a pointer to a volatile page with modification count for preventing ABA.
Definition: storage_id.hpp:194
Forward declarations of classes in root package.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
AutoVolatilePageReleaseScope(NumaCoreMemory *memory, PagePoolOffset offset)
An entry in CLL and RLL, representing a lock that is taken or will be taken.
uint64_t get_current_lock_list_capacity() const
Typical implementation of Initializable as a skeleton base class.
Definitions of IDs in this package and a few related constant values.
uint64_t get_local_work_memory_size() const
storage::VolatilePagePointer grab_free_volatile_page_pointer()
Wrapper for grab_free_volatile_page().
xct::LockEntry * get_retrospective_lock_list_memory() const
Repository of memories dynamically acquired within one CPU core (thread).
AlignedMemorySlice get_log_buffer_memory() const
const SmallThreadLocalMemoryPieces & get_small_thread_local_memory_pieces() const
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
Definition: cxx11.hpp:131
NumaNodeMemory * get_node_memory() const
Returns the parent memory repository.
void release_free_snapshot_page(PagePoolOffset offset)
Same, except it's for snapshot page.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
Repository of memories dynamically acquired and shared within one NUMA node (socket).
xct::LockEntry * get_current_lock_list_memory() const
Set of option values given to the engine at start-up.
A slice of foedus::memory::AlignedMemory.
memory::PagePool * get_volatile_pool()
void * get_block() const
Returns the memory block.
Packs pointers to pieces of small_thread_local_memory_.
Forward declarations of classes in memory package.
uint64_t get_size() const
Returns the byte size of the memory block.
PagePoolOffsetAndEpochChunk * get_retired_volatile_pool_chunk(uint16_t node)
#define CXX11_OVERRIDE
Used in public headers in place of "override" of C++11.
Definition: cxx11.hpp:134
PagePoolOffset grab_free_snapshot_page()
Same, except it's for snapshot page.
#define CXX11_FUNC_DELETE
Used in public headers in place of " = delete" of C++11.
Definition: cxx11.hpp:128
static uint64_t calculate_local_small_memory_size(const EngineOptions &options)
To reduce the overhead of grabbing/releasing pages from pool, we pack this many pointers for each gra...
Definition: page_pool.hpp:47
uint16_t ThreadId
Typedef for a global ID of Thread (core), which is unique across NUMA nodes.
Definition: thread_id.hpp:80
Represents one memory block aligned to actual OS/hardware pages.
memory::PagePool * get_snapshot_pool()
Used to store an epoch value with each entry in PagePoolOffsetChunk.
Definition: page_pool.hpp:108
uint64_t get_retrospective_lock_list_capacity() const
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
Automatically invokes a page offset acquired for volatile page.