Skip to content

Commit

Permalink
src: read exactly two tokens from Linux THP sysfs config
Browse files Browse the repository at this point in the history
There was an unexpected and hard-to-spot issue here:
the /sys/kernel/mm/transparent_hugepage/enabled file contains three
entries, and the std::ifstream reader was reading two values on each
loop iteration, resulting in incorrect behaviour.

Fixes: #37064

PR-URL: #37065
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
jayaddison authored and targos committed May 1, 2021
1 parent 11d3e71 commit 00309ee
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/large_pages/node_large_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ struct text_region FindNodeTextRegion() {
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) {
PrintWarning("could not open /sys/kernel/mm/transparent_hugepage/enabled");
Expand All @@ -268,7 +270,7 @@ bool IsTransparentHugePagesEnabled() {

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

Expand Down

0 comments on commit 00309ee

Please sign in to comment.