21 #include <sys/types.h> 28 #include <system_error> 30 #include <boost/regex.hpp> 47 size_t getDefaultHugePageSize() {
54 if (boost::regex_match(line.begin(), line.end(), match,
regex)) {
56 line.begin() + match.position(1), size_t(match.length(1)));
57 pageSize = to<size_t>(numStr) * 1024;
64 throw std::runtime_error(
"Can't find default huge page size");
75 fs::path path("/sys/kernel/mm/hugepages");
76 for (fs::directory_iterator it(path); it != fs::directory_iterator(); ++it) {
77 std::string filename(it->path().filename().string());
78 if (boost::regex_match(filename, match,
regex)) {
80 filename.data() + match.position(1), size_t(match.length(1)));
81 vec.emplace_back(to<size_t>(numStr) * 1024);
92 if (!boost::regex_match(value.begin(), value.end(), match,
regex)) {
93 throw std::runtime_error(
"Invalid pagesize option");
96 if (match.length(2) != 0) {
97 c = char(tolower(value[
size_t(match.position(2))]));
99 StringPiece numStr(value.data() + match.position(1), size_t(match.length(1)));
100 auto const size = to<size_t>(numStr);
101 auto const mult = [
c] {
124 if (sizeVec.empty()) {
127 std::sort(sizeVec.begin(), sizeVec.end());
129 size_t defaultHugePageSize = getDefaultHugePageSize();
131 struct PageSizeLess {
132 bool operator()(
const HugePageSize&
a,
size_t b)
const {
135 bool operator()(
size_t a,
const HugePageSize&
b)
const {
141 std::vector<StringPiece> parts;
142 std::vector<StringPiece> options;
144 gen::byLine(
"/proc/mounts") | gen::eachAs<StringPiece>() |
147 split(
" ", line, parts);
149 if (parts.size() != 6) {
150 throw std::runtime_error(
"Invalid /proc/mounts line");
152 if (parts[2] !=
"hugetlbfs") {
157 split(
",", parts[3], options);
158 size_t pageSize = defaultHugePageSize;
160 for (
auto&
option : options) {
162 const char* p =
static_cast<const char*
>(
174 auto pos = std::lower_bound(
175 sizeVec.begin(), sizeVec.end(), pageSize, PageSizeLess());
176 if (pos == sizeVec.end() || pos->size != pageSize) {
177 throw std::runtime_error(
"Mount page size not found");
179 if (!pos->mountPoint.empty()) {
185 fs::path path(parts[1].
begin(), parts[1].
end());
187 const int ret = stat(path.string().c_str(), &st);
188 if (ret == -1 && errno == ENOENT) {
192 pos->mountPoint = fs::canonical(path);
193 pos->device = st.st_dev;
209 if (p.mountPoint.empty()) {
212 if (size == 0 || size == p.size) {
222 if (p.mountPoint.empty()) {
225 if (device == p.device) {
const HugePageSizeVec & getHugePageSizes()
auto begin(TestAdlIterable &instance)
std::vector< HugePageSize > HugePageSizeVec
—— Concurrent Priority Queue Implementation ——
const HugePageSize * getHugePageSize(size_t size)
const HugePageSize * getHugePageSizeForDevice(dev_t device)
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
void split(const Delim &delimiter, const String &input, std::vector< OutputType > &out, bool ignoreEmpty)
constexpr auto size(C const &c) -> decltype(c.size())
auto end(TestAdlIterable &instance)
void checkUnixError(ssize_t ret, Args &&...args)
auto byLine(File file, char delim= '\n')
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
Range< const char * > StringPiece
option(BUILD_SHARED_LIBS"Build shared libraries (DLLs)."OFF) option(gmock_build_tests"Build all of Google Mock's own tests."OFF) if(EXISTS"$