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. */
12 #include <xbt/misc.h> // xbt_pagesize and friends
13 #include <xbt/asserts.h>
15 #include "src/mc/AddressSpace.hpp"
16 #include "src/mc/ChunkedData.hpp"
17 #include "src/mc/PageStore.hpp"
19 #define SOFT_DIRTY_BIT_NUMBER 55
20 #define SOFT_DIRTY (((uint64_t)1) << SOFT_DIRTY_BIT_NUMBER)
25 /** Take a per-page snapshot of a region
27 * @param data The start of the region (must be at the beginning of a page)
28 * @param pag_count Number of pages of the region
29 * @return Snapshot page numbers of this new snapshot
31 ChunkedData::ChunkedData(PageStore& store, AddressSpace& as,
32 RemotePtr<void> addr, std::size_t page_count,
33 const std::size_t* ref_page_numbers, const std::uint64_t* pagemap)
36 this->pagenos_.resize(page_count);
37 std::vector<char> buffer(xbt_pagesize);
39 for (size_t i = 0; i != page_count; ++i) {
41 // We don't have to compare soft-clean pages:
42 if (ref_page_numbers && pagemap && !(pagemap[i] & SOFT_DIRTY)) {
43 pagenos_[i] = ref_page_numbers[i];
44 store_->ref_page(ref_page_numbers[i]);
48 RemotePtr<void> page = remote((void*)
49 simgrid::mc::mmu::join(i, addr.address()));
50 xbt_assert(simgrid::mc::mmu::split(page.address()).second == 0,
51 "Not at the beginning of a page");
53 /* Adding another copy (and a syscall) will probably slow things a lot.
54 TODO, optimize this somehow (at least by grouping the syscalls)
56 - reduce the number of syscalls;
57 - let the application snapshot itself;
58 - move the segments in shared memory (this will break `fork` however).
62 buffer.data(), xbt_pagesize, page,
63 simgrid::mc::ProcessIndexDisabled);
65 pagenos_[i] = store_->store_page(buffer.data());