X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/64a1599658f6c313f789471fc829a574fa32bd70..9b00b25919fb4fe7311031c78a13e7ae2055df70:/src/mc/RegionSnapshot.cpp diff --git a/src/mc/RegionSnapshot.cpp b/src/mc/RegionSnapshot.cpp index 634aadc85b..bfcc7ba35a 100644 --- a/src/mc/RegionSnapshot.cpp +++ b/src/mc/RegionSnapshot.cpp @@ -4,11 +4,15 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include + #include #include "mc/mc.h" -#include "mc_snapshot.h" -#include "RegionSnapshot.hpp" +#include "src/mc/mc_snapshot.h" + +#include "src/mc/ChunkedData.hpp" +#include "src/mc/RegionSnapshot.hpp" extern "C" { @@ -35,33 +39,72 @@ const char* to_cstr(RegionType region) } } -void data_deleter::operator()(void* p) const +Buffer::Buffer(std::size_t size, Type type) : size_(size), type_(type) { switch(type_) { - case Free: - free(p); + case Type::Malloc: + data_ = ::malloc(size_); break; - case Munmap: - munmap(p, size_); + case Type::Mmap: + data_ = ::mmap(nullptr, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_POPULATE, -1, 0); + if (data_ == MAP_FAILED) { + data_ = nullptr; + size_ = 0; + type_ = Type::Malloc; + throw std::bad_alloc(); + } break; + default: + abort(); } } +void Buffer::clear() noexcept +{ + switch(type_) { + case Type::Malloc: + std::free(data_); + break; + case Type::Mmap: + if (munmap(data_, size_) != 0) + abort(); + break; + default: + abort(); + } + data_ = nullptr; + size_ = 0; + type_ = Type::Malloc; +} + RegionSnapshot dense_region( RegionType region_type, void *start_addr, void* permanent_addr, size_t size) { - simgrid::mc::RegionSnapshot::flat_data_ptr data((char*) malloc(size)); + // When KSM support is enables, we allocate memory using mmap: + // * we don't want to madvise bits of the heap; + // * mmap gives data aligned on page boundaries which is merge friendly. + simgrid::mc::Buffer data; + if (_sg_mc_ksm) + data = Buffer::mmap(size); + else + data = Buffer::malloc(size); + mc_model_checker->process().read_bytes(data.get(), size, remote(permanent_addr), simgrid::mc::ProcessIndexDisabled); + if (_sg_mc_ksm) + // Mark the region as mergeable *after* we have written into it. + // Trying to merge them before is useless/counterproductive. + madvise(data.get(), size, MADV_MERGEABLE); + simgrid::mc::RegionSnapshot region( region_type, start_addr, permanent_addr, size); region.flat_data(std::move(data)); XBT_DEBUG("New region : type : %s, data : %p (real addr %p), size : %zu", - to_cstr(region_type), region.flat_data(), permanent_addr, size); + to_cstr(region_type), region.flat_data().get(), permanent_addr, size); return std::move(region); } @@ -73,19 +116,26 @@ RegionSnapshot dense_region( * @param size Size of the data* */ RegionSnapshot region( - RegionType type, void *start_addr, void* permanent_addr, size_t size) + RegionType type, void *start_addr, void* permanent_addr, size_t size, + RegionSnapshot const* ref_region) { if (_sg_mc_sparse_checkpoint) { - return sparse_region(type, start_addr, permanent_addr, size); + return sparse_region(type, start_addr, permanent_addr, size, ref_region); } else { return dense_region(type, start_addr, permanent_addr, size); } } RegionSnapshot sparse_region(RegionType region_type, - void *start_addr, void* permanent_addr, size_t size) + void *start_addr, void* permanent_addr, size_t size, + RegionSnapshot const* ref_region) { simgrid::mc::Process* process = &mc_model_checker->process(); + assert(process != nullptr); + + bool use_soft_dirty = _sg_mc_sparse_checkpoint && _sg_mc_soft_dirty + && ref_region != nullptr + && ref_region->storage_type() == simgrid::mc::StorageType::Chunked; xbt_assert((((uintptr_t)start_addr) & (xbt_pagesize-1)) == 0, "Not at the beginning of a page"); @@ -93,8 +143,19 @@ RegionSnapshot sparse_region(RegionType region_type, "Not at the beginning of a page"); size_t page_count = mc_page_count(size); - simgrid::mc::PerPageCopy page_data(mc_model_checker->page_store(), *process, - permanent_addr, page_count); + std::vector pagemap; + const size_t* ref_page_numbers = nullptr; + if (use_soft_dirty) { + pagemap.resize(page_count); + process->read_pagemap(pagemap.data(), + mc_page_number(nullptr, permanent_addr), page_count); + ref_page_numbers = ref_region->page_data().pagenos(); + } + + simgrid::mc::ChunkedData page_data( + mc_model_checker->page_store(), *process, permanent_addr, page_count, + ref_page_numbers, + use_soft_dirty ? pagemap.data() : nullptr); simgrid::mc::RegionSnapshot region( region_type, start_addr, permanent_addr, size);