Skip to content

Commit

Permalink
src: adjust THP sysfs config token retrieval and file closure
Browse files Browse the repository at this point in the history
PR-URL: #37187
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
jayaddison authored and aduh95 committed Feb 17, 2021
1 parent 8353854 commit 9b32762
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/large_pages/node_large_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,21 @@ struct text_region FindNodeTextRegion() {

#if defined(__linux__)
bool IsTransparentHugePagesEnabled() {
std::ifstream ifs;

// File format reference:
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/huge_memory.c?id=13391c60da3308ed9980de0168f74cce6c62ac1d#n163
ifs.open("/sys/kernel/mm/transparent_hugepage/enabled");
if (!ifs) {
const char* filename = "/sys/kernel/mm/transparent_hugepage/enabled";
std::ifstream config_stream(filename, std::ios::in);
if (!config_stream.good()) {
PrintWarning("could not open /sys/kernel/mm/transparent_hugepage/enabled");
return false;
}

std::string always, madvise;
if (ifs.is_open()) {
ifs >> always >> madvise;
}
ifs.close();

return always == "[always]" || madvise == "[madvise]";
std::string token;
config_stream >> token;
if ("[always]" == token) return true;
config_stream >> token;
if ("[madvise]" == token) return true;
return false;
}
#elif defined(__FreeBSD__)
bool IsSuperPagesEnabled() {
Expand Down

0 comments on commit 9b32762

Please sign in to comment.