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"
18 #define SOFT_DIRTY_BIT_NUMBER 55
19 #define SOFT_DIRTY (((uint64_t)1) << SOFT_DIRTY_BIT_NUMBER)
24 /** Take a per-page snapshot of a region
26 * @param data The start of the region (must be at the beginning of a page)
27 * @param pag_count Number of pages of the region
28 * @return Snapshot page numbers of this new snapshot
30 ChunkedData::ChunkedData(PageStore& store, AddressSpace& as,
31 RemotePtr<void> addr, std::size_t page_count,
32 const std::size_t* ref_page_numbers, const std::uint64_t* pagemap)
35 this->pagenos_.resize(page_count);
36 std::vector<char> buffer(xbt_pagesize);
38 for (size_t i = 0; i != page_count; ++i) {
40 // We don't have to compare soft-clean pages:
41 if (ref_page_numbers && pagemap && !(pagemap[i] & SOFT_DIRTY)) {
42 pagenos_[i] = ref_page_numbers[i];
43 store_->ref_page(ref_page_numbers[i]);
47 RemotePtr<void> page = remote(addr.address() + (i << xbt_pagebits));
48 xbt_assert(mc_page_offset((void*)page.address())==0,
49 "Not at the beginning of a page");
51 /* Adding another copy (and a syscall) will probably slow things a lot.
52 TODO, optimize this somehow (at least by grouping the syscalls)
54 - reduce the number of syscalls;
55 - let the application snapshot itself;
56 - move the segments in shared memory (this will break `fork` however).
60 buffer.data(), xbt_pagesize, page,
61 simgrid::mc::ProcessIndexDisabled);
63 pagenos_[i] = store_->store_page(buffer.data());