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 <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
jayaddison authored and targos committed Feb 28, 2021
1 parent 01773ab commit daad7bb
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/large_pages/node_large_page.cc
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 daad7bb

Please sign in to comment.