This is an archive of the discontinued LLVM Phabricator instance.

[hwasan] Madvise away thread aux data
ClosedPublic

Authored by eugenis on Jan 11 2019, 4:19 PM.

Details

Summary

Release memory pages for thread data (allocator cache, stack allocations
ring buffer, etc) when a thread exits. We can not simply munmap them
because this memory is custom allocated within a limited address range,
and it needs to stay "reserved".

Diff Detail

Repository
rL LLVM

Event Timeline

eugenis created this revision.Jan 11 2019, 4:19 PM

This one is hard to test reliably for RSS change, because it only affect thread exit, and, generally, we don't know how much memory the platform thread support would release in that event, and it might even be a different amount for different threads (some kind of stack caching, etc).

We don't rely on ReleaseMemoryPagesToOS clearing memory here, so this an almost side-effect-free optimization.

PTAL.

pcc added inline comments.Jan 18 2019, 7:24 PM
compiler-rt/lib/hwasan/hwasan_thread_list.h
186 ↗(On Diff #181389)

Would it help to release memory starting from the original value of free_space_ here? It seems that you would be able to probabilistically free a fraction of a page more that way. Or am I missing something?

eugenis updated this revision to Diff 183194.Jan 23 2019, 3:05 PM

madvise the entire allocation range

eugenis marked an inline comment as done.Jan 23 2019, 3:05 PM
pcc accepted this revision.Jan 24 2019, 5:57 PM

LGTM

compiler-rt/lib/hwasan/hwasan_thread_list.h
146 ↗(On Diff #183194)

Remove FIXME.

This revision is now accepted and ready to land.Jan 24 2019, 5:57 PM
This revision was automatically updated to reflect the committed changes.