Skip to content

Commit 47b0f21

Browse files
nixprimegvisor-bot
authored andcommitted
test/util: fix StackTHPDisabled on newer kernels
PiperOrigin-RevId: 826269216
1 parent fe72162 commit 47b0f21

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

test/util/proc_util.cc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ PosixErrorOr<std::vector<ProcSmapsEntry>> ParseProcSmaps(
290290
RETURN_IF_ERRNO(on_optional_field_kb(&entry->mmu_page_size_kb));
291291
} else if (key == "Locked") {
292292
RETURN_IF_ERRNO(on_optional_field_kb(&entry->locked_kb));
293+
} else if (key == "THPeligible") {
294+
if (entry->thp_eligible) {
295+
return PosixError(EINVAL, "smaps entry has duplicate THPeligible line");
296+
}
297+
ASSIGN_OR_RETURN_ERRNO(entry->thp_eligible, Atoi<int>(key_value[1]));
293298
} else if (key == "VmFlags") {
294299
if (entry->vm_flags) {
295300
return PosixError(EINVAL, "duplicate VmFlags line");
@@ -336,17 +341,23 @@ PosixErrorOr<std::vector<ProcSmapsEntry>> ReadProcSmaps(pid_t pid) {
336341
return ParseProcSmaps(contents);
337342
}
338343

339-
bool EntryHasNH(const ProcSmapsEntry& e) {
340-
if (e.vm_flags) {
341-
auto flags = e.vm_flags.value();
342-
return std::find(flags.begin(), flags.end(), "nh") != flags.end();
343-
}
344-
return false;
345-
}
346-
347344
bool StackTHPDisabled(std::vector<ProcSmapsEntry> maps) {
348-
return std::any_of(maps.begin(), maps.end(), [](const ProcSmapsEntry& e) {
349-
return e.maps_entry.filename == "[stack]" && EntryHasNH(e);
345+
return absl::c_any_of(maps, [](const ProcSmapsEntry& e) {
346+
if (e.maps_entry.filename != "[stack]") {
347+
return false;
348+
}
349+
// Linux changed PR_SET_THP_DISABLE to cease setting VM_NOHUGEPAGE on VMAs
350+
// in 1860033237d4b ("mm: make PR_SET_THP_DISABLE immediately active") and
351+
// subsequently added THPeligible in 7635d9cbe8327 ("mm, thp, proc: report
352+
// THP eligibility for each vma").
353+
if (e.thp_eligible) {
354+
return *e.thp_eligible == 0;
355+
}
356+
if (e.vm_flags) {
357+
auto flags = e.vm_flags.value();
358+
return std::find(flags.begin(), flags.end(), "nh") != flags.end();
359+
}
360+
return false;
350361
});
351362
}
352363

test/util/proc_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct ProcSmapsEntry {
7070
absl::optional<size_t> kernel_page_size_kb;
7171
absl::optional<size_t> mmu_page_size_kb;
7272
absl::optional<size_t> locked_kb;
73+
absl::optional<int> thp_eligible;
7374

7475
// Caution: "Note that there is no guarantee that every flag and associated
7576
// mnemonic will be present in all further kernel releases. Things get

0 commit comments

Comments
 (0)