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

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

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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "wtf/PartitionAlloc.h" 32 #include "wtf/PartitionAlloc.h"
33 #include "wtf/Partitions.h"
Chris Evans 2015/04/02 15:53:01 Hmm -- this introduces a circular dependency. Not
haraken 2015/04/02 23:31:31 Done.
33 34
34 #include <string.h> 35 #include <string.h>
35 36
36 #ifndef NDEBUG 37 #ifndef NDEBUG
37 #include <stdio.h> 38 #include <stdio.h>
38 #endif 39 #endif
39 40
40 // Two partition pages are used as guard / metadata page so make sure the super 41 // Two partition pages are used as guard / metadata page so make sure the super
41 // page size is bigger. 42 // page size is bigger.
42 static_assert(WTF::kPartitionPageSize * 4 <= WTF::kSuperPageSize, "ok super page size"); 43 static_assert(WTF::kPartitionPageSize * 4 <= WTF::kSuperPageSize, "ok super page size");
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 RELEASE_ASSERT(numPartitionPages <= kNumPartitionPagesPerSuperPage); 350 RELEASE_ASSERT(numPartitionPages <= kNumPartitionPagesPerSuperPage);
350 size_t totalSize = kPartitionPageSize * numPartitionPages; 351 size_t totalSize = kPartitionPageSize * numPartitionPages;
351 size_t numPartitionPagesLeft = (root->nextPartitionPageEnd - root->nextParti tionPage) >> kPartitionPageShift; 352 size_t numPartitionPagesLeft = (root->nextPartitionPageEnd - root->nextParti tionPage) >> kPartitionPageShift;
352 if (LIKELY(numPartitionPagesLeft >= numPartitionPages)) { 353 if (LIKELY(numPartitionPagesLeft >= numPartitionPages)) {
353 // In this case, we can still hand out pages from the current super page 354 // In this case, we can still hand out pages from the current super page
354 // allocation. 355 // allocation.
355 char* ret = root->nextPartitionPage; 356 char* ret = root->nextPartitionPage;
356 root->nextPartitionPage += totalSize; 357 root->nextPartitionPage += totalSize;
357 root->totalSizeOfCommittedPages += totalSize; 358 root->totalSizeOfCommittedPages += totalSize;
358 ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages); 359 ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root->totalSizeOfDirectMappedPages);
360 Partitions::recordMemoryUsageIfNeeded();
Chris Evans 2015/04/02 15:53:01 To reduce minor code duplication, can we pull both
haraken 2015/04/02 23:31:32 Done.
359 return ret; 361 return ret;
360 } 362 }
361 363
362 // Need a new super page. We want to allocate super pages in a continguous 364 // Need a new super page. We want to allocate super pages in a continguous
363 // address region as much as possible. This is important for not causing 365 // address region as much as possible. This is important for not causing
364 // page table bloat and not fragmenting address spaces in 32 bit architectur es. 366 // page table bloat and not fragmenting address spaces in 32 bit architectur es.
365 char* requestedAddress = root->nextSuperPage; 367 char* requestedAddress = root->nextSuperPage;
366 char* superPage = reinterpret_cast<char*>(allocPages(requestedAddress, kSupe rPageSize, kSuperPageSize, PageAccessible)); 368 char* superPage = reinterpret_cast<char*>(allocPages(requestedAddress, kSupe rPageSize, kSuperPageSize, PageAccessible));
367 if (UNLIKELY(!superPage)) 369 if (UNLIKELY(!superPage))
368 return 0; 370 return 0;
369 371
370 root->totalSizeOfSuperPages += kSuperPageSize; 372 root->totalSizeOfSuperPages += kSuperPageSize;
371 root->totalSizeOfCommittedPages += totalSize; 373 root->totalSizeOfCommittedPages += totalSize;
372 ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root ->totalSizeOfDirectMappedPages); 374 ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root ->totalSizeOfDirectMappedPages);
375 Partitions::recordMemoryUsageIfNeeded();
373 376
374 root->nextSuperPage = superPage + kSuperPageSize; 377 root->nextSuperPage = superPage + kSuperPageSize;
375 char* ret = superPage + kPartitionPageSize; 378 char* ret = superPage + kPartitionPageSize;
376 root->nextPartitionPage = ret + totalSize; 379 root->nextPartitionPage = ret + totalSize;
377 root->nextPartitionPageEnd = root->nextSuperPage - kPartitionPageSize; 380 root->nextPartitionPageEnd = root->nextSuperPage - kPartitionPageSize;
378 // Make the first partition page in the super page a guard page, but leave a 381 // Make the first partition page in the super page a guard page, but leave a
379 // hole in the middle. 382 // hole in the middle.
380 // This is where we put page metadata and also a tiny amount of extent 383 // This is where we put page metadata and also a tiny amount of extent
381 // metadata. 384 // metadata.
382 setSystemPagesInaccessible(superPage, kSystemPageSize); 385 setSystemPagesInaccessible(superPage, kSystemPageSize);
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 // - We add a trailing guard page. 611 // - We add a trailing guard page.
609 size_t mapSize = size + kPartitionPageSize + kSystemPageSize; 612 size_t mapSize = size + kPartitionPageSize + kSystemPageSize;
610 // Round up to the allocation granularity. 613 // Round up to the allocation granularity.
611 mapSize += kPageAllocationGranularityOffsetMask; 614 mapSize += kPageAllocationGranularityOffsetMask;
612 mapSize &= kPageAllocationGranularityBaseMask; 615 mapSize &= kPageAllocationGranularityBaseMask;
613 616
614 size_t committedPageSize = size + kSystemPageSize; 617 size_t committedPageSize = size + kSystemPageSize;
615 root->totalSizeOfCommittedPages += committedPageSize; 618 root->totalSizeOfCommittedPages += committedPageSize;
616 root->totalSizeOfDirectMappedPages += committedPageSize; 619 root->totalSizeOfDirectMappedPages += committedPageSize;
617 ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root ->totalSizeOfDirectMappedPages); 620 ASSERT(root->totalSizeOfCommittedPages <= root->totalSizeOfSuperPages + root ->totalSizeOfDirectMappedPages);
621 Partitions::recordMemoryUsageIfNeeded();
Chris Evans 2015/04/02 15:53:01 For consistency, we should probably call the callb
haraken 2015/04/02 23:31:31 Done. Actually we don't need to report memory usag
618 622
619 // TODO: we may want to let the operating system place these allocations 623 // TODO: we may want to let the operating system place these allocations
620 // where it pleases. On 32-bit, this might limit address space 624 // where it pleases. On 32-bit, this might limit address space
621 // fragmentation and on 64-bit, this might have useful savings for TLB 625 // fragmentation and on 64-bit, this might have useful savings for TLB
622 // and page table overhead. 626 // and page table overhead.
623 // TODO: if upsizing realloc()s are common on large sizes, we could 627 // TODO: if upsizing realloc()s are common on large sizes, we could
624 // consider over-allocating address space on 64-bit, "just in case". 628 // consider over-allocating address space on 64-bit, "just in case".
625 // TODO: consider pre-populating page tables (e.g. MAP_POPULATE on Linux, 629 // TODO: consider pre-populating page tables (e.g. MAP_POPULATE on Linux,
626 // MADV_WILLNEED on POSIX). 630 // MADV_WILLNEED on POSIX).
627 // TODO: these pages will be zero-filled. Consider internalizing an 631 // TODO: these pages will be zero-filled. Consider internalizing an
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 printf("total live: %zu bytes\n", totalLive); 1045 printf("total live: %zu bytes\n", totalLive);
1042 printf("total resident: %zu bytes\n", totalResident); 1046 printf("total resident: %zu bytes\n", totalResident);
1043 printf("total freeable: %zu bytes\n", totalFreeable); 1047 printf("total freeable: %zu bytes\n", totalFreeable);
1044 fflush(stdout); 1048 fflush(stdout);
1045 } 1049 }
1046 1050
1047 #endif // !NDEBUG 1051 #endif // !NDEBUG
1048 1052
1049 } // namespace WTF 1053 } // namespace WTF
1050 1054
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698