Commit 94069728 authored by Benoit Lize's avatar Benoit Lize Committed by Commit Bot

[PartitionAlloc] Make the thread cache threshold explicit.

Bug: 998048
Change-Id: I9c8cdbec7b7748d6d4f9b473affb6d3948a374ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2428896
Commit-Queue: Benoit L <lizeb@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810977}
parent 4947543f
......@@ -272,16 +272,6 @@ void PartitionRoot<thread_safe>::Init(PartitionOptions opts) {
// If alignment needs to be enforced, disallow adding cookies and/or tags at
// the beginning of the slot.
allow_extras = (opts.alignment != PartitionOptions::Alignment::kAlignedAlloc);
#if !defined(OS_POSIX)
// TLS in ThreadCache not supported on other OSes.
with_thread_cache = false;
#else
with_thread_cache =
(opts.thread_cache == PartitionOptions::ThreadCache::kEnabled);
if (with_thread_cache)
internal::ThreadCache::Init(this);
#endif // !defined(OS_POSIX)
// We mark the sentinel bucket/page as free to make sure it is skipped by our
// logic to find a new active page.
......@@ -320,6 +310,17 @@ void PartitionRoot<thread_safe>::Init(PartitionOptions opts) {
// this operation is idempotent, so there is no harm.
InitBucketIndexLookup(this);
#if !defined(OS_POSIX)
// TLS in ThreadCache not supported on other OSes.
with_thread_cache = false;
#else
with_thread_cache =
(opts.thread_cache == PartitionOptions::ThreadCache::kEnabled);
if (with_thread_cache)
internal::ThreadCache::Init(this);
#endif // !defined(OS_POSIX)
initialized = true;
}
......
......@@ -105,6 +105,8 @@ void ThreadCacheRegistry::PurgeAll() {
// static
void ThreadCache::Init(PartitionRoot<ThreadSafe>* root) {
PA_CHECK(root->buckets[kBucketCount - 1].slot_size == kSizeThreshold);
bool ok = PartitionTlsCreate(&g_thread_cache_key, DeleteThreadCache);
PA_CHECK(ok);
......
......@@ -17,6 +17,7 @@
#include "base/no_destructor.h"
#include "base/partition_alloc_buildflags.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"
namespace base {
......@@ -166,9 +167,15 @@ class BASE_EXPORT ThreadCache {
PartitionFreelistEntry* freelist_head;
};
// TODO(lizeb): Optimize the threshold, and define it as an allocation size
// rather than a bucket index.
static constexpr size_t kBucketCount = 40;
// TODO(lizeb): Optimize the threshold.
#if defined(ARCH_CPU_64_BITS)
static constexpr size_t kBucketCount = 41;
#else
static constexpr size_t kBucketCount = 49;
#endif
// Checked in ThreadCache::Init(), not with static_assert() as the size is not
// set at compile-time.
static constexpr size_t kSizeThreshold = 512;
static_assert(
kBucketCount < kNumBuckets,
"Cannot have more cached buckets than what the allocator supports");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment