libfoedus-core
FOEDUS Core Library
page_resolver.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_RESOLVER_HPP_
19 #define FOEDUS_MEMORY_PAGE_RESOLVER_HPP_
20 #include <cstring>
21 
22 #include "foedus/assert_nd.hpp"
23 #include "foedus/compiler.hpp"
24 #include "foedus/cxx11.hpp"
25 #include "foedus/storage/page.hpp"
28 
29 namespace foedus {
30 namespace memory {
45  : begin_(begin), end_(end), base_(base) {}
46 
47  // default assignment/copy-constructor is enough
48 
51  PagePoolOffset offset = page - base_;
52  ASSERT_ND(offset >= begin_);
53  ASSERT_ND(offset < end_);
54  return offset;
55  }
58  storage::Page* page = resolve_offset_newpage(offset);
59  // this is NOT a new page, so we have sanity checks
61  return page;
62  }
65  ASSERT_ND(offset >= begin_);
66  ASSERT_ND(offset < end_);
67  return base_ + offset;
68  }
69 
76 };
77 
93  typedef storage::Page* Base;
94  enum Constants {
95  kMaxNumaNode = 256,
96  };
98  GlobalVolatilePageResolver(const Base *bases, uint16_t numa_node_count,
99  PagePoolOffset begin, PagePoolOffset end)
100  : numa_node_count_(numa_node_count), begin_(begin), end_(end) {
101  ASSERT_ND(numa_node_count <= kMaxNumaNode);
102  std::memcpy(bases_, bases, sizeof(Base) * numa_node_count_);
103  }
104  // default assignment/copy constructors are a bit wasteful when #numa node is small, thus:
106  operator=(other);
107  }
109  ASSERT_ND(other.numa_node_count_ > 0);
111  ASSERT_ND(other.end_ > other.begin_);
113  begin_ = other.begin_;
114  end_ = other.end_;
115  std::memcpy(bases_, other.bases_, sizeof(Base) * numa_node_count_);
116  return *this;
117  }
118 
120  storage::Page* resolve_offset(uint8_t numa_node, PagePoolOffset offset) const ALWAYS_INLINE {
121  storage::Page* page = resolve_offset_newpage(numa_node, offset);
122  // this is NOT a new page, so we have sanity checks
125  == numa_node);
126  return page;
127  }
130  return resolve_offset(page_pointer.get_numa_node(), page_pointer.get_offset());
131  }
132 
135  uint8_t numa_node,
136  PagePoolOffset offset) const ALWAYS_INLINE {
137  ASSERT_ND(numa_node < numa_node_count_);
138  ASSERT_ND(offset >= begin_);
139  ASSERT_ND(offset < end_);
140  storage::assert_aligned_page(bases_[numa_node] + offset);
141  return bases_[numa_node] + offset;
142  }
145  storage::VolatilePagePointer page_pointer) const ALWAYS_INLINE {
146  return resolve_offset_newpage(
147  page_pointer.get_numa_node(),
148  page_pointer.get_offset());
149  }
150 
157 
160 };
161 
162 } // namespace memory
163 } // namespace foedus
164 #endif // FOEDUS_MEMORY_PAGE_RESOLVER_HPP_
void assert_aligned_page(const void *page)
Definition: page.hpp:402
storage::Page * resolve_offset(uint8_t numa_node, PagePoolOffset offset) const __attribute__((always_inline))
Resolves offset plus NUMA node ID to storage::Page*.
Definitions of IDs in this package and a few related constant values.
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
GlobalVolatilePageResolver & operator=(const GlobalVolatilePageResolver &other)
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.
uint16_t numa_node_count_
number of NUMA nodes in this engine.
Represents a pointer to a volatile page with modification count for preventing ABA.
Definition: storage_id.hpp:194
storage::Page * resolve_offset_newpage(PagePoolOffset offset) const __attribute__((always_inline))
As the name suggests, this version is for new pages, which don't have sanity checks.
PagePoolOffset begin_
where a valid page entry starts.
PagePoolOffset end_
where a valid page entry ends.
PagePoolOffset end_
where a valid page entry ends.
storage::Page * resolve_offset(storage::VolatilePagePointer page_pointer) const __attribute__((always_inline))
Resolves volatile page ID to storage::Page*.
PagePoolOffset resolve_page(storage::Page *page) const __attribute__((always_inline))
Resolves storage::Page* to offset in this pool.
void assert_valid_volatile_page(const Page *page, uint32_t offset)
Definition: page.hpp:407
storage::Page * resolve_offset_newpage(storage::VolatilePagePointer page_pointer) const __attribute__((always_inline))
As the name suggests, this version is for new pages, which don't have sanity checks.
#define CXX11_FINAL
Used in public headers in place of "final" of C++11.
Definition: cxx11.hpp:131
Just a marker to denote that the memory region represents a data page.
Definition: page.hpp:334
GlobalVolatilePageResolver(const GlobalVolatilePageResolver &other)
storage::Page * resolve_offset(PagePoolOffset offset) const __attribute__((always_inline))
Resolves offset in this pool to storage::Page*.
GlobalVolatilePageResolver(const Base *bases, uint16_t numa_node_count, PagePoolOffset begin, PagePoolOffset end)
storage::Page * resolve_offset_newpage(uint8_t numa_node, PagePoolOffset offset) const __attribute__((always_inline))
As the name suggests, this version is for new pages, which don't have sanity checks.
VolatilePagePointer construct_volatile_page_pointer(uint64_t word)
Definition: storage_id.hpp:230
Resolves an offset in local (same NUMA node) page pool to a pointer and vice versa.
Resolves an offset in a volatile page pool to an actual pointer and vice versa.
PageHeader & get_header()
At least the basic header exists in all pages.
Definition: page.hpp:336
PagePoolOffset begin_
where a valid page entry starts.
#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 ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
Definition: compiler.hpp:106
storage::Page * base_
base address to calculate from/to offset.
Base bases_[kMaxNumaNode]
base address to calculate from/to offset.
uint64_t page_id_
Page ID of this page.
Definition: page.hpp:191
LocalPageResolver(storage::Page *base, PagePoolOffset begin, PagePoolOffset end)