[compiler-rt] r224469 - [sanitizer] add CombinedAllocator::InitIfLinkerInitialized and use it in lsan: speeds up lsan start-up time by ~25%
Sergey Matveev
earthdok at google.com
Fri Dec 19 04:22:54 PST 2014
On Fri, Dec 19, 2014 at 5:45 AM, Kostya Serebryany <kcc at google.com> wrote:
>
>
>
> On Thu, Dec 18, 2014 at 10:58 AM, Alexey Samsonov <vonosmas at gmail.com>
> wrote:
>>
>> Do you plan to call InitIfLinkerInitialized() to another sanitizers that
>> use linker-initialized allocator (e.g. ASan)?
>>
> for other sanitizers this is much less of a problem, but it clearly won't
> hurt.
>
> >> I find the name misleading. It implies that the function checks
> whether we've been linker-initialized. Maybe InitAfterLinkerInitialized? Or
> simply InitLinkerInitialized?
>
> Err. Bike shedding. If you feel strongly, please rename to
> InitLinkerInitialized
>
I commented only because it took me way too long to figure out what this
patch did, due to the confusing name. I'll fix it.
>
>
>
>>
>> On Wed, Dec 17, 2014 at 3:06 PM, Kostya Serebryany <kcc at google.com>
>> wrote:
>>>
>>> Author: kcc
>>> Date: Wed Dec 17 17:06:36 2014
>>> New Revision: 224469
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=224469&view=rev
>>> Log:
>>> [sanitizer] add CombinedAllocator::InitIfLinkerInitialized and use it in
>>> lsan: speeds up lsan start-up time by ~25%
>>>
>>> Modified:
>>> compiler-rt/trunk/lib/lsan/lsan_allocator.cc
>>> compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
>>>
>>> Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.cc
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.cc?rev=224469&r1=224468&r2=224469&view=diff
>>>
>>> ==============================================================================
>>> --- compiler-rt/trunk/lib/lsan/lsan_allocator.cc (original)
>>> +++ compiler-rt/trunk/lib/lsan/lsan_allocator.cc Wed Dec 17 17:06:36 2014
>>> @@ -47,7 +47,7 @@ static Allocator allocator;
>>> static THREADLOCAL AllocatorCache cache;
>>>
>>> void InitializeAllocator() {
>>> - allocator.Init(common_flags()->allocator_may_return_null);
>>> +
>>> allocator.InitIfLinkerInitialized(common_flags()->allocator_may_return_null);
>>> }
>>>
>>> void AllocatorThreadFinish() {
>>>
>>> Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h?rev=224469&r1=224468&r2=224469&view=diff
>>>
>>> ==============================================================================
>>> --- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h
>>> (original)
>>> +++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator.h Wed Dec
>>> 17 17:06:36 2014
>>> @@ -211,6 +211,7 @@ class AllocatorStats {
>>> void Init() {
>>> internal_memset(this, 0, sizeof(*this));
>>> }
>>> + void InitIfLinkerInitialized() {}
>>>
>>> void Add(AllocatorStat i, uptr v) {
>>> v += atomic_load(&stats_[i], memory_order_relaxed);
>>> @@ -240,11 +241,14 @@ class AllocatorStats {
>>> // Global stats, used for aggregation and querying.
>>> class AllocatorGlobalStats : public AllocatorStats {
>>> public:
>>> - void Init() {
>>> - internal_memset(this, 0, sizeof(*this));
>>> + void InitIfLinkerInitialized() {
>>> next_ = this;
>>> prev_ = this;
>>> }
>>> + void Init() {
>>> + internal_memset(this, 0, sizeof(*this));
>>> + InitIfLinkerInitialized();
>>> + }
>>>
>>> void Register(AllocatorStats *s) {
>>> SpinMutexLock l(&mu_);
>>> @@ -1002,12 +1006,16 @@ struct SizeClassAllocatorLocalCache {
>>> template <class MapUnmapCallback = NoOpMapUnmapCallback>
>>> class LargeMmapAllocator {
>>> public:
>>> - void Init(bool may_return_null) {
>>> - internal_memset(this, 0, sizeof(*this));
>>> + void InitIfLinkerInitialized(bool may_return_null) {
>>> page_size_ = GetPageSizeCached();
>>> atomic_store(&may_return_null_, may_return_null,
>>> memory_order_relaxed);
>>> }
>>>
>>> + void Init(bool may_return_null) {
>>> + internal_memset(this, 0, sizeof(*this));
>>> + InitIfLinkerInitialized(may_return_null);
>>> + }
>>> +
>>> void *Allocate(AllocatorStats *stat, uptr size, uptr alignment) {
>>> CHECK(IsPowerOfTwo(alignment));
>>> uptr map_size = RoundUpMapSize(size);
>>> @@ -1253,11 +1261,21 @@ template <class PrimaryAllocator, class
>>> class SecondaryAllocator> // NOLINT
>>> class CombinedAllocator {
>>> public:
>>> - void Init(bool may_return_null) {
>>> + void InitCommon(bool may_return_null) {
>>> primary_.Init();
>>> + atomic_store(&may_return_null_, may_return_null,
>>> memory_order_relaxed);
>>> + }
>>> +
>>> + void InitIfLinkerInitialized(bool may_return_null) {
>>> + secondary_.InitIfLinkerInitialized(may_return_null);
>>> + stats_.InitIfLinkerInitialized();
>>> + InitCommon(may_return_null);
>>> + }
>>> +
>>> + void Init(bool may_return_null) {
>>> secondary_.Init(may_return_null);
>>> stats_.Init();
>>> - atomic_store(&may_return_null_, may_return_null,
>>> memory_order_relaxed);
>>> + InitCommon(may_return_null);
>>> }
>>>
>>> void *Allocate(AllocatorCache *cache, uptr size, uptr alignment,
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>
>>
>>
>> --
>> Alexey Samsonov
>> vonosmas at gmail.com
>>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141219/08e850b5/attachment.html>
More information about the llvm-commits
mailing list