Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c1f3e2d4c0555a9660ccb9ae4c3b7a90273f2e3f
[simgrid.git] / src / mc / ChunkedData.cpp
1 #include <mc/ChunkedData.hpp>
2
3 #define SOFT_DIRTY_BIT_NUMBER 55
4 #define SOFT_DIRTY (((uint64_t)1) << SOFT_DIRTY_BIT_NUMBER)
5
6 namespace simgrid {
7 namespace mc {
8
9 /** Take a per-page snapshot of a region
10  *
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
14  */
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)
18 {
19   store_ = &store;
20   this->pagenos_.resize(page_count);
21   std::vector<char> buffer(xbt_pagesize);
22
23   for (size_t i = 0; i != page_count; ++i) {
24
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]);
29       continue;
30     }
31
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");
35
36         /* Adding another copy (and a syscall) will probably slow things a lot.
37            TODO, optimize this somehow (at least by grouping the syscalls)
38            if needed. Either:
39             - reduce the number of syscalls;
40             - let the application snapshot itself;
41             - move the segments in shared memory (this will break `fork` however).
42         */
43
44         as.read_bytes(
45           buffer.data(), xbt_pagesize, page,
46           simgrid::mc::ProcessIndexDisabled);
47
48       pagenos_[i] = store_->store_page(buffer.data());
49
50   }
51 }
52
53 }
54 }