/** @brief Compute a hash for the given memory page
*
- * The page is used before inserting the page in the page store
- * in order to find duplicate of this page in the page store.
+ * The page is used before inserting the page in the page store in order to find duplicate of this page in the page
+ * store.
*
* @param data Memory page
* @return hash off the page
// ***** snapshot_page_manager
-PageStore::PageStore(std::size_t size) : memory_(nullptr), capacity_(size), top_index_(0)
+PageStore::PageStore(std::size_t size) : capacity_(size)
{
// Using mmap in order to be able to expand the region by relocating it somewhere else in the virtual memory space:
void* memory =
std::size_t PageStore::alloc_page()
{
if (this->free_pages_.empty()) {
-
// Expand the region:
if (this->top_index_ == this->capacity_)
// All the pages are allocated, we need add more pages:
// Use a page from the top:
return this->top_index_++;
-
} else {
-
// Use a page from free_pages_ (inside of the region):
size_t res = this->free_pages_[this->free_pages_.size() - 1];
this->free_pages_.pop_back();
for (size_t const& pageno : page_set) {
const void* snapshot_page = this->get_page(pageno);
if (memcmp(page, snapshot_page, xbt_pagesize) == 0) {
-
// If a page with the same content is already in the page store it's reused and its refcount is incremented.
page_counts_[pageno]++;
return pageno;
// Otherwise, a new page is allocated in the page store and the content of the page is `memcpy()`-ed to this new page.
std::size_t pageno = alloc_page();
xbt_assert(this->page_counts_[pageno] == 0, "Allocated page is already used");
- void* snapshot_page = (void*)this->get_page(pageno);
+ void* snapshot_page = this->get_page(pageno);
memcpy(snapshot_page, page, xbt_pagesize);
page_set.insert(pageno);
page_counts_[pageno]++;