Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2024)

Unified Diff: Source/wtf/PartitionAlloc.h

Issue 172533004: Add partitionAllocActualSize() for predicting actual size of allocation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: addressing review comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/wtf/PartitionAlloc.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/PartitionAlloc.h
diff --git a/Source/wtf/PartitionAlloc.h b/Source/wtf/PartitionAlloc.h
index 3da9adcfe90b9004e0f144cede94e9c4074d84d4..78e039f04cf5a5a97ef2bc1884a8d2d4aa3e7b5b 100644
--- a/Source/wtf/PartitionAlloc.h
+++ b/Source/wtf/PartitionAlloc.h
@@ -182,6 +182,7 @@ static const size_t kGenericNumBucketsPerOrder = 1 << kGenericNumBucketsPerOrder
static const size_t kGenericSmallestBucket = 1 << (kGenericMinBucketedOrder - 1);
static const size_t kGenericMaxBucketSpacing = 1 << ((kGenericMaxBucketedOrder - 1) - kGenericNumBucketsPerOrderBits);
static const size_t kGenericMaxBucketed = (1 << (kGenericMaxBucketedOrder - 1)) + ((kGenericNumBucketsPerOrder - 1) * kGenericMaxBucketSpacing);
+static const size_t kGenericMaxDirectMapped = INT_MAX - kSystemPageSize;
static const size_t kBitsPerSizet = sizeof(void*) * CHAR_BIT;
// Constants for the memory reclaim logic.
@@ -565,6 +566,40 @@ ALWAYS_INLINE void partitionFreeGeneric(PartitionRootGeneric* root, void* ptr)
#endif
}
+ALWAYS_INLINE bool partitionBucketIsDirectMapped(PartitionBucket* bucket)
+{
+ return !bucket->numSystemPagesPerSlotSpan;
+}
+
+ALWAYS_INLINE size_t partitionDirectMapSize(size_t size)
+{
+ // Caller must check that the size is not above the kGenericMaxDirectMapped
+ // limit before calling. This also guards against integer overflow in the
+ // calculation here.
+ ASSERT(size <= kGenericMaxDirectMapped);
+ return (size + kSystemPageOffsetMask) & kSystemPageBaseMask;
+}
+
+ALWAYS_INLINE size_t partitionAllocActualSize(PartitionRootGeneric* root, size_t size)
+{
+#if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
+ return size;
+#else
+ ASSERT(root->initialized);
+ size = partitionCookieSizeAdjustAdd(size);
+ PartitionBucket* bucket = partitionGenericSizeToBucket(root, size);
+ if (LIKELY(!partitionBucketIsDirectMapped(bucket))) {
+ size = bucket->slotSize;
+ } else if (size > kGenericMaxDirectMapped) {
+ // Too large to allocate => return the size unchanged.
+ } else {
+ ASSERT(bucket == &PartitionRootBase::gPagedBucket);
+ size = partitionDirectMapSize(size);
+ }
+ return partitionCookieSizeAdjustSubtract(size);
+#endif
+}
+
ALWAYS_INLINE bool partitionAllocSupportsGetSize()
{
#if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
@@ -623,6 +658,7 @@ using WTF::partitionFree;
using WTF::partitionAllocGeneric;
using WTF::partitionFreeGeneric;
using WTF::partitionReallocGeneric;
+using WTF::partitionAllocActualSize;
using WTF::partitionAllocSupportsGetSize;
using WTF::partitionAllocGetSize;
« no previous file with comments | « no previous file | Source/wtf/PartitionAlloc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698