libfoedus-core
FOEDUS Core Library
numa_node_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_NODE_MEMORY_HPP_
19 #define FOEDUS_MEMORY_NUMA_NODE_MEMORY_HPP_
20 
21 #include <string>
22 #include <vector>
23 
24 #include "foedus/cxx11.hpp"
25 #include "foedus/error_stack.hpp"
26 #include "foedus/fwd.hpp"
27 #include "foedus/initializable.hpp"
28 #include "foedus/cache/fwd.hpp"
29 #include "foedus/log/log_id.hpp"
31 #include "foedus/memory/fwd.hpp"
34 #include "foedus/xct/fwd.hpp"
35 
36 namespace foedus {
37 namespace memory {
49  public:
54 
55  foedus::thread::ThreadGroupId get_numa_node() const { return numa_node_; }
56 
57  PagePool* get_volatile_pool() { return &volatile_pool_; }
58  PagePool* get_snapshot_pool() { return &snapshot_pool_; }
59  cache::CacheHashtable* get_snapshot_cache_table() { return snapshot_cache_table_; }
60 
61  // accessors for child memories
63  ASSERT_ND(core_memories_.size() <= foedus::thread::kMaxThreadLocalOrdinal);
64  return static_cast<foedus::thread::ThreadLocalOrdinal>(core_memories_.size());
65  }
66  std::vector<NumaCoreMemory*>& get_core_memories() { return core_memories_; }
68  return core_memories_[foedus::thread::decompose_numa_local_ordinal(id)];
69  }
71  return core_memories_[ordinal];
72  }
73 
82  uint64_t size,
83  uint64_t alignment,
84  AlignedMemory *out) const;
85  ErrorStack allocate_numa_memory(uint64_t size, AlignedMemory *out) const {
86  return allocate_numa_memory_general(size, 1 << 12, out);
87  }
88  ErrorStack allocate_huge_numa_memory(uint64_t size, AlignedMemory *out) const {
90  }
91 
94  return volatile_offset_chunk_memory_pieces_[core_ordinal];
95  }
98  return snapshot_offset_chunk_memory_pieces_[core_ordinal];
99  }
101  return log_buffer_memory_pieces_[logger];
102  }
103 
105  std::string dump_free_memory_stat() const;
106 
107  private:
109  ErrorStack initialize_page_offset_chunk_memory();
111  ErrorStack initialize_log_buffers_memory();
113  ErrorStack initialize_core_memory(thread::ThreadLocalOrdinal ordinal);
114 
115  Engine* const engine_;
116 
120  const foedus::thread::ThreadGroupId numa_node_;
121 
123  const thread::ThreadLocalOrdinal cores_;
124 
126  const uint16_t loggers_;
127 
129  PagePool volatile_pool_;
131  PagePool snapshot_pool_;
132  AlignedMemory snapshot_pool_control_block_;
133  AlignedMemory snapshot_pool_memory_;
134 
136  cache::CacheHashtable* snapshot_cache_table_;
137 
142  std::vector<NumaCoreMemory*> core_memories_;
143 
147  AlignedMemory volatile_offset_chunk_memory_;
148  std::vector<PagePoolOffsetChunk*> volatile_offset_chunk_memory_pieces_;
149 
153  AlignedMemory snapshot_offset_chunk_memory_;
154  std::vector<PagePoolOffsetChunk*> snapshot_offset_chunk_memory_pieces_;
155 
159  AlignedMemory log_buffer_memory_;
160  std::vector<AlignedMemorySlice> log_buffer_memory_pieces_;
161 };
162 
168  public:
171 
172  Engine* get_engine() { return engine_; }
173  foedus::thread::ThreadGroupId get_numa_node() const { return numa_node_; }
174 
175  PagePool* get_volatile_pool() { return &volatile_pool_; }
176 
178  std::string dump_free_memory_stat() const;
179 
180  private:
181  Engine* const engine_;
182 
186  const foedus::thread::ThreadGroupId numa_node_;
187 
189  PagePool volatile_pool_;
190 };
191 
192 } // namespace memory
193 } // namespace foedus
194 #endif // FOEDUS_MEMORY_NUMA_NODE_MEMORY_HPP_
std::string dump_free_memory_stat() const
Report rough statistics of free memory.
const ThreadLocalOrdinal kMaxThreadLocalOrdinal
Maximum possible value of ThreadLocalOrdinal.
Definition: thread_id.hpp:69
ErrorStack allocate_numa_memory(uint64_t size, AlignedMemory *out) const
NumaCoreMemory * get_core_memory(foedus::thread::ThreadId id) const
uint8_t ThreadLocalOrdinal
Typedef for a local ID of Thread (core), which is NOT unique across NUMA nodes.
Definition: thread_id.hpp:58
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
Typedefs of ID types used in thread package.
Forward declarations of classes in transaction package.
ThreadLocalOrdinal decompose_numa_local_ordinal(ThreadId global_id)
Extracts local ordinal from the given globally unique ID of Thread (core).
Definition: thread_id.hpp:139
foedus::thread::ThreadLocalOrdinal get_core_memory_count() const
Forward declarations of classes in root package.
PagePoolOffsetChunk * get_volatile_offset_chunk_memory_piece(foedus::thread::ThreadLocalOrdinal core_ordinal)
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Typical implementation of Initializable as a skeleton base class.
std::string dump_free_memory_stat() const
Report rough statistics of free memory.
Typedefs of ID types used in log package.
ErrorStack initialize_once() override
Forward declarations of classes in cache package.
Repository of memories dynamically acquired within one CPU core (thread).
A view of NumaNodeMemory for other SOCs and master engine.
const uint64_t kHugepageSize
So far 2MB is the only page size available via Transparent Huge Page (THP).
Definition: memory_id.hpp:50
foedus::thread::ThreadGroupId get_numa_node() const
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
Definition: cxx11.hpp:131
std::vector< NumaCoreMemory * > & get_core_memories()
NumaCoreMemory * get_core_memory(foedus::thread::ThreadLocalOrdinal ordinal) const
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).
ErrorStack allocate_huge_numa_memory(uint64_t size, AlignedMemory *out) const
A NUMA-local hashtable of cached snapshot pages.
A slice of foedus::memory::AlignedMemory.
Forward declarations of classes in memory package.
foedus::thread::ThreadGroupId get_numa_node() const
#define CXX11_OVERRIDE
Used in public headers in place of "override" of C++11.
Definition: cxx11.hpp:134
cache::CacheHashtable * get_snapshot_cache_table()
#define CXX11_FUNC_DELETE
Used in public headers in place of " = delete" of C++11.
Definition: cxx11.hpp:128
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.
ErrorStack uninitialize_once() override
PagePoolOffsetChunk * get_snapshot_offset_chunk_memory_piece(foedus::thread::ThreadLocalOrdinal core_ordinal)
#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
uint16_t LoggerId
Typedef for an ID of Logger.
Definition: log_id.hpp:36
uint8_t ThreadGroupId
Typedef for an ID of ThreadGroup (NUMA node).
Definition: thread_id.hpp:38
ErrorStack allocate_numa_memory_general(uint64_t size, uint64_t alignment, AlignedMemory *out) const
Allocate a memory of the given size on this NUMA node.
AlignedMemorySlice get_log_buffer_memory_piece(log::LoggerId logger)