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

Page pool for volatile read/write store (VolatilePage) and the read-only bufferpool (SnapshotPage). More...

Detailed Description

Page pool for volatile read/write store (VolatilePage) and the read-only bufferpool (SnapshotPage).

The engine maintains a few instances of this class; one for each NUMA node. Each page pool provides in-memory pages for both volatile pages and snapshot pages.

Definition at line 173 of file page_pool.hpp.

#include <page_pool.hpp>

Inheritance diagram for foedus::memory::PagePool:
Collaboration diagram for foedus::memory::PagePool:

Classes

struct  Stat
 

Public Member Functions

 PagePool ()
 
 ~PagePool ()
 
void attach (PagePoolControlBlock *control_block, void *memory, uint64_t memory_size, bool owns, bool rigorous_page_boundary_check)
 
 PagePool (const PagePool &)=delete
 
PagePooloperator= (const PagePool &)=delete
 
ErrorStack initialize () override
 Acquires resources in this object, usually called right after constructor. More...
 
bool is_initialized () const override
 Returns whether the object has been already initialized or not. More...
 
ErrorStack uninitialize () override
 An idempotent method to release all resources of this object, if any. More...
 
storage::Pageget_base () const
 
uint64_t get_free_pool_capacity () const
 
uint64_t get_memory_size () const
 
uint32_t get_recommended_pages_per_grab () const
 
Stat get_stat () const
 
std::string get_debug_pool_name () const
 
void set_debug_pool_name (const std::string &name)
 Call this anytime after attach() More...
 
ErrorCode grab (uint32_t desired_grab_count, PagePoolOffsetChunk *chunk)
 Adds the specified number of free pages to the chunk. More...
 
ErrorCode grab_one (PagePoolOffset *offset)
 Grab only one page. More...
 
void release (uint32_t desired_release_count, PagePoolOffsetChunk *chunk)
 Returns the specified number of free pages from the chunk. More...
 
void release (uint32_t desired_release_count, PagePoolOffsetDynamicChunk *chunk)
 
void release (uint32_t desired_release_count, PagePoolOffsetAndEpochChunk *chunk)
 Overload for PagePoolOffsetAndEpochChunk. More...
 
void release_one (PagePoolOffset offset)
 Returns only one page. More...
 
const LocalPageResolverget_resolver () const
 Gives an object to resolve an offset in this page pool (thus local) to an actual pointer and vice versa. More...
 
- Public Member Functions inherited from foedus::Initializable
virtual ~Initializable ()
 

Friends

std::ostream & operator<< (std::ostream &o, const PagePool &v)
 

Constructor & Destructor Documentation

foedus::memory::PagePool::PagePool ( )

Definition at line 98 of file page_pool.cpp.

98  {
99  pimpl_ = new PagePoolPimpl();
100 }
foedus::memory::PagePool::~PagePool ( )

Definition at line 109 of file page_pool.cpp.

109  {
110  delete pimpl_;
111  pimpl_ = nullptr;
112 }
foedus::memory::PagePool::PagePool ( const PagePool )
delete

Member Function Documentation

void foedus::memory::PagePool::attach ( PagePoolControlBlock control_block,
void *  memory,
uint64_t  memory_size,
bool  owns,
bool  rigorous_page_boundary_check 
)

Definition at line 101 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::attach().

Referenced by foedus::memory::NumaNodeMemory::initialize_once(), and foedus::memory::NumaNodeMemoryRef::NumaNodeMemoryRef().

106  {
107  pimpl_->attach(control_block, memory, memory_size, owns, rigorous_page_boundary_check);
108 }
void attach(PagePoolControlBlock *control_block, void *memory, uint64_t memory_size, bool owns, bool rigorous_page_boundary_check)

Here is the call graph for this function:

Here is the caller graph for this function:

storage::Page * foedus::memory::PagePool::get_base ( ) const

Definition at line 119 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::pool_base_.

Referenced by foedus::thread::ThreadPimpl::find_or_read_a_snapshot_page(), foedus::thread::ThreadPimpl::find_or_read_snapshot_pages_batch(), foedus::memory::EngineMemory::initialize_once(), and foedus::thread::ThreadPimpl::on_snapshot_cache_miss().

119 { return pimpl_->pool_base_; }
storage::Page * pool_base_
Just an auxiliary variable to the beginning of the pool.

Here is the caller graph for this function:

std::string foedus::memory::PagePool::get_debug_pool_name ( ) const

Definition at line 121 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::get_debug_pool_name().

121 { return pimpl_->get_debug_pool_name(); }
std::string get_debug_pool_name() const

Here is the call graph for this function:

uint64_t foedus::memory::PagePool::get_free_pool_capacity ( ) const
Returns
Number of all addressible data pages in this pool.

Definition at line 120 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::get_free_pool_capacity().

Referenced by foedus::memory::NumaCoreMemory::initialize_once().

120 { return pimpl_->get_free_pool_capacity(); }
uint64_t get_free_pool_capacity() const

Here is the call graph for this function:

Here is the caller graph for this function:

uint64_t foedus::memory::PagePool::get_memory_size ( ) const

Definition at line 117 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::memory_size_.

Referenced by foedus::memory::NumaNodeMemory::initialize_once().

117 { return pimpl_->memory_size_; }
uint64_t memory_size_
Byte size of this page pool.

Here is the caller graph for this function:

uint32_t foedus::memory::PagePool::get_recommended_pages_per_grab ( ) const
Returns
recommended number of pages to grab at once.

Especially in testcases, grabbing chunk-full of pages (4k pages) at a time immediately runs out of free pages unless we allocate huge pools for each run, which would make test-time significantly longer. For example, if the pool has only 1024 pages, it doesn't make sense to grab 2000 pages at a time! As soon as one thread does it, all other threads will get out-of-memory error although the culprit probably needs only a few pages. To avoid that, we respect this value in most places.

Definition at line 124 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::free_pool_capacity_.

Referenced by foedus::memory::RoundRobinPageGrabBatch::grab(), foedus::memory::DivvyupPageGrabBatch::grab(), and foedus::memory::NumaCoreMemory::initialize_once().

124  {
125  return std::min<uint32_t>(1U << 12, pimpl_->free_pool_capacity_ / 8U);
126 }
uint64_t free_pool_capacity_
Size of free_pool_.

Here is the caller graph for this function:

PagePool::Stat foedus::memory::PagePool::get_stat ( ) const
ErrorCode foedus::memory::PagePool::grab ( uint32_t  desired_grab_count,
PagePoolOffsetChunk chunk 
)

Adds the specified number of free pages to the chunk.

Parameters
[in]desired_grab_countwe grab this number of free pages at most
[in,out]chunkwe append the grabbed free pages to this chunk
Precondition
chunk->size() + desired_grab_count <= chunk->capacity()
Returns
only OUTOFMEMORY is possible

Callers usually maintain one PagePoolOffsetChunk for its private use and calls this method when the size() goes below some threshold (eg 10%) so as to get size() about 50%.

Definition at line 129 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::grab().

Referenced by foedus::memory::RoundRobinPageGrabBatch::grab(), foedus::memory::DivvyupPageGrabBatch::grab(), and foedus::memory::NumaCoreMemory::initialize_once().

129  {
130  return pimpl_->grab(desired_grab_count, chunk);
131 }
ErrorCode grab(uint32_t desired_grab_count, PagePoolOffsetChunk *chunk)

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorCode foedus::memory::PagePool::grab_one ( PagePoolOffset offset)

Grab only one page.

More expensive, but handy in some situation.

Definition at line 132 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::grab_one().

Referenced by foedus::storage::hash::HashStoragePimpl::create(), foedus::memory::EngineMemory::grab_one_volatile_page(), foedus::storage::sequential::SequentialStoragePimpl::initialize_head_tail_pages(), and foedus::storage::masstree::MasstreeStoragePimpl::load_empty().

132 { return pimpl_->grab_one(offset); }
ErrorCode grab_one(PagePoolOffset *offset)

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::memory::PagePool::initialize ( )
overridevirtual

Acquires resources in this object, usually called right after constructor.

Precondition
is_initialized() == FALSE

If and only if the return value was not an error, is_initialized() will return TRUE. This method is usually not idempotent, but some implementation can choose to be. In that case, the implementation class should clarify that it's idempotent. This method is responsible for releasing all acquired resources when initialization fails. This method itself is NOT thread-safe. Do not call this in a racy situation.

Implements foedus::Initializable.

Definition at line 114 of file page_pool.cpp.

References foedus::DefaultInitializable::initialize().

Referenced by foedus::memory::NumaNodeMemory::initialize_once().

114 { return pimpl_->initialize(); }
ErrorStack initialize() override final
Typical implementation of Initializable::initialize() that provides initialize-once semantics...

Here is the call graph for this function:

Here is the caller graph for this function:

bool foedus::memory::PagePool::is_initialized ( ) const
overridevirtual

Returns whether the object has been already initialized or not.

Implements foedus::Initializable.

Definition at line 115 of file page_pool.cpp.

References foedus::DefaultInitializable::is_initialized().

Referenced by foedus::memory::NumaNodeMemory::initialize_once().

115 { return pimpl_->is_initialized(); }
bool is_initialized() const override final
Returns whether the object has been already initialized or not.

Here is the call graph for this function:

Here is the caller graph for this function:

PagePool& foedus::memory::PagePool::operator= ( const PagePool )
delete
void foedus::memory::PagePool::release ( uint32_t  desired_release_count,
PagePoolOffsetChunk chunk 
)

Returns the specified number of free pages from the chunk.

Parameters
[in]desired_release_countwe release this number of free pages
[in,out]chunkwe release free pages from the tail of this chunk
Precondition
chunk->size() - desired_release_count >= 0

Callers usually maintain one PagePoolOffsetChunk for its private use and calls this method when the size() goes above some threshold (eg 90%) so as to get size() about 50%.

Definition at line 134 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::release().

Referenced by foedus::storage::sequential::SequentialStoragePimpl::drop(), foedus::storage::Composer::DropVolatilesArguments::drop(), foedus::snapshot::SnapshotManagerPimpl::drop_volatile_pages_parallel(), foedus::thread::ThreadPimpl::flush_retired_volatile_page(), foedus::cache::CacheManagerPimpl::handle_cleaner(), foedus::memory::RoundRobinPageGrabBatch::release_all(), foedus::memory::DivvyupPageGrabBatch::release_all(), foedus::memory::PageReleaseBatch::release_chunk(), foedus::memory::NumaCoreMemory::uninitialize_once(), and foedus::thread::ThreadPimpl::uninitialize_once().

134  {
135  pimpl_->release(desired_release_count, chunk);
136 }
void release(uint32_t desired_release_count, PagePoolOffsetChunk *chunk)

Here is the call graph for this function:

Here is the caller graph for this function:

void foedus::memory::PagePool::release ( uint32_t  desired_release_count,
PagePoolOffsetDynamicChunk chunk 
)

Definition at line 137 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::release().

137  {
138  pimpl_->release(desired_release_count, chunk);
139 }
void release(uint32_t desired_release_count, PagePoolOffsetChunk *chunk)

Here is the call graph for this function:

void foedus::memory::PagePool::release ( uint32_t  desired_release_count,
PagePoolOffsetAndEpochChunk chunk 
)

Overload for PagePoolOffsetAndEpochChunk.

Definition at line 140 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::release().

140  {
141  pimpl_->release(desired_release_count, chunk);
142 }
void release(uint32_t desired_release_count, PagePoolOffsetChunk *chunk)

Here is the call graph for this function:

void foedus::memory::PagePool::release_one ( PagePoolOffset  offset)

Returns only one page.

More expensive, but handy in some situation.

Definition at line 144 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::release_one().

Referenced by foedus::storage::sequential::SequentialStoragePimpl::drop(), foedus::storage::hash::HashIntermediatePage::release_pages_recursive_parallel(), and foedus::storage::masstree::MasstreeIntermediatePage::release_pages_recursive_parallel().

144 { pimpl_->release_one(offset); }
void release_one(PagePoolOffset offset)

Here is the call graph for this function:

Here is the caller graph for this function:

void foedus::memory::PagePool::set_debug_pool_name ( const std::string &  name)

Call this anytime after attach()

Definition at line 122 of file page_pool.cpp.

References foedus::memory::PagePoolPimpl::set_debug_pool_name().

Referenced by foedus::memory::NumaNodeMemory::initialize_once().

122 { pimpl_->set_debug_pool_name(name); }
void set_debug_pool_name(const std::string &name)

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::memory::PagePool::uninitialize ( )
overridevirtual

An idempotent method to release all resources of this object, if any.

After this method, is_initialized() will return FALSE. Whether this method encounters an error or not, the implementation should make the best effort to release as many resources as possible. In other words, Do not leak all resources because of one issue. This method itself is NOT thread-safe. Do not call this in a racy situation.

Attention
This method is NOT automatically called from the destructor. This is due to the fundamental limitation in C++. Explicitly call this method as soon as you are done, checking the returned value. You can also use UninitializeGuard to ameliorate the issue, but it's not perfect.
Returns
The error this method encounters, if any. In case there are multiple errors while uninitialization, the implementation should use ErrorStackBatch to produce a batched ErrorStack object.

Implements foedus::Initializable.

Definition at line 116 of file page_pool.cpp.

References foedus::DefaultInitializable::uninitialize().

Referenced by foedus::memory::NumaNodeMemory::uninitialize_once().

116 { return pimpl_->uninitialize(); }
ErrorStack uninitialize() override final
Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics...

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const PagePool v 
)
friend

Definition at line 148 of file page_pool.cpp.

148  {
149  o << v.pimpl_;
150  return o;
151 }

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