Skip to content

Commit

Permalink
partition_alloc: Move PartitionAlloc into the own namespaces (18 of N)
Browse files Browse the repository at this point in the history
Moves the PartitionAlloc APIs and implementations into the own
namespaces (partition_alloc and partition_alloc::internal).

This patch moves ThreadCache, ThreadCacheRegistry, etc.

Bug: 1288247
Change-Id: I44c19d35b5486d94e691315d30c9a5f2350ddf31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3534984
Reviewed-by: Bartek Nowierski <bartekn@chromium.org>
Reviewed-by: Benoit Lize <lizeb@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/main@{#984708}
  • Loading branch information
yuki3 authored and Chromium LUCI CQ committed Mar 24, 2022
1 parent bd64840 commit b73cb56
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 190 deletions.
4 changes: 2 additions & 2 deletions base/allocator/partition_alloc_support.cc
Expand Up @@ -148,7 +148,7 @@ namespace {

void RunThreadCachePeriodicPurge() {
TRACE_EVENT0("memory", "PeriodicPurge");
auto& instance = internal::ThreadCacheRegistry::Instance();
auto& instance = ::partition_alloc::ThreadCacheRegistry::Instance();
instance.RunPeriodicPurge();
TimeDelta delay =
Microseconds(instance.GetPeriodicPurgeNextIntervalInMicroseconds());
Expand All @@ -175,7 +175,7 @@ void RunMemoryReclaimer(scoped_refptr<SequencedTaskRunner> task_runner) {
} // namespace

void StartThreadCachePeriodicPurge() {
auto& instance = internal::ThreadCacheRegistry::Instance();
auto& instance = ::partition_alloc::ThreadCacheRegistry::Instance();
TimeDelta delay =
Microseconds(instance.GetPeriodicPurgeNextIntervalInMicroseconds());
ThreadTaskRunnerHandle::Get()->PostDelayedTask(
Expand Down
2 changes: 1 addition & 1 deletion base/allocator/partition_allocator/memory_reclaimer.cc
Expand Up @@ -81,7 +81,7 @@ void MemoryReclaimer::Reclaim(int flags) {
// as there is periodic purge which makes sure that it doesn't take too much
// space.
if (flags & PurgeFlags::kAggressiveReclaim)
base::internal::ThreadCacheRegistry::Instance().PurgeAll();
ThreadCacheRegistry::Instance().PurgeAll();
#endif

for (auto* partition : partitions_)
Expand Down
Expand Up @@ -118,12 +118,12 @@ TEST_F(MemoryReclaimerTest, DoNotAlwaysPurgeThreadCache) {
base::internal::PartitionAllocMalloc::Allocator()
->EnableThreadCacheIfSupported();

for (size_t i = 0; i < internal::ThreadCache::kDefaultSizeThreshold; i++) {
for (size_t i = 0; i < ThreadCache::kDefaultSizeThreshold; i++) {
void* data = malloc(i);
FreeForTest(data);
}

auto* tcache = internal::ThreadCache::Get();
auto* tcache = ThreadCache::Get();
ASSERT_TRUE(tcache);
size_t cached_size = tcache->CachedMemory();

Expand Down
33 changes: 17 additions & 16 deletions base/allocator/partition_allocator/partition_alloc_perftest.cc
Expand Up @@ -28,7 +28,8 @@
#define MEMORY_CONSTRAINED
#endif

namespace base {
namespace partition_alloc::internal {

namespace {

// Change kTimeLimit to something higher if you need more time to capture a
Expand Down Expand Up @@ -118,7 +119,7 @@ class PartitionAllocatorWithThreadCache : public Allocator {
PartitionOptions::UseConfigurablePool::kNo,
});
}
internal::ThreadCacheRegistry::Instance().PurgeAll();
ThreadCacheRegistry::Instance().PurgeAll();
if (!use_alternate_bucket_dist)
g_partition_root->SwitchToDenserBucketDistribution();
}
Expand All @@ -131,22 +132,22 @@ class PartitionAllocatorWithThreadCache : public Allocator {
void Free(void* data) override { ThreadSafePartitionRoot::FreeNoHooks(data); }
};

class TestLoopThread : public PlatformThread::Delegate {
class TestLoopThread : public base::PlatformThread::Delegate {
public:
explicit TestLoopThread(OnceCallback<float()> test_fn)
explicit TestLoopThread(base::OnceCallback<float()> test_fn)
: test_fn_(std::move(test_fn)) {
PA_CHECK(PlatformThread::Create(0, this, &thread_handle_));
PA_CHECK(base::PlatformThread::Create(0, this, &thread_handle_));
}

float Run() {
PlatformThread::Join(thread_handle_);
base::PlatformThread::Join(thread_handle_);
return laps_per_second_;
}

void ThreadMain() override { laps_per_second_ = std::move(test_fn_).Run(); }

OnceCallback<float()> test_fn_;
PlatformThreadHandle thread_handle_;
base::OnceCallback<float()> test_fn_;
base::PlatformThreadHandle thread_handle_;
std::atomic<float> laps_per_second_;
};

Expand Down Expand Up @@ -181,7 +182,7 @@ float SingleBucket(Allocator* allocator) {
reinterpret_cast<MemoryAllocationPerfNode*>(allocator->Alloc(kAllocSize));
size_t allocated_memory = kAllocSize;

LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
base::LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
MemoryAllocationPerfNode* cur = first;
do {
auto* next = reinterpret_cast<MemoryAllocationPerfNode*>(
Expand Down Expand Up @@ -214,7 +215,7 @@ float SingleBucketWithFree(Allocator* allocator) {
// Allocate an initial element to make sure the bucket stays set up.
void* elem = allocator->Alloc(kAllocSize);

LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
base::LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
do {
void* cur = allocator->Alloc(kAllocSize);
CHECK_NE(cur, nullptr);
Expand All @@ -233,7 +234,7 @@ float MultiBucket(Allocator* allocator) {
MemoryAllocationPerfNode* cur = first;
size_t allocated_memory = kAllocSize;

LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
base::LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
do {
for (int i = 0; i < kMultiBucketRounds; i++) {
size_t size = kMultiBucketMinimumSize + (i * kMultiBucketIncrement);
Expand Down Expand Up @@ -275,7 +276,7 @@ float MultiBucketWithFree(Allocator* allocator) {
elems.push_back(cur);
}

LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
base::LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
do {
for (int i = 0; i < kMultiBucketRounds; i++) {
void* cur = allocator->Alloc(kMultiBucketMinimumSize +
Expand All @@ -296,7 +297,7 @@ float MultiBucketWithFree(Allocator* allocator) {
float DirectMapped(Allocator* allocator) {
constexpr size_t kSize = 2 * 1000 * 1000;

LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
base::LapTimer timer(kWarmupRuns, kTimeLimit, kTimeCheckInterval);
do {
void* cur = allocator->Alloc(kSize);
CHECK_NE(cur, nullptr);
Expand Down Expand Up @@ -340,13 +341,13 @@ void RunTest(int thread_count,
std::unique_ptr<TestLoopThread> noisy_neighbor_thread = nullptr;
if (noisy_neighbor_fn) {
noisy_neighbor_thread = std::make_unique<TestLoopThread>(
BindOnce(noisy_neighbor_fn, Unretained(alloc.get())));
base::BindOnce(noisy_neighbor_fn, base::Unretained(alloc.get())));
}

std::vector<std::unique_ptr<TestLoopThread>> threads;
for (int i = 0; i < thread_count; ++i) {
threads.push_back(std::make_unique<TestLoopThread>(
BindOnce(test_fn, Unretained(alloc.get()))));
base::BindOnce(test_fn, base::Unretained(alloc.get()))));
}

uint64_t total_laps_per_second = 0;
Expand Down Expand Up @@ -452,4 +453,4 @@ TEST_P(PartitionAllocMemoryAllocationPerfTest,

} // namespace

} // namespace base
} // namespace partition_alloc::internal
1 change: 1 addition & 0 deletions base/allocator/partition_allocator/partition_root.h
Expand Up @@ -1949,6 +1949,7 @@ namespace partition_alloc {
// the migration to the new namespaces gets done.
using ::base::PartitionOptions;
using ::base::PurgeFlags;
using ::base::ThreadSafePartitionRoot;

namespace internal {

Expand Down

0 comments on commit b73cb56

Please sign in to comment.