This is an archive of the discontinued LLVM Phabricator instance.

[scudo][standalone] Add a free list to the Secondary
ClosedPublic

Authored by cryptoad on Oct 29 2019, 9:42 AM.

Details

Summary

The secondary allocator is slow, because we map and unmap each block
on allocation and deallocation.

While I really like the security benefits of such a behavior, this
yields very disappointing performance numbers on Android for larger
allocation benchmarks.

So this change adds a free list to the secondary, that will hold
recently deallocated chunks, and (currently) release the extraneous
memory. This allows to save on some memory mapping operations on
allocation and deallocation. I do not think that this lowers the
security of the secondary, but can increase the memory footprint a
little bit (RSS & VA).

The maximum number of blocks the free list can hold is templatable,
0U meaning that we fallback to the old behavior. The higher that
number, the higher the extra memory footprint.

I added default configurations for all our platforms, but they are
likely to change in the near future based on needs and feedback.

Diff Detail

Event Timeline

cryptoad created this revision.Oct 29 2019, 9:42 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 29 2019, 9:42 AM
Herald added subscribers: Restricted Project, mgorny. · View Herald Transcript
morehouse accepted this revision.Oct 29 2019, 6:29 PM
morehouse added inline comments.
compiler-rt/lib/scudo/standalone/secondary.h
222

Nit: From is a bit ambiguous. Maybe AllocationStart is more precise?

228

This does not release the header page, but we still reduce StatAllocated by CommitSize, which includes the the header page. Is this intended?

This revision is now accepted and ready to land.Oct 29 2019, 6:29 PM
cryptoad updated this revision to Diff 227097.Oct 30 2019, 7:56 AM
cryptoad marked 3 inline comments as done.

Renaming the variable From to RoundedAllocationStart.

This revision was automatically updated to reflect the committed changes.
cryptoad added inline comments.Oct 30 2019, 9:21 AM
compiler-rt/lib/scudo/standalone/secondary.h
228

This is intended. I chose the value that would always be consistent between allocations & deallocations so that there is no discrepancy later one.
I initially used sizes that were closer to the actual user size but ended up with FreedBytes > AllocatedBytes and messed up stats.

compiler-rt/lib/scudo/standalone/secondary.h