| OLD | NEW |
| 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 }; | 369 }; |
| 370 | 370 |
| 371 WTF_EXPORT void partitionAllocInit(PartitionRoot*, size_t numBuckets, size_t max
Allocation); | 371 WTF_EXPORT void partitionAllocInit(PartitionRoot*, size_t numBuckets, size_t max
Allocation); |
| 372 WTF_EXPORT bool partitionAllocShutdown(PartitionRoot*); | 372 WTF_EXPORT bool partitionAllocShutdown(PartitionRoot*); |
| 373 WTF_EXPORT void partitionAllocGenericInit(PartitionRootGeneric*); | 373 WTF_EXPORT void partitionAllocGenericInit(PartitionRootGeneric*); |
| 374 WTF_EXPORT bool partitionAllocGenericShutdown(PartitionRootGeneric*); | 374 WTF_EXPORT bool partitionAllocGenericShutdown(PartitionRootGeneric*); |
| 375 | 375 |
| 376 enum PartitionPurgeFlags { | 376 enum PartitionPurgeFlags { |
| 377 // Decommitting the ring list of empty pages is reasonably fast. | 377 // Decommitting the ring list of empty pages is reasonably fast. |
| 378 PartitionPurgeDecommitEmptyPages = 1 << 0, | 378 PartitionPurgeDecommitEmptyPages = 1 << 0, |
| 379 // Discarding unused system pages is slower, because it involves walking all |
| 380 // freelists in all active partition pages of all buckets >= system page |
| 381 // size. It often frees a similar amount of memory to decommitting the empty |
| 382 // pages, though. |
| 383 PartitionPurgeDiscardUnusedSystemPages = 1 << 1, |
| 379 }; | 384 }; |
| 380 | 385 |
| 381 WTF_EXPORT void partitionPurgeMemory(PartitionRoot*, int); | 386 WTF_EXPORT void partitionPurgeMemory(PartitionRoot*, int); |
| 382 WTF_EXPORT void partitionPurgeMemoryGeneric(PartitionRootGeneric*, int); | 387 WTF_EXPORT void partitionPurgeMemoryGeneric(PartitionRootGeneric*, int); |
| 383 | 388 |
| 384 WTF_EXPORT NEVER_INLINE void* partitionAllocSlowPath(PartitionRootBase*, int, si
ze_t, PartitionBucket*); | 389 WTF_EXPORT NEVER_INLINE void* partitionAllocSlowPath(PartitionRootBase*, int, si
ze_t, PartitionBucket*); |
| 385 WTF_EXPORT NEVER_INLINE void partitionFreeSlowPath(PartitionPage*); | 390 WTF_EXPORT NEVER_INLINE void partitionFreeSlowPath(PartitionPage*); |
| 386 WTF_EXPORT NEVER_INLINE void* partitionReallocGeneric(PartitionRootGeneric*, voi
d*, size_t); | 391 WTF_EXPORT NEVER_INLINE void* partitionReallocGeneric(PartitionRootGeneric*, voi
d*, size_t); |
| 387 | 392 |
| 388 WTF_EXPORT void partitionDumpStats(PartitionRoot*, const char* partitionName, Pa
rtitionStatsDumper*); | 393 WTF_EXPORT void partitionDumpStats(PartitionRoot*, const char* partitionName, Pa
rtitionStatsDumper*); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 // the last index is invalid because it is a guard page. | 476 // the last index is invalid because it is a guard page. |
| 472 ASSERT(partitionPageIndex); | 477 ASSERT(partitionPageIndex); |
| 473 ASSERT(partitionPageIndex < kNumPartitionPagesPerSuperPage - 1); | 478 ASSERT(partitionPageIndex < kNumPartitionPagesPerSuperPage - 1); |
| 474 PartitionPage* page = reinterpret_cast<PartitionPage*>(partitionSuperPageToM
etadataArea(superPagePtr) + (partitionPageIndex << kPageMetadataShift)); | 479 PartitionPage* page = reinterpret_cast<PartitionPage*>(partitionSuperPageToM
etadataArea(superPagePtr) + (partitionPageIndex << kPageMetadataShift)); |
| 475 // Partition pages in the same slot span can share the same page object. Adj
ust for that. | 480 // Partition pages in the same slot span can share the same page object. Adj
ust for that. |
| 476 size_t delta = page->pageOffset << kPageMetadataShift; | 481 size_t delta = page->pageOffset << kPageMetadataShift; |
| 477 page = reinterpret_cast<PartitionPage*>(reinterpret_cast<char*>(page) - delt
a); | 482 page = reinterpret_cast<PartitionPage*>(reinterpret_cast<char*>(page) - delt
a); |
| 478 return page; | 483 return page; |
| 479 } | 484 } |
| 480 | 485 |
| 481 ALWAYS_INLINE void* partitionPageToPointer(PartitionPage* page) | 486 ALWAYS_INLINE void* partitionPageToPointer(const PartitionPage* page) |
| 482 { | 487 { |
| 483 uintptr_t pointerAsUint = reinterpret_cast<uintptr_t>(page); | 488 uintptr_t pointerAsUint = reinterpret_cast<uintptr_t>(page); |
| 484 uintptr_t superPageOffset = (pointerAsUint & kSuperPageOffsetMask); | 489 uintptr_t superPageOffset = (pointerAsUint & kSuperPageOffsetMask); |
| 485 ASSERT(superPageOffset > kSystemPageSize); | 490 ASSERT(superPageOffset > kSystemPageSize); |
| 486 ASSERT(superPageOffset < kSystemPageSize + (kNumPartitionPagesPerSuperPage *
kPageMetadataSize)); | 491 ASSERT(superPageOffset < kSystemPageSize + (kNumPartitionPagesPerSuperPage *
kPageMetadataSize)); |
| 487 uintptr_t partitionPageIndex = (superPageOffset - kSystemPageSize) >> kPageM
etadataShift; | 492 uintptr_t partitionPageIndex = (superPageOffset - kSystemPageSize) >> kPageM
etadataShift; |
| 488 // Index 0 is invalid because it is the metadata area and the last index is
invalid because it is a guard page. | 493 // Index 0 is invalid because it is the metadata area and the last index is
invalid because it is a guard page. |
| 489 ASSERT(partitionPageIndex); | 494 ASSERT(partitionPageIndex); |
| 490 ASSERT(partitionPageIndex < kNumPartitionPagesPerSuperPage - 1); | 495 ASSERT(partitionPageIndex < kNumPartitionPagesPerSuperPage - 1); |
| 491 uintptr_t superPageBase = (pointerAsUint & kSuperPageBaseMask); | 496 uintptr_t superPageBase = (pointerAsUint & kSuperPageBaseMask); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 518 | 523 |
| 519 ALWAYS_INLINE size_t* partitionPageGetRawSizePtr(PartitionPage* page) | 524 ALWAYS_INLINE size_t* partitionPageGetRawSizePtr(PartitionPage* page) |
| 520 { | 525 { |
| 521 // For single-slot buckets which span more than one partition page, we | 526 // For single-slot buckets which span more than one partition page, we |
| 522 // have some spare metadata space to store the raw allocation size. We | 527 // have some spare metadata space to store the raw allocation size. We |
| 523 // can use this to report better statistics. | 528 // can use this to report better statistics. |
| 524 PartitionBucket* bucket = page->bucket; | 529 PartitionBucket* bucket = page->bucket; |
| 525 if (bucket->slotSize <= kMaxSystemPagesPerSlotSpan * kSystemPageSize) | 530 if (bucket->slotSize <= kMaxSystemPagesPerSlotSpan * kSystemPageSize) |
| 526 return nullptr; | 531 return nullptr; |
| 527 | 532 |
| 533 ASSERT((bucket->slotSize % kSystemPageSize) == 0); |
| 528 ASSERT(partitionBucketIsDirectMapped(bucket) || partitionBucketSlots(bucket)
== 1); | 534 ASSERT(partitionBucketIsDirectMapped(bucket) || partitionBucketSlots(bucket)
== 1); |
| 529 page++; | 535 page++; |
| 530 return reinterpret_cast<size_t*>(&page->freelistHead); | 536 return reinterpret_cast<size_t*>(&page->freelistHead); |
| 531 } | 537 } |
| 532 | 538 |
| 533 ALWAYS_INLINE size_t partitionPageGetRawSize(PartitionPage* page) | 539 ALWAYS_INLINE size_t partitionPageGetRawSize(PartitionPage* page) |
| 534 { | 540 { |
| 535 size_t* rawSizePtr = partitionPageGetRawSizePtr(page); | 541 size_t* rawSizePtr = partitionPageGetRawSizePtr(page); |
| 536 if (UNLIKELY(rawSizePtr != nullptr)) | 542 if (UNLIKELY(rawSizePtr != nullptr)) |
| 537 return *rawSizePtr; | 543 return *rawSizePtr; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 using WTF::partitionAlloc; | 796 using WTF::partitionAlloc; |
| 791 using WTF::partitionFree; | 797 using WTF::partitionFree; |
| 792 using WTF::partitionAllocGeneric; | 798 using WTF::partitionAllocGeneric; |
| 793 using WTF::partitionFreeGeneric; | 799 using WTF::partitionFreeGeneric; |
| 794 using WTF::partitionReallocGeneric; | 800 using WTF::partitionReallocGeneric; |
| 795 using WTF::partitionAllocActualSize; | 801 using WTF::partitionAllocActualSize; |
| 796 using WTF::partitionAllocSupportsGetSize; | 802 using WTF::partitionAllocSupportsGetSize; |
| 797 using WTF::partitionAllocGetSize; | 803 using WTF::partitionAllocGetSize; |
| 798 | 804 |
| 799 #endif // WTF_PartitionAlloc_h | 805 #endif // WTF_PartitionAlloc_h |
| OLD | NEW |