-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
198 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef OSRM_ENGINE_DATAFACADE_MMAP_MEMORY_ALLOCATOR_HPP_ | ||
#define OSRM_ENGINE_DATAFACADE_MMAP_MEMORY_ALLOCATOR_HPP_ | ||
|
||
#include "engine/datafacade/contiguous_block_allocator.hpp" | ||
|
||
#include "storage/storage_config.hpp" | ||
|
||
#include "util/vector_view.hpp" | ||
|
||
#include <boost/iostreams/device/mapped_file.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace osrm | ||
{ | ||
namespace engine | ||
{ | ||
namespace datafacade | ||
{ | ||
|
||
/** | ||
* This allocator uses file backed mmap memory block as the data location. | ||
*/ | ||
class MMapMemoryAllocator : public ContiguousBlockAllocator | ||
{ | ||
public: | ||
explicit MMapMemoryAllocator(const storage::StorageConfig &config, const boost::filesystem::path &memory_file); | ||
~MMapMemoryAllocator() override final; | ||
|
||
// interface to give access to the datafacades | ||
storage::DataLayout &GetLayout() override final; | ||
char *GetMemory() override final; | ||
|
||
private: | ||
storage::DataLayout *data_layout; | ||
util::vector_view<char> mapped_memory; | ||
boost::iostreams::mapped_file mapped_memory_file; | ||
}; | ||
|
||
} // namespace datafacade | ||
} // namespace engine | ||
} // namespace osrm | ||
|
||
#endif // OSRM_ENGINE_DATAFACADE_SHARED_MEMORY_ALLOCATOR_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "engine/datafacade/mmap_memory_allocator.hpp" | ||
|
||
#include "storage/storage.hpp" | ||
|
||
#include "util/log.hpp" | ||
#include "util/mmap_file.hpp" | ||
|
||
#include "boost/assert.hpp" | ||
|
||
namespace osrm | ||
{ | ||
namespace engine | ||
{ | ||
namespace datafacade | ||
{ | ||
|
||
MMapMemoryAllocator::MMapMemoryAllocator(const storage::StorageConfig &config, const boost::filesystem::path &memory_file) | ||
{ | ||
storage::Storage storage(config); | ||
|
||
if (!boost::filesystem::exists(memory_file)) | ||
{ | ||
storage::DataLayout initial_layout; | ||
storage.PopulateLayout(initial_layout); | ||
|
||
auto data_size = initial_layout.GetSizeOfLayout(); | ||
auto total_size = data_size + sizeof(storage::DataLayout); | ||
|
||
mapped_memory = util::mmapFile<char>(memory_file, mapped_memory_file, total_size); | ||
|
||
data_layout = reinterpret_cast<storage::DataLayout*>(mapped_memory.data()); | ||
*data_layout = initial_layout; | ||
storage.PopulateData(*data_layout, GetMemory()); | ||
} | ||
else | ||
{ | ||
mapped_memory = util::mmapFile<char>(memory_file, mapped_memory_file); | ||
data_layout = reinterpret_cast<storage::DataLayout*>(mapped_memory.data()); | ||
} | ||
} | ||
|
||
MMapMemoryAllocator::~MMapMemoryAllocator() {} | ||
|
||
storage::DataLayout &MMapMemoryAllocator::GetLayout() | ||
{ | ||
return *data_layout; | ||
} | ||
char *MMapMemoryAllocator::GetMemory() | ||
{ | ||
return mapped_memory.data() + sizeof(storage::DataLayout); | ||
} | ||
|
||
} // namespace datafacade | ||
} // namespace engine | ||
} // namespace osrm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters