Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 #include "wtf/FastMalloc.h" | 35 #include "wtf/FastMalloc.h" |
| 36 | 36 |
| 37 namespace WTF { | 37 namespace WTF { |
| 38 | 38 |
| 39 bool Partitions::s_initialized; | 39 bool Partitions::s_initialized; |
| 40 | 40 |
| 41 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; | 41 PartitionAllocatorGeneric Partitions::m_fastMallocAllocator; |
| 42 PartitionAllocatorGeneric Partitions::m_bufferAllocator; | 42 PartitionAllocatorGeneric Partitions::m_bufferAllocator; |
| 43 SizeSpecificPartitionAllocator<3328> Partitions::m_objectModelAllocator; | 43 SizeSpecificPartitionAllocator<3328> Partitions::m_objectModelAllocator; |
| 44 SizeSpecificPartitionAllocator<1024> Partitions::m_renderingAllocator; | 44 SizeSpecificPartitionAllocator<1024> Partitions::m_renderingAllocator; |
| 45 HistogramEnumerationFunction Partitions::m_histogramEnumeration = nullptr; | |
| 45 | 46 |
| 46 void Partitions::initialize() | 47 void Partitions::initialize(HistogramEnumerationFunction histogramEnumeration) |
| 47 { | 48 { |
| 48 static int lock = 0; | 49 static int lock = 0; |
| 49 // Guard against two threads hitting here in parallel. | 50 // Guard against two threads hitting here in parallel. |
| 50 spinLockLock(&lock); | 51 spinLockLock(&lock); |
| 51 if (!s_initialized) { | 52 if (!s_initialized) { |
| 52 m_fastMallocAllocator.init(); | 53 m_fastMallocAllocator.init(); |
| 53 m_bufferAllocator.init(); | 54 m_bufferAllocator.init(); |
| 54 m_objectModelAllocator.init(); | 55 m_objectModelAllocator.init(); |
| 55 m_renderingAllocator.init(); | 56 m_renderingAllocator.init(); |
| 57 m_histogramEnumeration = histogramEnumeration; | |
| 56 s_initialized = true; | 58 s_initialized = true; |
| 57 } | 59 } |
| 58 spinLockUnlock(&lock); | 60 spinLockUnlock(&lock); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void Partitions::shutdown() | 63 void Partitions::shutdown() |
| 62 { | 64 { |
| 63 // We could ASSERT here for a memory leak within the partition, but it leads | 65 // We could ASSERT here for a memory leak within the partition, but it leads |
| 64 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for | 66 // to very hard to diagnose ASSERTs, so it's best to leave leak checking for |
| 65 // the valgrind and heapcheck bots, which run without partitions. | 67 // the valgrind and heapcheck bots, which run without partitions. |
| 66 (void) m_renderingAllocator.shutdown(); | 68 (void) m_renderingAllocator.shutdown(); |
| 67 (void) m_objectModelAllocator.shutdown(); | 69 (void) m_objectModelAllocator.shutdown(); |
| 68 (void) m_bufferAllocator.shutdown(); | 70 (void) m_bufferAllocator.shutdown(); |
| 69 (void) m_fastMallocAllocator.shutdown(); | 71 (void) m_fastMallocAllocator.shutdown(); |
| 70 } | 72 } |
| 71 | 73 |
| 74 void Partitions::recordMemoryUsageIfNeeded() | |
|
Chris Evans
2015/04/02 15:53:01
This might be called on any thread -- is that OK?
haraken
2015/04/02 23:31:32
To avoid races on the static variable, I restricte
| |
| 75 { | |
| 76 static const size_t maxSizeInMB = 4 * 1024; | |
| 77 static bool s_isUsedSlot[maxSizeInMB] = { false }; | |
|
Chris Evans
2015/04/02 15:53:01
This is kind of big -- 4KB. If we keep it, I recom
| |
| 78 | |
| 79 if (!m_histogramEnumeration) | |
| 80 return; | |
| 81 size_t sizeInMB = Partitions::totalSizeOfCommittedPages() / 1024 / 1024; | |
| 82 if (sizeInMB >= maxSizeInMB) | |
| 83 sizeInMB = maxSizeInMB - 1; | |
| 84 if (!s_isUsedSlot[sizeInMB]) { | |
| 85 // Send the UseCounter only once for each slot for each renderer process . | |
|
Chris Evans
2015/04/02 15:53:01
Another strategy -- which would eliminate the abov
haraken
2015/04/02 23:31:32
Nice idea! Done.
| |
| 86 m_histogramEnumeration("PartitionAlloc.CommittedSize", sizeInMB, maxSize InMB); | |
| 87 s_isUsedSlot[sizeInMB] = true; | |
| 88 } | |
| 89 } | |
| 90 | |
| 72 } // namespace WTF | 91 } // namespace WTF |
| OLD | NEW |