@@ -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-
347344bool 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
0 commit comments