Add mmap allocator
This commit is contained in:
committed by
Patrick Niklaus
parent
43f0723b73
commit
bec57258a4
@@ -0,0 +1,53 @@
|
||||
#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
|
||||
@@ -112,6 +112,9 @@ inline unsigned generateServerProgramOptions(const int argc,
|
||||
("shared-memory,s",
|
||||
value<bool>(&config.use_shared_memory)->implicit_value(true)->default_value(false),
|
||||
"Load data from shared memory") //
|
||||
("memory_file",
|
||||
value<boost::filesystem::path>(&config.memory_file),
|
||||
"Store data in a memory mapped file rather than in process memory.") //
|
||||
("algorithm,a",
|
||||
value<EngineConfig::Algorithm>(&config.algorithm)
|
||||
->default_value(EngineConfig::Algorithm::CH, "CH"),
|
||||
|
||||
Reference in New Issue
Block a user