mirror of
https://github.com/klzgrad/naiveproxy.git
synced 2024-11-24 06:16:30 +03:00
Simplify partition_alloc_support
This commit is contained in:
parent
c86d7bb91e
commit
8f11f75564
@ -49,6 +49,9 @@ flags="$flags"'
|
||||
enable_reporting=false
|
||||
include_transport_security_state_preload_list=false
|
||||
use_nss_certs=false
|
||||
|
||||
enable_backup_ref_ptr_support=false
|
||||
enable_dangling_raw_ptr_checks=false
|
||||
'
|
||||
|
||||
if [ "$WITH_SYSROOT" ]; then
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/allocator/partition_alloc_support.h"
|
||||
#include "base/at_exit.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/feature_list.h"
|
||||
@ -145,7 +146,9 @@ class MultipleListenCollector : public base::DuplicateSwitchHandler {
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::string>& GetAllValues() const { return all_values_; }
|
||||
const std::vector<std::string>& GetAllValues() const {
|
||||
return all_values_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> all_values_;
|
||||
@ -539,7 +542,8 @@ int main(int argc, char* argv[]) {
|
||||
net::HttpNetworkSession::NORMAL_SOCKET_POOL,
|
||||
kDefaultMaxSocketsPerGroup * kExpectedMaxUsers);
|
||||
|
||||
naive_partition_alloc_support::ReconfigureAfterFeatureListInit();
|
||||
base::allocator::PartitionAllocSupport::Get()
|
||||
->ReconfigureAfterFeatureListInit(/*process_type=*/"");
|
||||
|
||||
#if BUILDFLAG(IS_APPLE)
|
||||
base::mac::ScopedNSAutoreleasePool pool;
|
||||
@ -576,7 +580,8 @@ int main(int argc, char* argv[]) {
|
||||
base::SingleThreadTaskExecutor io_task_executor(base::MessagePumpType::IO);
|
||||
base::ThreadPoolInstance::CreateAndStartWithDefaultParams("naive");
|
||||
|
||||
naive_partition_alloc_support::ReconfigureAfterTaskRunnerInit();
|
||||
base::allocator::PartitionAllocSupport::Get()
|
||||
->ReconfigureAfterTaskRunnerInit(/*process_type=*/"");
|
||||
|
||||
if (!params.ssl_key_path.empty()) {
|
||||
net::SSLClientSocket::SetSSLKeyLogger(
|
||||
|
@ -5,30 +5,13 @@
|
||||
|
||||
#include "net/tools/naive/partition_alloc_support.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/allocator/allocator_check.h"
|
||||
#include "base/allocator/buildflags.h"
|
||||
#include "base/allocator/partition_alloc_features.h"
|
||||
#include "base/allocator/partition_alloc_support.h"
|
||||
#include "base/allocator/partition_allocator/partition_alloc_config.h"
|
||||
#include "base/allocator/partition_allocator/shim/allocator_shim.h"
|
||||
#include "base/allocator/partition_allocator/shim/allocator_shim_default_dispatch_to_partition_alloc.h"
|
||||
#include "base/allocator/partition_allocator/thread_cache.h"
|
||||
#include "base/feature_list.h"
|
||||
#include "base/check.h"
|
||||
#include "base/process/memory.h"
|
||||
#include "base/time/time.h"
|
||||
#include "build/build_config.h"
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
#include "base/system/sys_info.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
#include "base/allocator/partition_allocator/memory_reclaimer.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_APPLE)
|
||||
#include "base/allocator/early_zone_registration_mac.h"
|
||||
#endif
|
||||
@ -62,9 +45,8 @@ void ReconfigureEarly() {
|
||||
// ReconfigureEarlyish():
|
||||
// These initializations are only relevant for PartitionAlloc-Everywhere
|
||||
// builds.
|
||||
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
allocator_shim::EnablePartitionAllocMemoryReclaimer();
|
||||
#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
base::allocator::PartitionAllocSupport::Get()->ReconfigureEarlyish(
|
||||
/*process_type=*/"");
|
||||
|
||||
// content/app/content_main.cc: RunContentProcess()
|
||||
// content/app/content_main_runner_impl.cc: Initialize()
|
||||
@ -75,96 +57,4 @@ void ReconfigureEarly() {
|
||||
CHECK(base::allocator::IsAllocatorInitialized());
|
||||
}
|
||||
|
||||
void ReconfigureAfterFeatureListInit() {
|
||||
// TODO(bartekn): Switch to DCHECK once confirmed there are no issues.
|
||||
CHECK(base::FeatureList::GetInstance());
|
||||
|
||||
// Does not use any of the security features yet.
|
||||
[[maybe_unused]] bool enable_brp = false;
|
||||
[[maybe_unused]] bool enable_memory_tagging = false;
|
||||
[[maybe_unused]] bool split_main_partition = false;
|
||||
[[maybe_unused]] bool use_dedicated_aligned_partition = false;
|
||||
[[maybe_unused]] bool process_affected_by_brp_flag = false;
|
||||
|
||||
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
auto bucket_distribution = allocator_shim::BucketDistribution::kNeutral;
|
||||
// No specified type means we are in the browser.
|
||||
switch (base::features::kPartitionAllocBucketDistributionParam.Get()) {
|
||||
case base::features::BucketDistributionMode::kDefault:
|
||||
break;
|
||||
case base::features::BucketDistributionMode::kDenser:
|
||||
bucket_distribution = allocator_shim::BucketDistribution::kDenser;
|
||||
break;
|
||||
}
|
||||
|
||||
allocator_shim::ConfigurePartitions(
|
||||
allocator_shim::EnableBrp(enable_brp),
|
||||
allocator_shim::EnableMemoryTagging(enable_memory_tagging),
|
||||
partition_alloc::TagViolationReportingMode::kDisabled,
|
||||
allocator_shim::SplitMainPartition(split_main_partition),
|
||||
allocator_shim::UseDedicatedAlignedPartition(
|
||||
use_dedicated_aligned_partition),
|
||||
/*ref_count_size=*/0, bucket_distribution);
|
||||
#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
|
||||
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
allocator_shim::internal::PartitionAllocMalloc::Allocator()
|
||||
->EnableThreadCacheIfSupported();
|
||||
|
||||
if (base::FeatureList::IsEnabled(
|
||||
base::features::kPartitionAllocLargeEmptySlotSpanRing)) {
|
||||
allocator_shim::internal::PartitionAllocMalloc::Allocator()
|
||||
->EnableLargeEmptySlotSpanRing();
|
||||
allocator_shim::internal::PartitionAllocMalloc::AlignedAllocator()
|
||||
->EnableLargeEmptySlotSpanRing();
|
||||
}
|
||||
#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
}
|
||||
|
||||
void ReconfigureAfterTaskRunnerInit() {
|
||||
#if defined(PA_THREAD_CACHE_SUPPORTED) && \
|
||||
BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
base::allocator::StartThreadCachePeriodicPurge();
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
// Lower thread cache limits to avoid stranding too much memory in the caches.
|
||||
if (base::SysInfo::IsLowEndDevice()) {
|
||||
::partition_alloc::ThreadCacheRegistry::Instance().SetThreadCacheMultiplier(
|
||||
::partition_alloc::ThreadCache::kDefaultMultiplier / 2.);
|
||||
}
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
// Renderer processes are more performance-sensitive, increase thread cache
|
||||
// limits.
|
||||
if (/*is_performance_sensitive=*/true &&
|
||||
base::FeatureList::IsEnabled(
|
||||
base::features::kPartitionAllocLargeThreadCacheSize)) {
|
||||
size_t largest_cached_size =
|
||||
::partition_alloc::ThreadCacheLimits::kLargeSizeThreshold;
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS)
|
||||
// Devices almost always report less physical memory than what they actually
|
||||
// have, so anything above 3GiB will catch 4GiB and above.
|
||||
if (base::SysInfo::AmountOfPhysicalMemoryMB() <= 3500)
|
||||
largest_cached_size =
|
||||
::partition_alloc::ThreadCacheLimits::kDefaultSizeThreshold;
|
||||
#endif // BUILDFLAG(IS_ANDROID) && !defined(ARCH_CPU_64_BITS)
|
||||
|
||||
::partition_alloc::ThreadCache::SetLargestCachedSize(largest_cached_size);
|
||||
}
|
||||
|
||||
#endif // defined(PA_THREAD_CACHE_SUPPORTED) &&
|
||||
// BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
|
||||
#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
base::allocator::StartMemoryReclaimer(
|
||||
base::SingleThreadTaskRunner::GetCurrentDefault());
|
||||
#endif
|
||||
|
||||
if (base::FeatureList::IsEnabled(
|
||||
base::features::kPartitionAllocSortActiveSlotSpans)) {
|
||||
partition_alloc::PartitionRoot::EnableSortActiveSlotSpans();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace naive_partition_alloc_support
|
||||
|
@ -9,8 +9,6 @@
|
||||
namespace naive_partition_alloc_support {
|
||||
|
||||
void ReconfigureEarly();
|
||||
void ReconfigureAfterFeatureListInit();
|
||||
void ReconfigureAfterTaskRunnerInit();
|
||||
|
||||
} // namespace naive_partition_alloc_support
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user