summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/scudo/standalone/tsd_shared.h
Commit message (Collapse)AuthorAgeFilesLines
* [scudo][standalone] Fork supportKostya Kortchinsky2020-01-141-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: fork() wasn't well (or at all) supported in Scudo. This materialized in deadlocks in children. In order to properly support fork, we will lock the allocator pre-fork and unlock it post-fork in parent and child. This is done via a `pthread_atfork` call installing the necessary handlers. A couple of things suck here: this function allocates - so this has to be done post initialization as our init path is not reentrance, and it doesn't allow for an extra pointer - so we can't pass the allocator we are currently working with. In order to work around this, I added a post-init template parameter that gets executed once the allocator is initialized for the current thread. Its job for the C wrappers is to install the atfork handlers. I reorganized a bit the impacted area and added some tests, courtesy of cferris@ that were deadlocking prior to this fix. Subscribers: jfb, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D72470
* [scudo][standalone] Implement TSD registry disablingKostya Kortchinsky2019-12-201-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: In order to implement `malloc_{enable|disable}` we were just disabling (or really locking) the Primary and the Secondary. That meant that allocations could still be serviced from the TSD as long as the cache wouldn't have to be filled from the Primary. This wasn't working out for Android tests, so this change implements registry disabling (eg: locking) so that `getTSDAndLock` doesn't return a TSD if the allocator is disabled. This also means that the Primary doesn't have to be disabled in this situation. For the Shared Registry, we loop through all the TSDs and lock them. For the Exclusive Registry, we add a `Disabled` boolean to the Registry that forces `getTSDAndLock` to use the Fallback TSD instead of the thread local one. Disabling the Registry is then done by locking the Fallback TSD and setting the boolean in question (I don't think this needed an atomic variable but I might be wrong). I clang-formatted the whole thing as usual hence the couple of extra whiteline changes in this CL. Reviewers: cferris, pcc, hctim, morehouse, eugenis Subscribers: jfb, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D71719
* scudo: Add a basic malloc/free benchmark.Peter Collingbourne2019-12-091-0/+1
| | | | Differential Revision: https://reviews.llvm.org/D71104
* scudo: Call setCurrentTSD(nullptr) when bringing down the TSD registry in tests.Peter Collingbourne2019-11-271-0/+1
| | | | | | | | | Otherwise, we will hit a use-after-free when testing multiple instances of the same allocator on the same thread. This only recently became a problem with D70552 which caused us to run both ScudoCombinedTest.BasicCombined and ScudoCombinedTest.ReleaseToOS on the unit tests' main thread. Differential Revision: https://reviews.llvm.org/D70760
* scudo: Only use the Android reserved TLS slot when building libc's copy of ↵Peter Collingbourne2019-11-201-4/+4
| | | | | | | | | | | | | | the allocator. When we're not building libc's allocator, just use a regular TLS variable. This lets the unit tests pass on Android devices whose libc uses Scudo. Otherwise libc's copy of Scudo and the unit tests' copy will both try to use the same TLS slot, in likely incompatible ways. This requires using ELF TLS, so start passing -fno-emulated-tls when building the library and the unit tests on Android. Differential Revision: https://reviews.llvm.org/D70472
* [scudo][standalone] Optimization passKostya Kortchinsky2019-07-241-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This introduces a bunch of small optimizations with the purpose of making the fastpath tighter: - tag more conditions as `LIKELY`/`UNLIKELY`: as a rule of thumb we consider that every operation related to the secondary is unlikely - attempt to reduce the number of potentially extraneous instructions - reorganize the `Chunk` header to not straddle a word boundary and use more appropriate types Note that some `LIKELY`/`UNLIKELY` impact might be less obvious as they are in slow paths (for example in `secondary.cc`), but at this point I am throwing a pretty wide net, and it's consistant and doesn't hurt. This was mosly done for the benfit of Android, but other platforms benefit from it too. An aarch64 Android benchmark gives: - before: ``` BM_youtube/min_time:15.000/repeats:4/manual_time_mean 445244 us 659385 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_median 445007 us 658970 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_stddev 885 us 1332 us 4 ``` - after: ``` BM_youtube/min_time:15.000/repeats:4/manual_time_mean 415697 us 621925 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_median 415913 us 622061 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_stddev 990 us 1163 us 4 ``` Additional since `-Werror=conversion` is enabled on some platforms we are built on, enable it upstream to catch things early: a few sign conversions had slept through and needed additional casting. Reviewers: hctim, morehouse, eugenis, vitalybuka Reviewed By: vitalybuka Subscribers: srhines, mgorny, javed.absar, kristof.beyls, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D64664 llvm-svn: 366918
* [scudo][standalone] Merge Spin & Blocking mutex into a Hybrid oneKostya Kortchinsky2019-07-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: We ran into a problem on Fuchsia where yielding threads would never be deboosted, ultimately resulting in several threads spinning on the same TSD, and no possibility for another thread to be scheduled, dead-locking the process. While this was fixed in Zircon, this lead to discussions about if spinning without a break condition was a good decision, and settled on a new hybrid model that would spin for a while then block. Currently we are using a number of iterations for spinning that is mostly arbitrary (based on sanitizer_common values), but this can be tuned in the future. Since we are touching `common.h`, we also use this change as a vehicle for an Android optimization (the page size is fixed in Bionic, so use a fixed value too). Reviewers: morehouse, hctim, eugenis, dvyukov, vitalybuka Reviewed By: hctim Subscribers: srhines, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D64358 llvm-svn: 365790
* [scudo] Correct a behavior on the shared TSD registryKostya Kortchinsky2019-06-251-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: There is an error in the shared TSD registry logic when looking for a TSD in the slow path. There is an unlikely event when a TSD's precedence was 0 after attempting a `tryLock` which indicated that it was grabbed by another thread in between. We dealt with that case by continuing to the next iteration, but that meant that the `Index` was not increased and we ended up trying to lock the same TSD. This would manifest in heavy contention, and in the end we would still lock a TSD, but that was a wasted iteration. So, do not `continue`, just skip the TSD as a potential candidate. This is in both the standalone & non-standalone versions. Reviewers: morehouse, eugenis, vitalybuka, hctim Reviewed By: morehouse Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D63783 llvm-svn: 364345
* [scudo][standalone] Unmap memory in testsKostya Kortchinsky2019-06-111-0/+5
| | | | | | | | | | | | | | | | | | | | | Summary: The more tests are added, the more we are limited by the size of the address space on 32-bit. Implement `unmapTestOnly` all around (like it is in sanitzer_common) to be able to free up some memory. This is not intended to be a proper "destructor" for an allocator, but allows us to not fail due to having no memory left. Reviewers: morehouse, vitalybuka, eugenis, hctim Reviewed By: morehouse Subscribers: delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D63146 llvm-svn: 363095
* [scudo][standalone] Introduce the thread specific data structuresKostya Kortchinsky2019-06-101-0/+166
Summary: This CL adds the structures dealing with thread specific data for the allocator. This includes the thread specific data structure itself and two registries for said structures: an exclusive one, where each thread will have its own TSD struct, and a shared one, where a pool of TSD structs will be shared by all threads, with dynamic reassignment at runtime based on contention. This departs from the current Scudo implementation: we intend to make the Registry a template parameter of the allocator (as opposed to a single global entity), allowing various allocators to coexist with different TSD registry models. As a result, TSD registry and Allocator are tightly coupled. This also corrects a couple of things in other files that I noticed while adding this. Reviewers: eugenis, vitalybuka, morehouse, hctim Reviewed By: morehouse Subscribers: srhines, mgorny, delcypher, jfb, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D62258 llvm-svn: 362962
OpenPOWER on IntegriCloud