Skip to content

Commit 270f187

Browse files
wip
1 parent fb8182a commit 270f187

File tree

5 files changed

+29
-30
lines changed

5 files changed

+29
-30
lines changed

Diff for: include/util/meminfo.hpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MEMINFO_HPP
33

44
#include "util/log.hpp"
5+
#include <cstddef>
56

67
#ifndef _WIN32
78
#include <sys/resource.h>
@@ -10,18 +11,27 @@
1011
namespace osrm::util
1112
{
1213

13-
inline void DumpMemoryStats()
14+
inline size_t PeakRAMUsedInBytes()
1415
{
1516
#ifndef _WIN32
1617
rusage usage;
1718
getrusage(RUSAGE_SELF, &usage);
1819
#ifdef __linux__
1920
// Under linux, ru.maxrss is in kb
20-
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss * 1024;
21+
return usage.ru_maxrss * 1024;
2122
#else // __linux__
2223
// Under BSD systems (OSX), it's in bytes
23-
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss;
24+
return usage.ru_maxrss;
2425
#endif // __linux__
26+
#else // _WIN32
27+
return 0;
28+
#endif // _WIN32
29+
}
30+
31+
inline void DumpMemoryStats()
32+
{
33+
#ifndef _WIN32
34+
util::Log() << "RAM: peak bytes used: " << PeakRAMUsedInBytes();
2535
#else // _WIN32
2636
util::Log() << "RAM: peak bytes used: <not implemented on Windows>";
2737
#endif // _WIN32

Diff for: include/util/pool_allocator.hpp

+10-19
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
namespace osrm::util
1515
{
1616

17-
#if 1
18-
19-
template <typename T, size_t MinItemsInBlock = 1024>
17+
template <typename T>
2018
class PoolAllocator;
2119

22-
template <typename T, size_t MinItemsInBlock = 1024>
20+
template <typename T>
2321
class MemoryManager
2422
{
23+
private:
24+
constexpr static size_t MIN_ITEMS_IN_BLOCK = 1024;
2525
public:
2626
static std::shared_ptr<MemoryManager> instance()
2727
{
@@ -82,7 +82,7 @@ class MemoryManager
8282

8383
void allocate_block(size_t items_in_block)
8484
{
85-
items_in_block = std::max(items_in_block, MinItemsInBlock);
85+
items_in_block = std::max(items_in_block, MIN_ITEMS_IN_BLOCK);
8686

8787
size_t block_size = items_in_block * sizeof(T);
8888
T *block = static_cast<T *>(std::malloc(block_size));
@@ -104,21 +104,21 @@ class MemoryManager
104104
size_t total_allocated_ = 0;
105105
};
106106

107-
template <typename T, size_t MinItemsInBlock>
107+
template <typename T>
108108
class PoolAllocator
109109
{
110110
public:
111111
using value_type = T;
112112

113-
PoolAllocator() noexcept : pool(MemoryManager<T, MinItemsInBlock>::instance()) {};
113+
PoolAllocator() noexcept : pool(MemoryManager<T>::instance()) {};
114114

115115
template <typename U>
116-
PoolAllocator(const PoolAllocator<U> &) noexcept : pool(MemoryManager<T, MinItemsInBlock>::instance()) {}
116+
PoolAllocator(const PoolAllocator<U> &) noexcept : pool(MemoryManager<T>::instance()) {}
117117

118118
template <typename U>
119119
struct rebind
120120
{
121-
using other = PoolAllocator<U, MinItemsInBlock>;
121+
using other = PoolAllocator<U>;
122122
};
123123

124124
T *allocate(std::size_t n)
@@ -139,13 +139,7 @@ class PoolAllocator
139139
PoolAllocator &operator=(PoolAllocator &&) noexcept = default;
140140

141141
private:
142-
std::shared_ptr<MemoryManager<T, MinItemsInBlock>> pool;
143-
144-
static size_t get_next_power_of_two_exponent(size_t n)
145-
{
146-
BOOST_ASSERT(n > 0);
147-
return (sizeof(size_t) * 8) - std::countl_zero(n - 1);
148-
}
142+
std::shared_ptr<MemoryManager<T>> pool;
149143
};
150144

151145
template <typename T, typename U>
@@ -160,7 +154,4 @@ bool operator!=(const PoolAllocator<T> &, const PoolAllocator<U> &)
160154
return false;
161155
}
162156

163-
#else
164-
template <typename T> using PoolAllocator = std::allocator<T>;
165-
#endif
166157
} // namespace osrm::util

Diff for: include/util/query_heap.hpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ template <typename NodeID,
194194
typename Key,
195195
typename Weight,
196196
typename Data,
197-
typename IndexStorage = ArrayStorage<NodeID, NodeID>,
198-
bool ThreadLocal = true>
197+
typename IndexStorage = ArrayStorage<NodeID, NodeID>>
199198
class QueryHeap
200199
{
201200
private:
@@ -214,16 +213,13 @@ class QueryHeap
214213
}
215214
};
216215

217-
using AllocatorType = typename std::conditional<ThreadLocal,
218-
PoolAllocator<HeapData>,
219-
std::allocator<HeapData>>::type;
220216

221217

222218
using HeapContainer = boost::heap::d_ary_heap<HeapData,
223219
boost::heap::arity<4>,
224220
boost::heap::mutable_<true>,
225221
boost::heap::compare<std::greater<HeapData>>,
226-
boost::heap::allocator<AllocatorType>>;
222+
boost::heap::allocator<PoolAllocator<HeapData>>>;
227223
using HeapHandle = typename HeapContainer::handle_type;
228224

229225
public:

Diff for: src/benchmarks/bench.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "osrm/coordinate.hpp"
1313
#include "osrm/engine_config.hpp"
1414
#include "osrm/json_container.hpp"
15-
15+
#include "util/meminfo.hpp"
1616
#include "osrm/osrm.hpp"
1717
#include "osrm/status.hpp"
1818

@@ -655,6 +655,8 @@ try
655655
std::cerr << "Unknown benchmark: " << benchmarkToRun << std::endl;
656656
return EXIT_FAILURE;
657657
}
658+
659+
std::cerr << "Peak RAM: " << osrm::util::PeakRAMUsedInBytes() / (1024 * 1024) << "MB" << std::endl;
658660
return EXIT_SUCCESS;
659661
}
660662
catch (const std::exception &e)

Diff for: test/data/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ benchmark: data $(DATA_NAME).requests
6565
checksum:
6666
$(MD5SUM) $(DATA_NAME).osm.pbf $(DATA_NAME).poly > data.md5sum
6767

68-
.PHONY: clean checksum data
68+
.PHONY: clean checksum benchmark data

0 commit comments

Comments
 (0)