summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_allocator_local_cache.h
AgeCommit message (Collapse)Author
2017-08-28[sanitizer] Re-introduce kUseSeparateSizeClassForBatch for the 32-bit PrimaryKostya Kortchinsky
Summary: Currently `TransferBatch` are located within the same memory regions as "regular" chunks. This is not ideal for security: they make for an interesting target to overwrite, and are not protected by the frontend (namely, Scudo). To solve this, we re-introduce `kUseSeparateSizeClassForBatch` for the 32-bit Primary allowing for `TransferBatch` to end up in their own memory region. Currently only Scudo would use this new feature, the default behavior remains unchanged. The separate `kBatchClassID` was used for a brief period of time previously but removed when the 64-bit ended up using the "free array". Reviewers: alekseyshl, kcc, eugenis Reviewed By: alekseyshl Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D37082 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@311891 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-26[Sanitizers] 64 bit allocator respects allocator_may_return_null flagAlex Shlyapnikov
Summary: Make SizeClassAllocator64 return nullptr when it encounters OOM, which allows the entire sanitizer's allocator to follow allocator_may_return_null=1 policy (LargeMmapAllocator: D34243, SizeClassAllocator64: D34433). Reviewers: eugenis Subscribers: srhines, kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D34540 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@306342 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-22[Sanitizers] 32 bit allocator respects allocator_may_return_null flagAlex Shlyapnikov
Summary: Make SizeClassAllocator32 return nullptr when it encounters OOM, which allows the entire sanitizer's allocator to follow allocator_may_return_null=1 policy, even for small allocations (LargeMmapAllocator is already fixed by D34243). Will add a test for OOM in primary allocator later, when SizeClassAllocator64 can gracefully handle OOM too. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D34433 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@305972 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-24[sanitizer] Cache SizeClassForTransferBatch in the 32-bit local cacheKostya Kortchinsky
Summary: `SizeClassForTransferBatch` is expensive and is called for every `CreateBatch` and `DestroyBatch`. Caching it means `kNumClasses` calls in `InitCache` instead. This should be a performance gain if more than `kNumClasses / 2` batches are created and destroyed during the lifetime of the local cache. I have chosen to fully remove the function and putting the code in `InitCache`, which is a debatable choice. In single threaded benchmarks leveraging primary backed allocations, this turns out to be a sizeable gain in performances (greater than 5%). In multithreaded benchmarks leveraging everything, it is less significant but still an improvement (about 1%). Reviewers: kcc, dvyukov, alekseyshl Reviewed By: dvyukov Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D32365 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301184 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-13Cache size per class size in SizeClassAllocatorXLocalCache.Alex Shlyapnikov
Summary: Allocator::ClassIdToSize() is not free and calling it in every Allocate/Deallocate has noticeable impact on perf. Reapplying D31991 with the appropriate fixes. Reviewers: cryptoad Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D32024 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300216 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-13Revert "Cache size per class size in SizeClassAllocatorXLocalCache."Diana Picus
This reverts commit r300107 because it broke the ARM and AArch64 buildbots. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300180 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-12Cache size per class size in SizeClassAllocatorXLocalCache.Alex Shlyapnikov
Summary: Allocator::ClassIdToSize() is not free and calling it in every Allocate/Deallocate has noticeable impact on perf. Reviewers: eugenis, kcc Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D31991 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300107 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-12Avoid calling SizeClassMap::MaxCachedHint on hot path, it's not free.Alex Shlyapnikov
Summary: Remove unecessary SizeClassMap::MaxCachedHint call. Reviewers: eugenis Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D31989 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@300103 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-31[sanitizer] remove kBatchClassID that is not used any more; NFCKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@280185 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24[sanitizer] re-apply r279572 and r279595 reverted in r279643: change the ↵Kostya Serebryany
64-bit allocator to use a single array for free-d chunks instead of a lock-free linked list of tranfer batches. This change simplifies the code, makes the allocator more 'hardened', and will allow simpler code to release RAM to OS. This may also slowdown malloc stress tests due to lock contension, but I did not observe noticeable slowdown on various real multi-threaded benchmarks. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@279664 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-24Revert r279572 "[sanitizer] change the 64-bit..." because of failures on ubsanVitaly Buka
This reverts commit r279572 and r279595. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@279643 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23[sanitizer] change the 64-bit allocator to use a single array for free-d ↵Kostya Serebryany
chunks instead of a lock-free linked list of tranfer batches. This change simplifies the code, makes the allocator more 'hardened', and will allow simpler code to release RAM to OS. This may also slowdown malloc stress tests due to lock contension, but I did not observe noticeable slowdown on various real multi-threaded benchmarks. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@279572 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-23[sanitizer] allocator: split the local cache class into two, one for 32-bit ↵Kostya Serebryany
allocator and one for 64-bit one. NFC. The two imlementations will diverge in the following changes. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@279495 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-09[sanitizer] use 32-bit offset instead of 64-bit pointers in the 64-bit ↵Kostya Serebryany
allocator's transfer batches. This saves 2x memory for the transfer batches (up to ~1.5% overall in some cases) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@278179 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-09[sanitizer] minor refactoring in the allocator, NFCKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@278163 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-06[sanitizer] allocator: move TransferBatch into ↵Kostya Serebryany
SizeClassAllocator64/SizeClassAllocator32 because we actually need different iplementations for the 64- and 32-bit case. NFC; the following patches will make the TransferBatch implementations differ git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277899 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-03[sanitizer] remove one redundant loop from the allocatorKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277563 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-03[sanitizer] refactor TransferBatch to hide the implementation. NFC expected. ↵Kostya Serebryany
Second attempt after failed r276383 which was reverted. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277554 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-22[sanitizer] revert r276383 while investigating failures on botKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276456 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-22[sanitizer] refactor TransferBatch to hide the implementation. NFCKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276383 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-22[sanitizer] allocator: introduce kUseSeparateSizeClassForBatch (false by ↵Kostya Serebryany
default). When true, it will cause all TransferBatches to be allocated on a separate dedicated size class, which improves security and may potentially simplify memory reclamation. However in the current state this may cause up to 3% extra memory usage. Subsequent changes should bring this overhead down git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276377 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-21[sanitizer] allocator: remove kPopulateSize and only use ↵Kostya Serebryany
SizeClassMap::MaxCached; ensure that TransferBatch size is a power of two, refactor TransferBatch creation/destruction into separate functions. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276318 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-20[sanitizers] split sanitizer_allocator.h into a number of smaller .h files; NFCKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@276195 91177308-0d34-0410-b5e6-96231b3b80d8