Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / mc / sosp / PageStore.hpp
index 5851513..1764483 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2015-2022. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -6,14 +6,12 @@
 #ifndef SIMGRID_MC_PAGESTORE_HPP
 #define SIMGRID_MC_PAGESTORE_HPP
 
-#include <cstdint>
-#include <vector>
+#include "src/mc/mc_forward.hpp"
+#include "src/mc/mc_mmu.hpp"
 
 #include <unordered_map>
 #include <unordered_set>
-
-#include "src/mc/mc_forward.hpp"
-#include "src/mc/mc_mmu.hpp"
+#include <vector>
 
 #ifndef XBT_ALWAYS_INLINE
 #define XBT_ALWAYS_INLINE inline __attribute__((always_inline))
@@ -25,7 +23,7 @@ namespace mc {
 /** @brief Storage for snapshot memory pages
  *
  * The first (lower) layer of the per-page snapshot mechanism is a page store:
- * its responsibility is to store immutable sharable reference-counted memory
+ * its responsibility is to store immutable shareable reference-counted memory
  * pages independently of the snapshotting logic. Snapshot management and
  * representation is handled to an higher layer. READMORE
  *
@@ -36,7 +34,7 @@ namespace mc {
  *
  *    We want to keep this memory region aligned on the memory pages (so
  *    that we might be able to create non-linear memory mappings on those
- *    pages in the future) and be able to expand it without coyping the
+ *    pages in the future) and be able to expand it without copying the
  *    data (there will be a lot of pages here): we will be able to
  *    efficiently expand the memory mapping using `mremap()`, moving it
  *    to another virtual address if necessary.
@@ -75,15 +73,15 @@ namespace mc {
  */
 class PageStore {
 public: // Types
-  typedef std::uint64_t hash_type;
+  using hash_type = std::uint64_t;
 
 private:
   // Types
   // We are using a cheap hash to index a page.
   // We should expect collision and we need to associate multiple page indices
   // to the same hash.
-  typedef std::unordered_set<std::size_t> page_set_type;
-  typedef std::unordered_map<hash_type, page_set_type> pages_map_type;
+  using page_set_type  = std::unordered_set<std::size_t>;
+  using pages_map_type = std::unordered_map<hash_type, page_set_type>;
 
   // Fields:
   /** First page */
@@ -130,34 +128,34 @@ public:
    * store.
    *
    * This will be the case if a page if soft clean: we know that is has not
-   * changed since the previous cnapshot/restoration and we can avoid
+   * changed since the previous snapshot/restoration and we can avoid
    * hashing the page, comparing byte-per-byte to candidates.
    * */
   void ref_page(size_t pageno);
 
   /** @brief Store a page in the page store */
-  std::size_t store_page(void* page);
+  std::size_t store_page(const void* page);
 
   /** @brief Get a page from its page number
    *
    *  @param pageno Number of the memory page in the store
    *  @return Start of the page
    */
-  const void* get_page(std::size_t pageno) const;
+  void* get_page(std::size_t pageno) const;
 
   // Debug/test methods
 
   /** @brief Get the number of references for a page */
-  std::size_t get_ref(std::size_t pageno);
+  std::size_t get_ref(std::size_t pageno) const;
 
   /** @brief Get the number of used pages */
-  std::size_t size();
+  std::size_t size() const;
 
   /** @brief Get the capacity of the page store
    *
    *  The capacity is expanded by a system call (mremap).
    * */
-  std::size_t capacity();
+  std::size_t capacity() const;
 };
 
 XBT_ALWAYS_INLINE void PageStore::unref_page(std::size_t pageno)
@@ -171,22 +169,22 @@ XBT_ALWAYS_INLINE void PageStore::ref_page(size_t pageno)
   ++this->page_counts_[pageno];
 }
 
-XBT_ALWAYS_INLINE const void* PageStore::get_page(std::size_t pageno) const
+XBT_ALWAYS_INLINE void* PageStore::get_page(std::size_t pageno) const
 {
   return (void*)simgrid::mc::mmu::join(pageno, (std::uintptr_t)this->memory_);
 }
 
-XBT_ALWAYS_INLINE std::size_t PageStore::get_ref(std::size_t pageno)
+XBT_ALWAYS_INLINE std::size_t PageStore::get_ref(std::size_t pageno) const
 {
   return this->page_counts_[pageno];
 }
 
-XBT_ALWAYS_INLINE std::size_t PageStore::size()
+XBT_ALWAYS_INLINE std::size_t PageStore::size() const
 {
   return this->top_index_ - this->free_pages_.size();
 }
 
-XBT_ALWAYS_INLINE std::size_t PageStore::capacity()
+XBT_ALWAYS_INLINE std::size_t PageStore::capacity() const
 {
   return this->capacity_;
 }