This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Fix hugify on new Linux kernels
Needs ReviewPublic

Authored by maksfb on Dec 20 2022, 12:01 PM.

Details

Summary

Memory needs to be unlocked before madvise(2) is called for transparent
huge pages. I verified that /proc/<pid>/smaps reports FilePmdMapped
correctly. Note that there's a (non-deterministic) delay before the call
to madvise() is issued and pages are remapped. Thus, it's difficult to
test the functionality automatically.

Diff Detail

Event Timeline

maksfb created this revision.Dec 20 2022, 12:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 20 2022, 12:01 PM
maksfb requested review of this revision.Dec 20 2022, 12:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 20 2022, 12:01 PM

Could you please provide related kernel commit? Thank you!

Could you please provide related kernel commit? Thank you!

There's no corresponding kernel patch. The hugify feature was apparently always broken for THP kernels as pointed out by @treapster in D137620.

@maksfb should we lock the memory again after the __madvise?

@maksfb should we lock the memory again after the __madvise?

Sadly, we cannot because of the delayed action of the kernel.

yota9 added a comment.Dec 21 2022, 4:22 AM

@maksfb I'm just not completely understand why mlock has something todo with it? Why the binary memory even get locked on startup?

yavtuk added a comment.EditedDec 21 2022, 6:32 PM

@maksfb Can you use __prctl(41 /* PR_SET_THP_DISABLE */, 0, 0, 0, 0); call instead of munlock?

@maksfb Can you use __prctl(41 /* PR_SET_THP_DISABLE */, 0, 0, 0, 0); call instead of munlock?

Could not get huge pages on my system with the above.

maksfb added a comment.Jan 3 2023, 1:27 PM

@maksfb I'm just not completely understand why mlock has something todo with it? Why the binary memory even get locked on startup?

I've used the code from HHVM's hugify (https://github.com/facebook/hhvm/blob/62d67f83bd96b23f8522fb1d3fe8597bcfd7fc75/hphp/runtime/base/program-functions.cpp#L859-L863), and huge pages started to work for me. I'm not entirely sure why the memory was locked in the first place.

yota9 added a comment.Jan 7 2023, 10:44 AM

@maksfb I see, thank you. I assume that the application code becomes locked due to some kind of meta optimisations for the services on the kernel level or interpreter , probably it is not common situation... Because of that I don't really think this munlock call may harm somehow, so LGTM.