| OLD | NEW |
| 1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
| 2 // All rights reserved. | 2 // 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 16 matching lines...) Expand all Loading... |
| 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 // Author: Sanjay Ghemawat <opensource@google.com> | 31 // Author: Sanjay Ghemawat <opensource@google.com> |
| 32 | 32 |
| 33 #ifndef TCMALLOC_CENTRAL_FREELIST_H_ | 33 #ifndef TCMALLOC_CENTRAL_FREELIST_H_ |
| 34 #define TCMALLOC_CENTRAL_FREELIST_H_ | 34 #define TCMALLOC_CENTRAL_FREELIST_H_ |
| 35 | 35 |
| 36 #include "config.h" | 36 #include "config.h" |
| 37 #include <stddef.h> // for size_t |
| 38 #ifdef HAVE_STDINT_H |
| 39 #include <stdint.h> // for int32_t |
| 40 #endif |
| 41 #include "base/spinlock.h" |
| 37 #include "base/thread_annotations.h" | 42 #include "base/thread_annotations.h" |
| 38 #include "base/spinlock.h" | |
| 39 #include "common.h" | 43 #include "common.h" |
| 40 #include "span.h" | 44 #include "span.h" |
| 41 | 45 |
| 42 namespace tcmalloc { | 46 namespace tcmalloc { |
| 43 | 47 |
| 44 // Data kept per size-class in central cache. | 48 // Data kept per size-class in central cache. |
| 45 class CentralFreeList { | 49 class CentralFreeList { |
| 46 public: | 50 public: |
| 47 void Init(size_t cl); | 51 void Init(size_t cl); |
| 48 | 52 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 71 struct TCEntry { | 75 struct TCEntry { |
| 72 void *head; // Head of chain of objects. | 76 void *head; // Head of chain of objects. |
| 73 void *tail; // Tail of chain of objects. | 77 void *tail; // Tail of chain of objects. |
| 74 }; | 78 }; |
| 75 | 79 |
| 76 // A central cache freelist can have anywhere from 0 to kNumTransferEntries | 80 // A central cache freelist can have anywhere from 0 to kNumTransferEntries |
| 77 // slots to put link list chains into. To keep memory usage bounded the total | 81 // slots to put link list chains into. To keep memory usage bounded the total |
| 78 // number of TCEntries across size classes is fixed. Currently each size | 82 // number of TCEntries across size classes is fixed. Currently each size |
| 79 // class is initially given one TCEntry which also means that the maximum any | 83 // class is initially given one TCEntry which also means that the maximum any |
| 80 // one class can have is kNumClasses. | 84 // one class can have is kNumClasses. |
| 85 #ifdef TCMALLOC_SMALL_BUT_SLOW |
| 86 // For the small memory model, the transfer cache is not used. |
| 87 static const int kNumTransferEntries = 0; |
| 88 #else |
| 81 static const int kNumTransferEntries = kNumClasses; | 89 static const int kNumTransferEntries = kNumClasses; |
| 90 #endif |
| 82 | 91 |
| 83 // REQUIRES: lock_ is held | 92 // REQUIRES: lock_ is held |
| 84 // Remove object from cache and return. | 93 // Remove object from cache and return. |
| 85 // Return NULL if no free entries in cache. | 94 // Return NULL if no free entries in cache. |
| 86 void* FetchFromSpans() EXCLUSIVE_LOCKS_REQUIRED(lock_); | 95 void* FetchFromSpans() EXCLUSIVE_LOCKS_REQUIRED(lock_); |
| 87 | 96 |
| 88 // REQUIRES: lock_ is held | 97 // REQUIRES: lock_ is held |
| 89 // Remove object from cache and return. Fetches | 98 // Remove object from cache and return. Fetches |
| 90 // from pageheap if cache is empty. Only returns | 99 // from pageheap if cache is empty. Only returns |
| 91 // NULL on allocation failure. | 100 // NULL on allocation failure. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 class CentralFreeListPaddedTo<0> : public CentralFreeList { | 175 class CentralFreeListPaddedTo<0> : public CentralFreeList { |
| 167 }; | 176 }; |
| 168 | 177 |
| 169 class CentralFreeListPadded : public CentralFreeListPaddedTo< | 178 class CentralFreeListPadded : public CentralFreeListPaddedTo< |
| 170 sizeof(CentralFreeList) % 64> { | 179 sizeof(CentralFreeList) % 64> { |
| 171 }; | 180 }; |
| 172 | 181 |
| 173 } // namespace tcmalloc | 182 } // namespace tcmalloc |
| 174 | 183 |
| 175 #endif // TCMALLOC_CENTRAL_FREELIST_H_ | 184 #endif // TCMALLOC_CENTRAL_FREELIST_H_ |
| OLD | NEW |