Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ef35495c2c75e3e237466c638f96b65dd0b67dde
[simgrid.git] / src / mc / sosp / ChunkedData.cpp
1 /* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/mc/AddressSpace.hpp"
7 #include "src/mc/sosp/ChunkedData.hpp"
8
9 namespace simgrid {
10 namespace mc {
11
12 /** Take a per-page snapshot of a region
13  *
14  *  @param addr            The start of the region (must be at the beginning of a page)
15  *  @param page_count      Number of pages of the region
16  *  @return                Snapshot page numbers of this new snapshot
17  */
18 ChunkedData::ChunkedData(PageStore& store, const AddressSpace& as, RemotePtr<void> addr, std::size_t page_count)
19     : store_(&store)
20 {
21   this->pagenos_.resize(page_count);
22   std::vector<char> buffer(xbt_pagesize);
23
24   for (size_t i = 0; i != page_count; ++i) {
25
26     RemotePtr<void> page = remote((void*)simgrid::mc::mmu::join(i, addr.address()));
27     xbt_assert(simgrid::mc::mmu::split(page.address()).second == 0, "Not at the beginning of a page");
28
29     /* Adding another copy (and a syscall) will probably slow things a lot.
30        TODO, optimize this somehow (at least by grouping the syscalls)
31        if needed. Either:
32        - reduce the number of syscalls
33        - let the application snapshot itself
34        - move the segments in shared memory (this will break `fork` however)
35     */
36
37     as.read_bytes(buffer.data(), xbt_pagesize, page);
38
39     pagenos_[i] = store_->store_page(buffer.data());
40   }
41 }
42
43 } // namespace mc
44 } // namespace simgrid