Skip to content

Commit

Permalink
[scudo] Quarantine optimization
Browse files Browse the repository at this point in the history
Summary:
It turns out that the previous code construct was not optimizing the allocation
and deallocation of batches. The class id was read as a class member (even
though a precomputed one) and nothing else was optimized. By changing the
construct this way, the compiler actually optimizes most of the allocation and
deallocation away to only work with a single class id, which not only saves some
CPU but also some code footprint.

Reviewers: alekseyshl, dvyukov

Reviewed By: dvyukov

Subscribers: dvyukov, delcypher, llvm-commits, #sanitizers

Differential Revision: https://reviews.llvm.org/D46961

llvm-svn: 332502
  • Loading branch information
Kostya Kortchinsky committed May 16, 2018
1 parent 332bbb0 commit e5c9e9f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler-rt/lib/scudo/scudo_allocator.cpp
Expand Up @@ -197,16 +197,17 @@ struct QuarantineCallback {
// that the batches are indeed serviced by the Primary.
// TODO(kostyak): figure out the best way to protect the batches.
void *Allocate(uptr Size) {
const uptr BatchClassId = SizeClassMap::ClassID(sizeof(QuarantineBatch));
return getBackendAllocator().allocatePrimary(Cache_, BatchClassId);
}

void Deallocate(void *Ptr) {
const uptr BatchClassId = SizeClassMap::ClassID(sizeof(QuarantineBatch));
getBackendAllocator().deallocatePrimary(Cache_, Ptr, BatchClassId);
}

AllocatorCache *Cache_;
COMPILER_CHECK(sizeof(QuarantineBatch) < SizeClassMap::kMaxSize);
const uptr BatchClassId = SizeClassMap::ClassID(sizeof(QuarantineBatch));
};

typedef Quarantine<QuarantineCallback, void> ScudoQuarantine;
Expand Down

0 comments on commit e5c9e9f

Please sign in to comment.