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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 root->totalSizeOfCommittedPages += len; | 322 root->totalSizeOfCommittedPages += len; |
323 } | 323 } |
324 | 324 |
325 static ALWAYS_INLINE void* partitionAllocPartitionPages(PartitionRootBase* root, int flags, uint16_t numPartitionPages) | 325 static ALWAYS_INLINE void* partitionAllocPartitionPages(PartitionRootBase* root, int flags, uint16_t numPartitionPages) |
326 { | 326 { |
327 ASSERT(!(reinterpret_cast<uintptr_t>(root->nextPartitionPage) % kPartitionPa geSize)); | 327 ASSERT(!(reinterpret_cast<uintptr_t>(root->nextPartitionPage) % kPartitionPa geSize)); |
328 ASSERT(!(reinterpret_cast<uintptr_t>(root->nextPartitionPageEnd) % kPartitio nPageSize)); | 328 ASSERT(!(reinterpret_cast<uintptr_t>(root->nextPartitionPageEnd) % kPartitio nPageSize)); |
329 RELEASE_ASSERT(numPartitionPages <= kNumPartitionPagesPerSuperPage); | 329 RELEASE_ASSERT(numPartitionPages <= kNumPartitionPagesPerSuperPage); |
330 size_t totalSize = kPartitionPageSize * numPartitionPages; | 330 size_t totalSize = kPartitionPageSize * numPartitionPages; |
331 root->totalSizeOfCommittedPages += totalSize; | 331 root->totalSizeOfCommittedPages += totalSize; |
332 if (root->totalSizeOfCommittedPages > kMaxPartitionSize) | |
333 partitionFull(); | |
332 size_t numPartitionPagesLeft = (root->nextPartitionPageEnd - root->nextParti tionPage) >> kPartitionPageShift; | 334 size_t numPartitionPagesLeft = (root->nextPartitionPageEnd - root->nextParti tionPage) >> kPartitionPageShift; |
333 if (LIKELY(numPartitionPagesLeft >= numPartitionPages)) { | 335 if (LIKELY(numPartitionPagesLeft >= numPartitionPages)) { |
334 // In this case, we can still hand out pages from the current super page | 336 // In this case, we can still hand out pages from the current super page |
335 // allocation. | 337 // allocation. |
336 char* ret = root->nextPartitionPage; | 338 char* ret = root->nextPartitionPage; |
337 root->nextPartitionPage += totalSize; | 339 root->nextPartitionPage += totalSize; |
338 return ret; | 340 return ret; |
339 } | 341 } |
340 | 342 |
341 // Need a new super page. | 343 // Need a new super page. |
342 root->totalSizeOfSuperPages += kSuperPageSize; | 344 root->totalSizeOfSuperPages += kSuperPageSize; |
343 if (root->totalSizeOfSuperPages > kMaxPartitionSize) | |
344 partitionFull(); | |
345 char* requestedAddress = root->nextSuperPage; | 345 char* requestedAddress = root->nextSuperPage; |
346 char* superPage = reinterpret_cast<char*>(allocPages(requestedAddress, kSupe rPageSize, kSuperPageSize)); | 346 char* superPage = reinterpret_cast<char*>(allocPages(requestedAddress, kSupe rPageSize, kSuperPageSize)); |
347 if (UNLIKELY(!superPage)) { | 347 if (UNLIKELY(!superPage)) { |
348 if (flags & PartitionAllocReturnNull) | 348 if (flags & PartitionAllocReturnNull) |
349 return 0; | 349 return 0; |
350 partitionOutOfMemory(); | 350 partitionOutOfMemory(); |
351 } | 351 } |
352 root->nextSuperPage = superPage + kSuperPageSize; | 352 root->nextSuperPage = superPage + kSuperPageSize; |
353 char* ret = superPage + kPartitionPageSize; | 353 char* ret = superPage + kPartitionPageSize; |
354 root->nextPartitionPage = ret + totalSize; | 354 root->nextPartitionPage = ret + totalSize; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 // a bunch of system pages more than "size": | 571 // a bunch of system pages more than "size": |
572 // - The first few system pages are the partition page in which the super | 572 // - The first few system pages are the partition page in which the super |
573 // page metadata is stored. We fault just one system page out of a partition | 573 // page metadata is stored. We fault just one system page out of a partition |
574 // page sized clump. | 574 // page sized clump. |
575 // - We add a trailing guard page. | 575 // - We add a trailing guard page. |
576 size_t mapSize = size + kPartitionPageSize + kSystemPageSize; | 576 size_t mapSize = size + kPartitionPageSize + kSystemPageSize; |
577 // Round up to the allocation granularity. | 577 // Round up to the allocation granularity. |
578 mapSize += kPageAllocationGranularityOffsetMask; | 578 mapSize += kPageAllocationGranularityOffsetMask; |
579 mapSize &= kPageAllocationGranularityBaseMask; | 579 mapSize &= kPageAllocationGranularityBaseMask; |
580 | 580 |
581 root->totalSizeOfCommittedPages += size; | |
Chris Evans
2014/10/15 22:06:16
I think we might as well try and be fully accurate
Jens Widell
2014/10/16 11:09:53
Done.
| |
582 if (root->totalSizeOfCommittedPages > kMaxPartitionSize) | |
583 partitionFull(); | |
584 | |
581 // TODO: we may want to let the operating system place these allocations | 585 // TODO: we may want to let the operating system place these allocations |
582 // where it pleases. On 32-bit, this might limit address space | 586 // where it pleases. On 32-bit, this might limit address space |
583 // fragmentation and on 64-bit, this might have useful savings for TLB | 587 // fragmentation and on 64-bit, this might have useful savings for TLB |
584 // and page table overhead. | 588 // and page table overhead. |
585 // TODO: if upsizing realloc()s are common on large sizes, we could | 589 // TODO: if upsizing realloc()s are common on large sizes, we could |
586 // consider over-allocating address space on 64-bit, "just in case". | 590 // consider over-allocating address space on 64-bit, "just in case". |
587 // TODO: consider pre-populating page tables (e.g. MAP_POPULATE on Linux, | 591 // TODO: consider pre-populating page tables (e.g. MAP_POPULATE on Linux, |
588 // MADV_WILLNEED on POSIX). | 592 // MADV_WILLNEED on POSIX). |
589 // TODO: these pages will be zero-filled. Consider internalizing an | 593 // TODO: these pages will be zero-filled. Consider internalizing an |
590 // allocZeroed() API so we can avoid a memset() entirely in this case. | 594 // allocZeroed() API so we can avoid a memset() entirely in this case. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 } | 631 } |
628 | 632 |
629 static ALWAYS_INLINE void partitionDirectUnmap(PartitionPage* page) | 633 static ALWAYS_INLINE void partitionDirectUnmap(PartitionPage* page) |
630 { | 634 { |
631 size_t unmapSize = partitionPageToDirectMapExtent(page)->mapSize; | 635 size_t unmapSize = partitionPageToDirectMapExtent(page)->mapSize; |
632 | 636 |
633 // Add on the size of the trailing guard page and preceeding partition | 637 // Add on the size of the trailing guard page and preceeding partition |
634 // page. | 638 // page. |
635 unmapSize += kPartitionPageSize + kSystemPageSize; | 639 unmapSize += kPartitionPageSize + kSystemPageSize; |
636 | 640 |
641 PartitionRootBase* root = partitionPageToRoot(page); | |
642 root->totalSizeOfCommittedPages -= page->bucket->slotSize; | |
Chris Evans
2014/10/15 22:06:16
+ kSystemPageSize as per above?
Jens Widell
2014/10/16 11:09:53
Done.
| |
643 | |
637 ASSERT(!(unmapSize & kPageAllocationGranularityOffsetMask)); | 644 ASSERT(!(unmapSize & kPageAllocationGranularityOffsetMask)); |
638 | 645 |
639 char* ptr = reinterpret_cast<char*>(partitionPageToPointer(page)); | 646 char* ptr = reinterpret_cast<char*>(partitionPageToPointer(page)); |
640 // Account for the mapping starting a partition page before the actual | 647 // Account for the mapping starting a partition page before the actual |
641 // allocation address. | 648 // allocation address. |
642 ptr -= kPartitionPageSize; | 649 ptr -= kPartitionPageSize; |
643 | 650 |
644 freePages(ptr, unmapSize); | 651 freePages(ptr, unmapSize); |
645 } | 652 } |
646 | 653 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 printf("total live: %zu bytes\n", totalLive); | 982 printf("total live: %zu bytes\n", totalLive); |
976 printf("total resident: %zu bytes\n", totalResident); | 983 printf("total resident: %zu bytes\n", totalResident); |
977 printf("total freeable: %zu bytes\n", totalFreeable); | 984 printf("total freeable: %zu bytes\n", totalFreeable); |
978 fflush(stdout); | 985 fflush(stdout); |
979 } | 986 } |
980 | 987 |
981 #endif // !NDEBUG | 988 #endif // !NDEBUG |
982 | 989 |
983 } // namespace WTF | 990 } // namespace WTF |
984 | 991 |
OLD | NEW |