Skip to content

Commit

Permalink
src: extract GetTransparentHugePagesConfiguration function to read sy…
Browse files Browse the repository at this point in the history
…stem huge tables configuration on Linux-based systems
  • Loading branch information
jayaddison committed Jan 26, 2021
1 parent 53648a0 commit a7fe193
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/large_pages/node_large_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,30 @@ struct text_region FindNodeTextRegion() {
}

#if defined(__linux__)
bool IsTransparentHugePagesEnabled() {
std::ifstream ifs;
std::istream *GetTransparentHugePagesConfiguration() {
std::ifstream *ifs = new std::ifstream();

ifs.open("/sys/kernel/mm/transparent_hugepage/enabled");
if (!ifs) {
ifs->open("/sys/kernel/mm/transparent_hugepage/enabled");
if (!*ifs) {
PrintWarning("could not open /sys/kernel/mm/transparent_hugepage/enabled");
return nullptr;
}

return ifs;
}

bool IsTransparentHugePagesEnabled() {
std::istream *configuration = GetTransparentHugePagesConfiguration();
if (configuration == nullptr) {
return false;
}

bool enabled = false;
if (ifs.is_open()) {
std::string token;
while (ifs >> token) {
enabled = enabled || token == "[always]" || token == "[madvise]";
}
std::string token;
while (*configuration >> token) {
enabled = enabled || token == "[always]" || token == "[madvise]";
}
ifs.close();

delete configuration;
return enabled;
}
#elif defined(__FreeBSD__)
Expand Down

0 comments on commit a7fe193

Please sign in to comment.