Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: adjust THP sysfs config token retrieval and file closure #37187

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
jayaddison marked this conversation as resolved.
Show resolved Hide resolved
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