
Summary: This change simplifies the XRay Allocator implementation to self-manage an mmap'ed memory segment instead of using the internal allocator implementation in sanitizer_common. We've found through benchmarks and profiling these benchmarks in D48879 that using the internal allocator in sanitizer_common introduces a bottleneck on allocating memory through a central spinlock. This change allows thread-local allocators to eliminate contention on the centralized allocator. To get the most benefit from this approach, we also use a managed allocator for the chunk elements used by the segmented array implementation. This gives us the chance to amortize the cost of allocating memory when creating these internal segmented array data structures. We also took the opportunity to remove the preallocation argument from the allocator API, simplifying the usage of the allocator throughout the profiling implementation. In this change we also tweak some of the flag values to reduce the amount of maximum memory we use/need for each thread, when requesting memory through mmap. Depends on D48956. Reviewers: kpw, eizan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D49217 llvm-svn: 337342
43 lines
1.0 KiB
C++
43 lines
1.0 KiB
C++
//===-- allocator_test.cc -------------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file is a part of XRay, a function call tracing system.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "xray_allocator.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace __xray {
|
|
namespace {
|
|
|
|
struct TestData {
|
|
s64 First;
|
|
s64 Second;
|
|
};
|
|
|
|
TEST(AllocatorTest, Construction) { Allocator<sizeof(TestData)> A(2 << 11); }
|
|
|
|
TEST(AllocatorTest, Allocate) {
|
|
Allocator<sizeof(TestData)> A(2 << 11);
|
|
auto B = A.Allocate();
|
|
ASSERT_NE(B.Data, nullptr);
|
|
}
|
|
|
|
TEST(AllocatorTest, OverAllocate) {
|
|
Allocator<sizeof(TestData)> A(sizeof(TestData));
|
|
auto B1 = A.Allocate();
|
|
(void)B1;
|
|
auto B2 = A.Allocate();
|
|
ASSERT_EQ(B2.Data, nullptr);
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace __xray
|