blob: c14f58ce56488cd77c78196c080fe390f6cc5ebf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <atomic>
#include <mutex>
#include <unordered_map>
namespace vespamalloc {
class MMapPool {
public:
MMapPool();
MMapPool(const MMapPool &) = delete;
MMapPool & operator =(const MMapPool &) = delete;
~MMapPool();
void * mmap(size_t sz);
void unmap(void *);
size_t get_size(void *) const;
size_t getNumMappings() const;
size_t getMmappedBytes() const;
void info(FILE * os, size_t level) const;
private:
struct MMapInfo {
MMapInfo(size_t id, size_t sz) noexcept : _id(id), _sz(sz) { }
size_t _id;
size_t _sz;
};
const size_t _page_size;
const int _huge_flags;
std::atomic<size_t> _count;
std::atomic<bool> _has_hugepage_failure_just_happened;
mutable std::mutex _mutex;
std::unordered_map<const void *, MMapInfo> _mappings;
};
}
|