From 1094746d67df432366abb8796278934a386b81e1 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 16 May 2019 01:26:51 +0200 Subject: [PATCH] mc::Buffer: no need for mmap type now that KSM is gone --- src/mc/sosp/RegionSnapshot.cpp | 38 ---------------------------------- src/mc/sosp/RegionSnapshot.hpp | 23 ++++++++++---------- 2 files changed, 12 insertions(+), 49 deletions(-) diff --git a/src/mc/sosp/RegionSnapshot.cpp b/src/mc/sosp/RegionSnapshot.cpp index 6dea387e40..c638c81563 100644 --- a/src/mc/sosp/RegionSnapshot.cpp +++ b/src/mc/sosp/RegionSnapshot.cpp @@ -36,44 +36,6 @@ static inline const char* to_cstr(RegionType region) } } -Buffer::Buffer(std::size_t size, Type type) : size_(size), type_(type) -{ - switch (type_) { - case Type::Malloc: - data_ = ::operator new(size_); - break; - case Type::Mmap: - data_ = ::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0); - if (data_ == MAP_FAILED) { - data_ = nullptr; - size_ = 0; - type_ = Type::Malloc; - throw std::bad_alloc(); - } - break; - default: - abort(); - } -} - -void Buffer::clear() noexcept -{ - switch (type_) { - case Type::Malloc: - ::operator delete(data_); - break; - case Type::Mmap: - if (munmap(data_, size_) != 0) - abort(); - break; - default: - abort(); - } - data_ = nullptr; - size_ = 0; - type_ = Type::Malloc; -} - RegionSnapshot dense_region(RegionType region_type, void* start_addr, void* permanent_addr, size_t size) { simgrid::mc::Buffer data = Buffer::malloc(size); diff --git a/src/mc/sosp/RegionSnapshot.hpp b/src/mc/sosp/RegionSnapshot.hpp index de4734a011..8db62e4698 100644 --- a/src/mc/sosp/RegionSnapshot.hpp +++ b/src/mc/sosp/RegionSnapshot.hpp @@ -28,42 +28,43 @@ enum class StorageType { NoData = 0, Flat = 1, Chunked = 2, Privatized = 3 }; class Buffer { private: - enum class Type { Malloc, Mmap }; void* data_ = nullptr; std::size_t size_; - Type type_ = Type::Malloc; - Buffer(std::size_t size, Type type = Type::Malloc); - Buffer(void* data, std::size_t size, Type type = Type::Malloc) : data_(data), size_(size), type_(type) {} + Buffer(std::size_t size) : size_(size) { data_ = ::operator new(size_); } + + Buffer(void* data, std::size_t size) : data_(data), size_(size) {} public: Buffer() = default; - void clear() noexcept; + void clear() noexcept + { + ::operator delete(data_); + data_ = nullptr; + size_ = 0; + } + ~Buffer() noexcept { clear(); } - static Buffer malloc(std::size_t size) { return Buffer(size, Type::Malloc); } - static Buffer mmap(std::size_t size) { return Buffer(size, Type::Mmap); } + static Buffer malloc(std::size_t size) { return Buffer(size); } // No copy Buffer(Buffer const& buffer) = delete; Buffer& operator=(Buffer const& buffer) = delete; // Move - Buffer(Buffer&& that) noexcept : data_(that.data_), size_(that.size_), type_(that.type_) + Buffer(Buffer&& that) noexcept : data_(that.data_), size_(that.size_) { that.data_ = nullptr; that.size_ = 0; - that.type_ = Type::Malloc; } Buffer& operator=(Buffer&& that) noexcept { clear(); data_ = that.data_; size_ = that.size_; - type_ = that.type_; that.data_ = nullptr; that.size_ = 0; - that.type_ = Type::Malloc; return *this; } -- 2.20.1