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

Side by Side Diff: Source/wtf/PartitionAlloc.h

Issue 1053793004: Add a UseCounter that measures the amount of memory used in PartitionAlloc (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 268
269 // An "extent" is a span of consecutive superpages. We link to the partition's 269 // An "extent" is a span of consecutive superpages. We link to the partition's
270 // next extent (if there is one) at the very start of a superpage's metadata 270 // next extent (if there is one) at the very start of a superpage's metadata
271 // area. 271 // area.
272 struct PartitionSuperPageExtentEntry { 272 struct PartitionSuperPageExtentEntry {
273 PartitionRootBase* root; 273 PartitionRootBase* root;
274 char* superPageBase; 274 char* superPageBase;
275 char* superPagesEnd; 275 char* superPagesEnd;
276 PartitionSuperPageExtentEntry* next; 276 PartitionSuperPageExtentEntry* next;
277 }; 277 };
278 278
Chris Evans 2015/04/03 22:14:21 Nit: add comment here: "This callback can be calle
279 typedef void (*ReportMemoryUsageFunction)();
Chris Evans 2015/04/03 22:14:21 Nit: I'm not sure about the name of this callback
280
279 struct WTF_EXPORT PartitionRootBase { 281 struct WTF_EXPORT PartitionRootBase {
280 size_t totalSizeOfCommittedPages; 282 size_t totalSizeOfCommittedPages;
281 size_t totalSizeOfSuperPages; 283 size_t totalSizeOfSuperPages;
282 size_t totalSizeOfDirectMappedPages; 284 size_t totalSizeOfDirectMappedPages;
283 // Invariant: totalSizeOfCommittedPages <= totalSizeOfSuperPages + totalSize OfDirectMappedPages. 285 // Invariant: totalSizeOfCommittedPages <= totalSizeOfSuperPages + totalSize OfDirectMappedPages.
284 unsigned numBuckets; 286 unsigned numBuckets;
285 unsigned maxAllocation; 287 unsigned maxAllocation;
286 bool initialized; 288 bool initialized;
287 char* nextSuperPage; 289 char* nextSuperPage;
288 char* nextPartitionPage; 290 char* nextPartitionPage;
289 char* nextPartitionPageEnd; 291 char* nextPartitionPageEnd;
290 PartitionSuperPageExtentEntry* currentExtent; 292 PartitionSuperPageExtentEntry* currentExtent;
291 PartitionSuperPageExtentEntry* firstExtent; 293 PartitionSuperPageExtentEntry* firstExtent;
292 PartitionPage* globalEmptyPageRing[kMaxFreeableSpans]; 294 PartitionPage* globalEmptyPageRing[kMaxFreeableSpans];
293 int16_t globalEmptyPageRingIndex; 295 int16_t globalEmptyPageRingIndex;
294 uintptr_t invertedSelf; 296 uintptr_t invertedSelf;
297 ReportMemoryUsageFunction reportMemoryUsageFunction;
295 298
296 static int gInitializedLock; 299 static int gInitializedLock;
297 static bool gInitialized; 300 static bool gInitialized;
298 // gSeedPage is used as a sentinel to indicate that there is no page 301 // gSeedPage is used as a sentinel to indicate that there is no page
299 // in the active page list. We can use nullptr, but in that case we need 302 // in the active page list. We can use nullptr, but in that case we need
300 // to add a null-check branch to the hot allocation path. We want to avoid 303 // to add a null-check branch to the hot allocation path. We want to avoid
301 // that. 304 // that.
302 static PartitionPage gSeedPage; 305 static PartitionPage gSeedPage;
303 static PartitionBucket gPagedBucket; 306 static PartitionBucket gPagedBucket;
304 }; 307 };
(...skipping 17 matching lines...) Expand all
322 // need to index array[blah][max+1] which risks undefined behavior. 325 // need to index array[blah][max+1] which risks undefined behavior.
323 PartitionBucket* bucketLookups[((kBitsPerSizet + 1) * kGenericNumBucketsPerO rder) + 1]; 326 PartitionBucket* bucketLookups[((kBitsPerSizet + 1) * kGenericNumBucketsPerO rder) + 1];
324 PartitionBucket buckets[kGenericNumBucketedOrders * kGenericNumBucketsPerOrd er]; 327 PartitionBucket buckets[kGenericNumBucketedOrders * kGenericNumBucketsPerOrd er];
325 }; 328 };
326 329
327 // Flags for partitionAllocGenericFlags. 330 // Flags for partitionAllocGenericFlags.
328 enum PartitionAllocFlags { 331 enum PartitionAllocFlags {
329 PartitionAllocReturnNull = 1 << 0, 332 PartitionAllocReturnNull = 1 << 0,
330 }; 333 };
331 334
332 WTF_EXPORT void partitionAllocInit(PartitionRoot*, size_t numBuckets, size_t max Allocation); 335 WTF_EXPORT void partitionAllocInit(PartitionRoot*, size_t numBuckets, size_t max Allocation, ReportMemoryUsageFunction);
333 WTF_EXPORT bool partitionAllocShutdown(PartitionRoot*); 336 WTF_EXPORT bool partitionAllocShutdown(PartitionRoot*);
334 WTF_EXPORT void partitionAllocGenericInit(PartitionRootGeneric*); 337 WTF_EXPORT void partitionAllocGenericInit(PartitionRootGeneric*, ReportMemoryUsa geFunction);
335 WTF_EXPORT bool partitionAllocGenericShutdown(PartitionRootGeneric*); 338 WTF_EXPORT bool partitionAllocGenericShutdown(PartitionRootGeneric*);
336 339
337 WTF_EXPORT NEVER_INLINE void* partitionAllocSlowPath(PartitionRootBase*, int, si ze_t, PartitionBucket*); 340 WTF_EXPORT NEVER_INLINE void* partitionAllocSlowPath(PartitionRootBase*, int, si ze_t, PartitionBucket*);
338 WTF_EXPORT NEVER_INLINE void partitionFreeSlowPath(PartitionPage*); 341 WTF_EXPORT NEVER_INLINE void partitionFreeSlowPath(PartitionPage*);
339 WTF_EXPORT NEVER_INLINE void* partitionReallocGeneric(PartitionRootGeneric*, voi d*, size_t); 342 WTF_EXPORT NEVER_INLINE void* partitionReallocGeneric(PartitionRootGeneric*, voi d*, size_t);
340 343
341 #ifndef NDEBUG 344 #ifndef NDEBUG
342 WTF_EXPORT void partitionDumpStats(const PartitionRoot&); 345 WTF_EXPORT void partitionDumpStats(const PartitionRoot&);
343 #endif 346 #endif
344 347
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 } 663 }
661 664
662 // N (or more accurately, N - sizeof(void*)) represents the largest size in 665 // N (or more accurately, N - sizeof(void*)) represents the largest size in
663 // bytes that will be handled by a SizeSpecificPartitionAllocator. 666 // bytes that will be handled by a SizeSpecificPartitionAllocator.
664 // Attempts to partitionAlloc() more than this amount will fail. 667 // Attempts to partitionAlloc() more than this amount will fail.
665 template <size_t N> 668 template <size_t N>
666 class SizeSpecificPartitionAllocator { 669 class SizeSpecificPartitionAllocator {
667 public: 670 public:
668 static const size_t kMaxAllocation = N - kAllocationGranularity; 671 static const size_t kMaxAllocation = N - kAllocationGranularity;
669 static const size_t kNumBuckets = N / kAllocationGranularity; 672 static const size_t kNumBuckets = N / kAllocationGranularity;
670 void init() { partitionAllocInit(&m_partitionRoot, kNumBuckets, kMaxAllocati on); } 673 void init(ReportMemoryUsageFunction reportMemoryUsageFunction = nullptr)
674 {
675 partitionAllocInit(&m_partitionRoot, kNumBuckets, kMaxAllocation, report MemoryUsageFunction);
676 }
671 bool shutdown() { return partitionAllocShutdown(&m_partitionRoot); } 677 bool shutdown() { return partitionAllocShutdown(&m_partitionRoot); }
672 ALWAYS_INLINE PartitionRoot* root() { return &m_partitionRoot; } 678 ALWAYS_INLINE PartitionRoot* root() { return &m_partitionRoot; }
673 private: 679 private:
674 PartitionRoot m_partitionRoot; 680 PartitionRoot m_partitionRoot;
675 PartitionBucket m_actualBuckets[kNumBuckets]; 681 PartitionBucket m_actualBuckets[kNumBuckets];
676 }; 682 };
677 683
678 class PartitionAllocatorGeneric { 684 class PartitionAllocatorGeneric {
679 public: 685 public:
680 void init() { partitionAllocGenericInit(&m_partitionRoot); } 686 void init(ReportMemoryUsageFunction reportMemoryUsageFunction = nullptr)
687 {
688 partitionAllocGenericInit(&m_partitionRoot, reportMemoryUsageFunction);
689 }
681 bool shutdown() { return partitionAllocGenericShutdown(&m_partitionRoot); } 690 bool shutdown() { return partitionAllocGenericShutdown(&m_partitionRoot); }
682 ALWAYS_INLINE PartitionRootGeneric* root() { return &m_partitionRoot; } 691 ALWAYS_INLINE PartitionRootGeneric* root() { return &m_partitionRoot; }
683 private: 692 private:
684 PartitionRootGeneric m_partitionRoot; 693 PartitionRootGeneric m_partitionRoot;
685 }; 694 };
686 695
687 } // namespace WTF 696 } // namespace WTF
688 697
689 using WTF::SizeSpecificPartitionAllocator; 698 using WTF::SizeSpecificPartitionAllocator;
690 using WTF::PartitionAllocatorGeneric; 699 using WTF::PartitionAllocatorGeneric;
691 using WTF::PartitionRoot; 700 using WTF::PartitionRoot;
692 using WTF::partitionAllocInit; 701 using WTF::partitionAllocInit;
693 using WTF::partitionAllocShutdown; 702 using WTF::partitionAllocShutdown;
694 using WTF::partitionAlloc; 703 using WTF::partitionAlloc;
695 using WTF::partitionFree; 704 using WTF::partitionFree;
696 using WTF::partitionAllocGeneric; 705 using WTF::partitionAllocGeneric;
697 using WTF::partitionFreeGeneric; 706 using WTF::partitionFreeGeneric;
698 using WTF::partitionReallocGeneric; 707 using WTF::partitionReallocGeneric;
699 using WTF::partitionAllocActualSize; 708 using WTF::partitionAllocActualSize;
700 using WTF::partitionAllocSupportsGetSize; 709 using WTF::partitionAllocSupportsGetSize;
701 using WTF::partitionAllocGetSize; 710 using WTF::partitionAllocGetSize;
702 711
703 #endif // WTF_PartitionAlloc_h 712 #endif // WTF_PartitionAlloc_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698