Skip to content

Commit 9946c11

Browse files
jayaddisondanielleadams
authored andcommitted
src: read exactly two tokens from Linux THP sysfs config
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>
1 parent 67c9a8e commit 9946c11

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/large_pages/node_large_page.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ struct text_region FindNodeTextRegion() {
260260
bool IsTransparentHugePagesEnabled() {
261261
std::ifstream ifs;
262262

263+
// File format reference:
264+
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/mm/huge_memory.c?id=13391c60da3308ed9980de0168f74cce6c62ac1d#n163
263265
ifs.open("/sys/kernel/mm/transparent_hugepage/enabled");
264266
if (!ifs) {
265267
PrintWarning("could not open /sys/kernel/mm/transparent_hugepage/enabled");
@@ -268,7 +270,7 @@ bool IsTransparentHugePagesEnabled() {
268270

269271
std::string always, madvise;
270272
if (ifs.is_open()) {
271-
while (ifs >> always >> madvise) {}
273+
ifs >> always >> madvise;
272274
}
273275
ifs.close();
274276

0 commit comments

Comments
 (0)