libfoedus-core
FOEDUS Core Library
page_pool_pimpl.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_PAGE_POOL_PIMPL_HPP_
19 #define FOEDUS_MEMORY_PAGE_POOL_PIMPL_HPP_
20 
21 #include <stdint.h>
22 
23 #include <iosfwd>
24 #include <string>
25 
26 #include "foedus/assert_nd.hpp"
27 #include "foedus/fwd.hpp"
28 #include "foedus/initializable.hpp"
36 
37 namespace foedus {
38 namespace memory {
41  // this is backed by shared memory. not instantiation. just reinterpret_cast.
42  PagePoolControlBlock() = delete;
43  ~PagePoolControlBlock() = delete;
44 
45  void initialize() {
46  lock_.initialize();
47  }
48  void uninitialize() {
50  }
51 
53  uint64_t free_pool_head_;
55  uint64_t free_pool_count_;
56 
59 
65 };
66 
74 class PagePoolPimpl final : public DefaultInitializable {
75  public:
76  PagePoolPimpl();
77  void attach(
78  PagePoolControlBlock* control_block,
79  void* memory,
80  uint64_t memory_size,
81  bool owns,
82  bool rigorous_page_boundary_check);
83  ErrorStack initialize_once() override;
84  ErrorStack uninitialize_once() override;
85 
86  ErrorCode grab(uint32_t desired_grab_count, PagePoolOffsetChunk *chunk);
87 
88  template <typename CHUNK>
89  void release_impl(uint32_t desired_release_count, CHUNK* chunk);
90  void release(uint32_t desired_release_count, PagePoolOffsetChunk *chunk);
91  void release(uint32_t desired_release_count, PagePoolOffsetDynamicChunk* chunk);
92  void release(uint32_t desired_release_count, PagePoolOffsetAndEpochChunk* chunk);
93 
95  void release_one(PagePoolOffset offset);
96  const LocalPageResolver& get_resolver() const { return resolver_; }
97  PagePool::Stat get_stat() const;
99  uint64_t free_pool_head() const { return control_block_->free_pool_head_;}
100  uint64_t get_free_pool_capacity() const { return free_pool_capacity_; }
103  void decrease_free_pool_count(uint64_t op) {
106  }
108  void assert_free_pool() const {
109 #ifndef NDEBUG
110  const uint64_t free_count = get_free_pool_count();
111  const uint64_t free_head = free_pool_head();
112  for (uint64_t i = 0; i < free_count; ++i) {
113  uint64_t index = free_head + i;
114  while (index >= free_pool_capacity_) {
115  index -= free_pool_capacity_;
116  }
117  PagePoolOffset* address = free_pool_ + index;
118  ASSERT_ND(*address >= pages_for_free_pool_);
119  ASSERT_ND(*address < pool_size_);
120  }
121 #endif // NDEBUG
122  }
123 
124  std::string get_debug_pool_name() const {
125  if (control_block_) {
128  } else {
129  return "Unnamed";
130  }
131  } else {
132  return "Not-attached";
133  }
134  }
135  void set_debug_pool_name(const std::string& name) {
136  if (control_block_) {
138  }
139  }
140 
141  friend std::ostream& operator<<(std::ostream& o, const PagePoolPimpl& v);
142 
144 
146  void* memory_;
147 
149  uint64_t memory_size_;
150 
152  bool owns_;
153 
156 
162 
165 
167  uint64_t pool_size_;
168 
176 
184 };
185 static_assert(
187  "PagePoolControlBlock is too large.");
188 } // namespace memory
189 } // namespace foedus
190 #endif // FOEDUS_MEMORY_PAGE_POOL_PIMPL_HPP_
void attach(PagePoolControlBlock *control_block, void *memory, uint64_t memory_size, bool owns, bool rigorous_page_boundary_check)
void increase_free_pool_count(uint64_t op)
std::string get_debug_pool_name() const
bool rigorous_page_boundary_check_
Whether to use mprotect() for page boundaries to detect bogus memory accesses.
void * memory_
The whole memory region of the pool.
uint64_t get_free_pool_count() const
void initialize(bool recursive=false)
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.
void set_debug_pool_name(const std::string &name)
Forward declarations of classes in root package.
friend std::ostream & operator<<(std::ostream &o, const PagePoolPimpl &v)
storage::Page * pool_base_
Just an auxiliary variable to the beginning of the pool.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
uint64_t free_pool_capacity_
Size of free_pool_.
Typical implementation of Initializable as a skeleton base class.
void release_one(PagePoolOffset offset)
soc::SharedMutex lock_
grab()/release() are protected with this lock.
PagePoolControlBlock * control_block_
ErrorCode grab(uint32_t desired_grab_count, PagePoolOffsetChunk *chunk)
A mutex that can be placed in shared memory and used from multiple processes.
uint64_t pool_size_
Just an auxiliary variable of the size of pool.
PagePool::Stat get_stat() const
void release_impl(uint32_t desired_release_count, CHUNK *chunk)
void assign(const FixedString< MAXLEN2, CHAR > &other) noexcept
Assign operator for all FixedString objects.
ErrorStack initialize_once() override
void decrease_free_pool_count(uint64_t op)
void assert_free_pool() const
Not thread safe.
Pimpl object of PagePool.
bool empty() const noexcept
Test if string is empty.
void release(uint32_t desired_release_count, PagePoolOffsetChunk *chunk)
ErrorStack uninitialize_once() override
std::basic_string< CHAR > str() const
Convert to a std::string object.
Just a marker to denote that the memory region represents a data page.
Definition: page.hpp:334
uint64_t free_pool_head_
Inclusive head of the circular queue.
ErrorCode grab_one(PagePoolOffset *offset)
bool owns_
Whether this engine owns this page pool.
LocalPageResolver resolver_
An object to resolve an offset in this page pool (thus local) to an actual pointer and vice versa...
Used to point to an already existing array.
Definition: page_pool.hpp:81
uint64_t free_pool_count_
Number of free pages.
Shared data in PagePoolPimpl.
assorted::FixedString< 60 > debug_pool_name_
just for debugging/logging.
const LocalPageResolver & get_resolver() const
To reduce the overhead of grabbing/releasing pages from pool, we pack this many pointers for each gra...
Definition: page_pool.hpp:47
uint64_t pages_for_free_pool_
This many first pages are used for free page maintainance.
Resolves an offset in local (same NUMA node) page pool to a pointer and vice versa.
Used to store an epoch value with each entry in PagePoolOffsetChunk.
Definition: page_pool.hpp:108
#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
uint64_t get_free_pool_capacity() const
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
uint64_t memory_size_
Byte size of this page pool.
PagePoolOffset * free_pool_
We maintain free pages as a simple circular queue.