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

Side by Side Diff: base/trace_event/heap_profiler_allocation_register.h

Issue 1530583003: [Tracing] Adjust allocation register size for low-end devices (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: CR Feedback Created 5 years 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
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_register.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_
6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 friend class AllocationRegister; 53 friend class AllocationRegister;
54 using CellIndex = uint32_t; 54 using CellIndex = uint32_t;
55 55
56 ConstIterator(const AllocationRegister& alloc_register, CellIndex index); 56 ConstIterator(const AllocationRegister& alloc_register, CellIndex index);
57 57
58 const AllocationRegister& register_; 58 const AllocationRegister& register_;
59 CellIndex index_; 59 CellIndex index_;
60 }; 60 };
61 61
62 AllocationRegister(); 62 AllocationRegister();
63 explicit AllocationRegister(uint32_t num_cells);
64
63 ~AllocationRegister(); 65 ~AllocationRegister();
64 66
65 // Inserts allocation details into the table. If the address was present 67 // Inserts allocation details into the table. If the address was present
66 // already, its details are updated. |address| must not be null. (This is 68 // already, its details are updated. |address| must not be null. (This is
67 // because null is used to mark free cells, to allow efficient iteration of 69 // because null is used to mark free cells, to allow efficient iteration of
68 // the hash table.) 70 // the hash table.)
69 void Insert(void* address, size_t size, AllocationContext context); 71 void Insert(void* address, size_t size, AllocationContext context);
70 72
71 // Removes the address from the table if it is present. It is ok to call this 73 // Removes the address from the table if it is present. It is ok to call this
72 // with a null pointer. 74 // with a null pointer.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 static const uint32_t kNumBuckets = 0x40000; 107 static const uint32_t kNumBuckets = 0x40000;
106 static const uint32_t kNumBucketsMask = kNumBuckets - 1; 108 static const uint32_t kNumBucketsMask = kNumBuckets - 1;
107 109
108 // Reserve address space to store at most this number of entries. High 110 // Reserve address space to store at most this number of entries. High
109 // capacity does not imply high memory usage due to the access pattern. The 111 // capacity does not imply high memory usage due to the access pattern. The
110 // only constraint on the number of cells is that on 32-bit systems address 112 // only constraint on the number of cells is that on 32-bit systems address
111 // space is scarce (i.e. reserving 2GiB of address space for the entries is 113 // space is scarce (i.e. reserving 2GiB of address space for the entries is
112 // not an option). A value of ~3M entries is large enough to handle spikes in 114 // not an option). A value of ~3M entries is large enough to handle spikes in
113 // the number of allocations, and modest enough to require no more than a few 115 // the number of allocations, and modest enough to require no more than a few
114 // dozens of MiB of address space. 116 // dozens of MiB of address space.
115 static const uint32_t kNumCells = kNumBuckets * 10; 117 static const uint32_t kNumCellsPerBucket = 10;
116 118
117 // Returns a value in the range [0, kNumBuckets - 1] (inclusive). 119 // Returns a value in the range [0, kNumBuckets - 1] (inclusive).
118 static uint32_t Hash(void* address); 120 static uint32_t Hash(void* address);
119 121
120 // Allocates a region of virtual address space of |size| rounded up to the 122 // Allocates a region of virtual address space of |size| rounded up to the
121 // system page size. The memory is zeroed by the system. A guard page is 123 // system page size. The memory is zeroed by the system. A guard page is
122 // added after the end. 124 // added after the end.
123 static void* AllocateVirtualMemory(size_t size); 125 static void* AllocateVirtualMemory(size_t size);
124 126
125 // Frees a region of virtual address space allocated by a call to 127 // Frees a region of virtual address space allocated by a call to
126 // |AllocateVirtualMemory|. 128 // |AllocateVirtualMemory|.
127 static void FreeVirtualMemory(void* address, size_t allocated_size); 129 static void FreeVirtualMemory(void* address, size_t allocated_size);
128 130
129 // Returns a pointer to the variable that contains or should contain the 131 // Returns a pointer to the variable that contains or should contain the
130 // index of the cell that stores the entry for |address|. The pointer may 132 // index of the cell that stores the entry for |address|. The pointer may
131 // point at an element of |buckets_| or at the |next| member of an element of 133 // point at an element of |buckets_| or at the |next| member of an element of
132 // |cells_|. If the value pointed at is 0, |address| is not in the table. 134 // |cells_|. If the value pointed at is 0, |address| is not in the table.
133 CellIndex* Lookup(void* address); 135 CellIndex* Lookup(void* address);
134 136
135 // Takes a cell that is not being used to store an entry (either by recycling 137 // Takes a cell that is not being used to store an entry (either by recycling
136 // from the free list or by taking a fresh cell) and returns its index. 138 // from the free list or by taking a fresh cell) and returns its index.
137 CellIndex GetFreeCell(); 139 CellIndex GetFreeCell();
138 140
141 // The maximum number of cells which can be allocated.
142 uint32_t const num_cells_;
143
139 // The array of cells. This array is backed by mmapped memory. Lower indices 144 // The array of cells. This array is backed by mmapped memory. Lower indices
140 // are accessed first, higher indices are only accessed when required. In 145 // are accessed first, higher indices are only accessed when required. In
141 // this way, even if a huge amount of address space has been mmapped, only 146 // this way, even if a huge amount of address space has been mmapped, only
142 // the cells that are actually used will be backed by physical memory. 147 // the cells that are actually used will be backed by physical memory.
143 Cell* const cells_; 148 Cell* const cells_;
144 149
145 // The array of indices into |cells_|. |buckets_[Hash(address)]| will contain 150 // The array of indices into |cells_|. |buckets_[Hash(address)]| will contain
146 // the index of the head of the linked list for |Hash(address)|. A value of 0 151 // the index of the head of the linked list for |Hash(address)|. A value of 0
147 // indicates an empty list. This array is backed by mmapped memory. 152 // indicates an empty list. This array is backed by mmapped memory.
148 CellIndex* const buckets_; 153 CellIndex* const buckets_;
149 154
150 // The head of the free list. This is the index of the cell. A value of 0 155 // The head of the free list. This is the index of the cell. A value of 0
151 // means that the free list is empty. 156 // means that the free list is empty.
152 CellIndex free_list_; 157 CellIndex free_list_;
153 158
154 // The index of the first element of |cells_| that has not been used before. 159 // The index of the first element of |cells_| that has not been used before.
155 // If the free list is empty and a new cell is needed, the cell at this index 160 // If the free list is empty and a new cell is needed, the cell at this index
156 // is used. This is the high water mark for the number of entries stored. 161 // is used. This is the high water mark for the number of entries stored.
157 CellIndex next_unused_cell_; 162 CellIndex next_unused_cell_;
158 163
159 DISALLOW_COPY_AND_ASSIGN(AllocationRegister); 164 DISALLOW_COPY_AND_ASSIGN(AllocationRegister);
160 }; 165 };
161 166
162 } // namespace trace_event 167 } // namespace trace_event
163 } // namespace base 168 } // namespace base
164 169
165 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ 170 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/heap_profiler_allocation_register.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698