This is an archive of the discontinued LLVM Phabricator instance.

[SectionMemoryManager] Make better use of virtual memory
ClosedPublic

Authored by loladiro on Dec 3 2015, 1:11 PM.

Details

Summary

On Windows, the allocation granularity can be significantly larger than a page (64K), so with many small objects, just clearing the FreeMem list rapidly leaks quite a bit of virtual memory space (if not rss). Fix that by only removing those parts of the FreeMem blocks that overlap pages for which we are applying memory permissions, rather than dropping the FreeMem blocks entirely.

Diff Detail

Repository
rL LLVM

Event Timeline

loladiro updated this revision to Diff 41792.Dec 3 2015, 1:11 PM
loladiro retitled this revision from to [SectionMemoryManager] Make better use of virtual memory.
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.
loladiro planned changes to this revision.Dec 3 2015, 3:24 PM

Jameson Nash points out to me that on windows you're not allowed to pass ranges that straddle allocation domains to it's version of mprotect, so I'll update the code to take that into account.

loladiro updated this revision to Diff 41881.Dec 4 2015, 8:17 AM

Updated to take into account that we shouldn't merge things across reservation boundaries.
Instead, have a free block keep a reference to any pending block that may be before it
(in the same allocation) and updating that as we go along.

loladiro updated this revision to Diff 41909.Dec 4 2015, 11:54 AM

Remove a method used in the first version that is no longer used now.

lhames edited edge metadata.Dec 4 2015, 2:49 PM

This sounds great.

I don't think we want to change the operations on MemoryBlock though - I'd rather see SectionMemoryManager create new MemoryBlocks representing the ranges you want to change permissions on.

I added trimMemoryBlock to Memory because it depends on the system Page size, but later realized that Process already exposes that, so I would be happy to just make that a static function in the SectionMemoryManager.

loladiro updated this revision to Diff 41959.Dec 4 2015, 4:24 PM
loladiro edited edge metadata.

Make trimBlockToPageSize a static in SectionMemoryManager rather than a new
static member of Memory.

loladiro updated this revision to Diff 41990.Dec 5 2015, 7:04 AM

Fix accidental inclusion of a previous commit in the diff which is already on trunk.

loladiro updated this revision to Diff 41992.Dec 5 2015, 11:18 AM

Used indices rather than pointers into the array, because those can get
invalidated if you're not careful.

@lhames, does this look ok now?

lhames accepted this revision.Dec 15 2015, 10:36 AM
lhames edited edge metadata.

LGTM. Thanks Keno!

This revision is now accepted and ready to land.Dec 15 2015, 10:36 AM
This revision was automatically updated to reflect the committed changes.