This is an archive of the discontinued LLVM Phabricator instance.

Set Huge Page mode on shadow regions based on no_huge_pages_for_shadow
ClosedPublic

Authored by stephan.yichao.zhao on Oct 18 2020, 6:27 PM.

Details

Reviewers
morehouse
Summary

It turned out that at dynamic shared library mode, the memory access

pattern can increase memory footprint significantly on OS when transparent
hugepages (THP) are enabled. This could cause >70x memory overhead than
running a static linked binary. For example, a static binary with RSS
overhead 300M can use > 23G RSS if it is built dynamically.
/proc/../smaps shows in 6204552 kB RSS 6141952 kB relates to
AnonHugePages.

Also such a high RSS happens in some rate: around 25% runs may use > 23G RSS, the
rest uses in between 6-23G. I guess this may relate to how user memory
is allocated and distributted across huge pages.

THP is a trade-off between time and space. We have a flag
no_huge_pages_for_shadow for sanitizer. It is true by default but DFSan
did not follow this. Depending on if a target is built statically or
dynamically, maybe Clang can set no_huge_pages_for_shadow accordingly
after this change. But it still seems fine to follow the default setting of
no_huge_pages_for_shadow. If time is an issue, and users are fine with
high RSS, this flag can be set to false selectively.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptOct 18 2020, 6:27 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
stephan.yichao.zhao requested review of this revision.Oct 18 2020, 6:27 PM
morehouse accepted this revision.Oct 19 2020, 12:02 PM
morehouse added inline comments.
compiler-rt/lib/dfsan/dfsan.cpp
440

Nit: Let's prefer SetShadowRegionFlags style for new code.

This revision is now accepted and ready to land.Oct 19 2020, 12:02 PM
morehouse requested changes to this revision.Oct 19 2020, 12:06 PM
morehouse added inline comments.
compiler-rt/lib/dfsan/dfsan.cpp
440

On second thought, let's eliminate this static function entirely since we only need to call it from one place.

447

Let's reuse MmapFixedSuperNoReserve and then to the use_madv_dontdump check inline here.

458

I think this is unnecessary here since the memory is marked PROT_NONE anyway.

This revision now requires changes to proceed.Oct 19 2020, 12:06 PM

But it still seems fine to follow the default setting of
no_huge_pages_for_shadow. If time is an issue, and users are fine with
high RSS, this flag can be set to false selectively.

I agree 100%

stephan.yichao.zhao marked 4 inline comments as done.Oct 19 2020, 1:08 PM

addressed comments

morehouse accepted this revision.Oct 19 2020, 1:36 PM

LGTM, thanks!

This revision is now accepted and ready to land.Oct 19 2020, 1:36 PM