This is an archive of the discontinued LLVM Phabricator instance.

Fix performance problem in long-running SectionMemoryManagers
ClosedPublic

Authored by loladiro on Sep 24 2015, 10:45 PM.

Details

Summary

Without this patch, the memory manager would call mprotect on every memory region it ever allocated whenever it wanted to finalize memory (i.e. not just the ones it just allocated). This caused terrible performance problems for long running memory managers. In one particular compile heavy julia benchmark, we were spending 50% of time in mprotect if running under MCJIT. Fix this by splitting
allocated memory blocks into those on which memory permissions have been set and those on which
they haven't and only running mprotect on the latter.

Diff Detail

Repository
rL LLVM

Event Timeline

loladiro updated this revision to Diff 35701.Sep 24 2015, 10:45 PM
loladiro retitled this revision from to Fix performance problem in long-running SectionMemoryManagers.
loladiro updated this object.
loladiro added a reviewer: lhames.
loladiro set the repository for this revision to rL LLVM.
loladiro added a subscriber: llvm-commits.
reames added a subscriber: reames.Sep 29 2015, 5:50 AM
reames added inline comments.
include/llvm/ExecutionEngine/SectionMemoryManager.h
87 ↗(On Diff #35701)

Comment explaining purpose?

lib/ExecutionEngine/SectionMemoryManager.cpp
169 ↗(On Diff #35701)

I think you need to extend the destructor to handle the case where the memory manager is destructed before finalization.

lhames accepted this revision.Sep 29 2015, 10:38 AM
lhames edited edge metadata.

Pending addressing of Philip's comment this looks great to me. Thanks Keno!

This revision is now accepted and ready to land.Sep 29 2015, 10:38 AM
loladiro added inline comments.Sep 30 2015, 11:34 AM
lib/ExecutionEngine/SectionMemoryManager.cpp
169 ↗(On Diff #35701)

Thanks! I guess we also need to release the FreeMem blocks in here then.

reames added inline comments.Sep 30 2015, 11:36 AM
lib/ExecutionEngine/SectionMemoryManager.cpp
169 ↗(On Diff #35701)

Nope. Be careful with this. FreeMem appears to point inside regions tracked by AllocatedMem

loladiro added inline comments.Sep 30 2015, 11:38 AM
lib/ExecutionEngine/SectionMemoryManager.cpp
169 ↗(On Diff #35701)

I see, thanks!

loladiro updated this revision to Diff 36145.Sep 30 2015, 2:41 PM
loladiro edited edge metadata.

Addresses review comments. @reames let me know if you agree with the wording of the explanatory
comment.

reames accepted this revision.Sep 30 2015, 4:55 PM
reames added a reviewer: reames.

LGTM

lib/ExecutionEngine/SectionMemoryManager.cpp
143 ↗(On Diff #36145)

very minor: I'd put the clear immediately after each append.

This revision was automatically updated to reflect the committed changes.

Thanks for the quick review. Also, while looking at this again, I noticed, we're setting RX permissions on RO memory. Does that sound right? Seems like that memory should be executable? Isn't that the whole point of splitting this?

reames added a comment.Oct 1 2015, 7:20 AM

I assume you meant that we are applying execute permissions to the read
only memory and probably shouldn't be? If so, I tend to agree.
However, I'd have to study the code much more carefully to understand
the implications. There may be an issue with the relocations or something.

Philip