1 /* Copyright (c) 2007-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "src/mc/ChunkedData.hpp"
10 #define SOFT_DIRTY_BIT_NUMBER 55
11 #define SOFT_DIRTY (((uint64_t)1) << SOFT_DIRTY_BIT_NUMBER)
16 /** Take a per-page snapshot of a region
18 * @param data The start of the region (must be at the beginning of a page)
19 * @param pag_count Number of pages of the region
20 * @return Snapshot page numbers of this new snapshot
22 ChunkedData::ChunkedData(PageStore& store, AddressSpace& as,
23 remote_ptr<void> addr, std::size_t page_count,
24 const std::size_t* ref_page_numbers, const std::uint64_t* pagemap)
27 this->pagenos_.resize(page_count);
28 std::vector<char> buffer(xbt_pagesize);
30 for (size_t i = 0; i != page_count; ++i) {
32 // We don't have to compare soft-clean pages:
33 if (ref_page_numbers && pagemap && !(pagemap[i] & SOFT_DIRTY)) {
34 pagenos_[i] = ref_page_numbers[i];
35 store_->ref_page(ref_page_numbers[i]);
39 remote_ptr<void> page = remote(addr.address() + (i << xbt_pagebits));
40 xbt_assert(mc_page_offset((void*)page.address())==0,
41 "Not at the beginning of a page");
43 /* Adding another copy (and a syscall) will probably slow things a lot.
44 TODO, optimize this somehow (at least by grouping the syscalls)
46 - reduce the number of syscalls;
47 - let the application snapshot itself;
48 - move the segments in shared memory (this will break `fork` however).
52 buffer.data(), xbt_pagesize, page,
53 simgrid::mc::ProcessIndexDisabled);
55 pagenos_[i] = store_->store_page(buffer.data());