1 #include <mc/ChunkedData.hpp>
3 #define SOFT_DIRTY_BIT_NUMBER 55
4 #define SOFT_DIRTY (((uint64_t)1) << SOFT_DIRTY_BIT_NUMBER)
9 /** Take a per-page snapshot of a region
11 * @param data The start of the region (must be at the beginning of a page)
12 * @param pag_count Number of pages of the region
13 * @return Snapshot page numbers of this new snapshot
15 ChunkedData::ChunkedData(PageStore& store, AddressSpace& as,
16 remote_ptr<void> addr, std::size_t page_count,
17 const std::size_t* ref_page_numbers, const std::uint64_t* pagemap)
20 this->pagenos_.resize(page_count);
21 std::vector<char> buffer(xbt_pagesize);
23 for (size_t i = 0; i != page_count; ++i) {
25 // We don't have to compare soft-clean pages:
26 if (ref_page_numbers && pagemap && !(pagemap[i] & SOFT_DIRTY)) {
27 pagenos_[i] = ref_page_numbers[i];
28 store_->ref_page(ref_page_numbers[i]);
32 remote_ptr<void> page = remote(addr.address() + (i << xbt_pagebits));
33 xbt_assert(mc_page_offset((void*)page.address())==0,
34 "Not at the beginning of a page");
36 /* Adding another copy (and a syscall) will probably slow things a lot.
37 TODO, optimize this somehow (at least by grouping the syscalls)
39 - reduce the number of syscalls;
40 - let the application snapshot itself;
41 - move the segments in shared memory (this will break `fork` however).
45 buffer.data(), xbt_pagesize, page,
46 simgrid::mc::ProcessIndexDisabled);
48 pagenos_[i] = store_->store_page(buffer.data());