Skip to content

Commit

Permalink
[PartitionAlloc] Remove thread cache purge feature, since it's enabled.
Browse files Browse the repository at this point in the history
The feature has been enabled by default for a while, remove the code
corresponding to it, and clean up a function without any caller.

Bug: 998048
Change-Id: I006cc6ae81309dc0cbc2eaf74172e81374b9ebd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3110605
Reviewed-by: Thiabaud Engelbrecht <thiabaud@google.com>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#913812}
  • Loading branch information
Benoit Lize authored and Chromium LUCI CQ committed Aug 20, 2021
1 parent 2de496d commit 2066b73
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 65 deletions.
42 changes: 23 additions & 19 deletions base/allocator/partition_allocator/extended_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

namespace base {

namespace internal {
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && \
defined(PA_THREAD_CACHE_SUPPORTED)

namespace {

void DisableThreadCacheForRootIfEnabled(ThreadSafePartitionRoot* root) {
// Some platforms don't have a thread cache, or it could already have been
// disabled.
Expand All @@ -31,14 +35,27 @@ void EnablePartitionAllocThreadCacheForRootIfDisabled(
root->with_thread_cache = true;
}

} // namespace internal
void DisablePartitionAllocThreadCacheForProcess() {
auto* regular_allocator = internal::PartitionAllocMalloc::Allocator();
auto* aligned_allocator = internal::PartitionAllocMalloc::AlignedAllocator();
DisableThreadCacheForRootIfEnabled(regular_allocator);
if (aligned_allocator != regular_allocator)
DisableThreadCacheForRootIfEnabled(aligned_allocator);
DisableThreadCacheForRootIfEnabled(
internal::PartitionAllocMalloc::OriginalAllocator());
}

} // namespace

#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) &&
// defined(PA_THREAD_CACHE_SUPPORTED)

void SwapOutProcessThreadCacheForTesting(ThreadSafePartitionRoot* root) {
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && \
defined(PA_THREAD_CACHE_SUPPORTED)
DisablePartitionAllocThreadCacheForProcess();
internal::ThreadCache::SwapForTesting(root);
internal::EnablePartitionAllocThreadCacheForRootIfDisabled(root);
EnablePartitionAllocThreadCacheForRootIfDisabled(root);
#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) &&
// defined(PA_THREAD_CACHE_SUPPORTED)
}
Expand All @@ -47,27 +64,14 @@ void SwapInProcessThreadCacheForTesting(ThreadSafePartitionRoot* root) {
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && \
defined(PA_THREAD_CACHE_SUPPORTED)
// First, disable the test thread cache we have.
internal::DisableThreadCacheForRootIfEnabled(root);
DisableThreadCacheForRootIfEnabled(root);

auto* regular_allocator = base::internal::PartitionAllocMalloc::Allocator();
internal::EnablePartitionAllocThreadCacheForRootIfDisabled(regular_allocator);
auto* regular_allocator = internal::PartitionAllocMalloc::Allocator();
EnablePartitionAllocThreadCacheForRootIfDisabled(regular_allocator);

internal::ThreadCache::SwapForTesting(regular_allocator);
#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) &&
// defined(PA_THREAD_CACHE_SUPPORTED)
}

void DisablePartitionAllocThreadCacheForProcess() {
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
auto* regular_allocator = base::internal::PartitionAllocMalloc::Allocator();
auto* aligned_allocator =
base::internal::PartitionAllocMalloc::AlignedAllocator();
internal::DisableThreadCacheForRootIfEnabled(regular_allocator);
if (aligned_allocator != regular_allocator)
internal::DisableThreadCacheForRootIfEnabled(aligned_allocator);
internal::DisableThreadCacheForRootIfEnabled(
base::internal::PartitionAllocMalloc::OriginalAllocator());
#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
}

} // namespace base
18 changes: 0 additions & 18 deletions base/allocator/partition_allocator/extended_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,6 @@ BASE_EXPORT void SwapOutProcessThreadCacheForTesting(
BASE_EXPORT void SwapInProcessThreadCacheForTesting(
ThreadSafePartitionRoot* root);

// Disables the thread cache for the entire process.
//
// Saves memory but slows down the allocator *significantly*. Only use for
// configurations that are very memory-constrained or performance-insensitive
// processes.
//
// Must preferably be called from the main thread, when no/few threads have
// been started.
//
// Otherwise, there are several things that can happen:
// 1. Another thread is currently temporarily disabling the thread cache, and
// will re-enable it, negating this call's effect.
// 2. Other threads' caches cannot be purged from here, and would retain their
// cached memory until thread destruction (where it is reclaimed).
//
// These are not correctness issues, at worst in the first case, memory is not
// saved, and in the second one, *some* of the memory is leaked.
BASE_EXPORT void DisablePartitionAllocThreadCacheForProcess();
} // namespace base

#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_EXTENDED_API_H_
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ const Feature kPartitionAllocPCScanBrowserOnly{
const Feature kPartitionAllocBackupRefPtrControl{
"PartitionAllocBackupRefPtrControl", FEATURE_DISABLED_BY_DEFAULT};

// If enabled, the thread cache will be periodically purged.
const Feature kPartitionAllocThreadCachePeriodicPurge{
"PartitionAllocThreadCachePeriodicPurge", FEATURE_ENABLED_BY_DEFAULT};

// Use a larger maximum thread cache cacheable bucket size.
const Feature kPartitionAllocLargeThreadCacheSize{
"PartitionAllocLargeThreadCacheSize", FEATURE_DISABLED_BY_DEFAULT};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extern const BASE_EXPORT Feature kPartitionAllocPCScan;
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
extern const BASE_EXPORT Feature kPartitionAllocPCScanBrowserOnly;
extern const BASE_EXPORT Feature kPartitionAllocBackupRefPtrControl;
extern const BASE_EXPORT Feature kPartitionAllocThreadCachePeriodicPurge;
extern const BASE_EXPORT Feature kPartitionAllocLargeThreadCacheSize;
#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)

Expand Down
30 changes: 7 additions & 23 deletions content/common/partition_alloc_support.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "base/allocator/allocator_shim.h"
#include "base/allocator/buildflags.h"
#include "base/allocator/partition_allocator/extended_api.h"
#include "base/allocator/partition_allocator/partition_alloc_config.h"
#include "base/allocator/partition_allocator/partition_alloc_features.h"
#include "base/allocator/partition_allocator/starscan/pcscan.h"
Expand Down Expand Up @@ -203,17 +202,6 @@ void PartitionAllocSupport::ReconfigureAfterFeatureListInit(

#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
base::allocator::ReconfigurePartitionAllocLazyCommit();

#if defined(OS_ANDROID)
// The thread cache consumes more memory. Don't use one on low-memory devices
// if thread cache purging is not enabled.
if (base::SysInfo::IsLowEndDevice() &&
!base::FeatureList::IsEnabled(
base::features::kPartitionAllocThreadCachePeriodicPurge)) {
base::DisablePartitionAllocThreadCacheForProcess();
}
#endif // defined(OS_ANDROID)

#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)

bool scan_enabled = EnablePCScanForMallocPartitionsIfNeeded();
Expand Down Expand Up @@ -263,20 +251,16 @@ void PartitionAllocSupport::ReconfigureAfterTaskRunnerInit(
// initialized later.
DCHECK(process_type != switches::kZygoteProcess);

if (base::FeatureList::IsEnabled(
base::features::kPartitionAllocThreadCachePeriodicPurge)) {
auto& registry = base::internal::ThreadCacheRegistry::Instance();
registry.StartPeriodicPurge();
auto& registry = base::internal::ThreadCacheRegistry::Instance();
registry.StartPeriodicPurge();

#if defined(OS_ANDROID)
// Lower thread cache limits to avoid stranding too much memory in the
// caches.
if (base::SysInfo::IsLowEndDevice()) {
registry.SetThreadCacheMultiplier(
base::internal::ThreadCache::kDefaultMultiplier / 2.);
}
#endif // defined(OS_ANDROID)
// Lower thread cache limits to avoid stranding too much memory in the caches.
if (base::SysInfo::IsLowEndDevice()) {
registry.SetThreadCacheMultiplier(
base::internal::ThreadCache::kDefaultMultiplier / 2.);
}
#endif // defined(OS_ANDROID)

// Renderer processes are more performance-sensitive, increase thread cache
// limits.
Expand Down

0 comments on commit 2066b73

Please sign in to comment.