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 <raisinten@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
jayaddison authored and danielleadams committed Feb 16, 2021
1 parent 67c9a8e commit 9946c11
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 9946c11

Please sign in to comment.