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

Side by Side Diff: content/common/gpu/gpu_memory_manager.h

Issue 308743005: Lobotomize the GPU memory manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update OWNER Created 6 years, 6 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
« no previous file with comments | « content/common/gpu/OWNERS ('k') | content/common/gpu/gpu_memory_manager.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ 5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_
6 #define CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ 6 #define CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 void GetVideoMemoryUsageStats( 56 void GetVideoMemoryUsageStats(
57 content::GPUVideoMemoryUsageStats* video_memory_usage_stats) const; 57 content::GPUVideoMemoryUsageStats* video_memory_usage_stats) const;
58 58
59 GpuMemoryManagerClientState* CreateClientState( 59 GpuMemoryManagerClientState* CreateClientState(
60 GpuMemoryManagerClient* client, bool has_surface, bool visible); 60 GpuMemoryManagerClient* client, bool has_surface, bool visible);
61 61
62 GpuMemoryTrackingGroup* CreateTrackingGroup( 62 GpuMemoryTrackingGroup* CreateTrackingGroup(
63 base::ProcessId pid, gpu::gles2::MemoryTracker* memory_tracker); 63 base::ProcessId pid, gpu::gles2::MemoryTracker* memory_tracker);
64 64
65 uint64 GetClientMemoryUsage(const GpuMemoryManagerClient* client) const; 65 uint64 GetClientMemoryUsage(const GpuMemoryManagerClient* client) const;
66 66 uint64 GetMaximumClientAllocation() const {
67 // The maximum and minimum amount of memory that a client may be assigned. 67 return client_hard_limit_bytes_;
68 uint64 GetMaximumClientAllocation() const;
69 uint64 GetMinimumClientAllocation() const {
70 return bytes_minimum_per_client_;
71 } 68 }
72 69
73 private: 70 private:
74 friend class GpuMemoryManagerTest; 71 friend class GpuMemoryManagerTest;
75 friend class GpuMemoryTrackingGroup; 72 friend class GpuMemoryTrackingGroup;
76 friend class GpuMemoryManagerClientState; 73 friend class GpuMemoryManagerClientState;
77 74
78 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, 75 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest,
79 TestManageBasicFunctionality); 76 TestManageBasicFunctionality);
80 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, 77 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest,
(...skipping 30 matching lines...) Expand all
111 typedef std::map<gpu::gles2::MemoryTracker*, GpuMemoryTrackingGroup*> 108 typedef std::map<gpu::gles2::MemoryTracker*, GpuMemoryTrackingGroup*>
112 TrackingGroupMap; 109 TrackingGroupMap;
113 110
114 typedef std::list<GpuMemoryManagerClientState*> ClientStateList; 111 typedef std::list<GpuMemoryManagerClientState*> ClientStateList;
115 112
116 void Manage(); 113 void Manage();
117 void SetClientsHibernatedState() const; 114 void SetClientsHibernatedState() const;
118 void AssignSurfacesAllocations(); 115 void AssignSurfacesAllocations();
119 void AssignNonSurfacesAllocations(); 116 void AssignNonSurfacesAllocations();
120 117
121 // Math helper function to compute the maximum value of cap such that
122 // sum_i min(bytes[i], cap) <= bytes_sum_limit
123 static uint64 ComputeCap(std::vector<uint64> bytes, uint64 bytes_sum_limit);
124
125 // Compute the allocation for clients when visible and not visible.
126 void ComputeVisibleSurfacesAllocations();
127 void DistributeRemainingMemoryToVisibleSurfaces();
128
129 // Compute the budget for a client. Allow at most bytes_above_required_cap
130 // bytes above client_state's required level. Allow at most
131 // bytes_above_minimum_cap bytes above client_state's minimum level. Allow
132 // at most bytes_overall_cap bytes total.
133 uint64 ComputeClientAllocationWhenVisible(
134 GpuMemoryManagerClientState* client_state,
135 uint64 bytes_above_required_cap,
136 uint64 bytes_above_minimum_cap,
137 uint64 bytes_overall_cap);
138
139 // Update the amount of GPU memory we think we have in the system, based 118 // Update the amount of GPU memory we think we have in the system, based
140 // on what the stubs' contexts report. 119 // on what the stubs' contexts report.
141 void UpdateAvailableGpuMemory(); 120 void UpdateAvailableGpuMemory();
142 void UpdateUnmanagedMemoryLimits();
143
144 // The amount of video memory which is available for allocation.
145 uint64 GetAvailableGpuMemory() const;
146
147 // Minimum value of available GPU memory, no matter how little the GPU
148 // reports. This is the default value.
149 uint64 GetDefaultAvailableGpuMemory() const;
150
151 // Maximum cap on total GPU memory, no matter how much the GPU reports.
152 uint64 GetMaximumTotalGpuMemory() const;
153
154 // The default amount of memory that a client is assigned, if it has not
155 // reported any memory usage stats yet.
156 uint64 GetDefaultClientAllocation() const {
157 return bytes_default_per_client_;
158 }
159
160 static uint64 CalcAvailableFromGpuTotal(uint64 total_gpu_memory);
161 121
162 // Send memory usage stats to the browser process. 122 // Send memory usage stats to the browser process.
163 void SendUmaStatsToBrowser(); 123 void SendUmaStatsToBrowser();
164 124
165 // Get the current number of bytes allocated. 125 // Get the current number of bytes allocated.
166 uint64 GetCurrentUsage() const { 126 uint64 GetCurrentUsage() const {
167 return bytes_allocated_managed_current_ + 127 return bytes_allocated_managed_current_ +
168 bytes_allocated_unmanaged_current_; 128 bytes_allocated_unmanaged_current_;
169 } 129 }
170 130
(...skipping 15 matching lines...) Expand all
186 void OnDestroyClientState(GpuMemoryManagerClientState* client); 146 void OnDestroyClientState(GpuMemoryManagerClientState* client);
187 147
188 // Add or remove a client from its clients list (visible, nonvisible, or 148 // Add or remove a client from its clients list (visible, nonvisible, or
189 // nonsurface). When adding the client, add it to the front of the list. 149 // nonsurface). When adding the client, add it to the front of the list.
190 void AddClientToList(GpuMemoryManagerClientState* client_state); 150 void AddClientToList(GpuMemoryManagerClientState* client_state);
191 void RemoveClientFromList(GpuMemoryManagerClientState* client_state); 151 void RemoveClientFromList(GpuMemoryManagerClientState* client_state);
192 ClientStateList* GetClientList(GpuMemoryManagerClientState* client_state); 152 ClientStateList* GetClientList(GpuMemoryManagerClientState* client_state);
193 153
194 // Interfaces for testing 154 // Interfaces for testing
195 void TestingDisableScheduleManage() { disable_schedule_manage_ = true; } 155 void TestingDisableScheduleManage() { disable_schedule_manage_ = true; }
196 void TestingSetAvailableGpuMemory(uint64 bytes) {
197 bytes_available_gpu_memory_ = bytes;
198 bytes_available_gpu_memory_overridden_ = true;
199 }
200
201 void TestingSetMinimumClientAllocation(uint64 bytes) {
202 bytes_minimum_per_client_ = bytes;
203 }
204
205 void TestingSetDefaultClientAllocation(uint64 bytes) {
206 bytes_default_per_client_ = bytes;
207 }
208
209 void TestingSetUnmanagedLimitStep(uint64 bytes) {
210 bytes_unmanaged_limit_step_ = bytes;
211 }
212 156
213 GpuChannelManager* channel_manager_; 157 GpuChannelManager* channel_manager_;
214 158
215 // A list of all visible and nonvisible clients, in most-recently-used 159 // A list of all visible and nonvisible clients, in most-recently-used
216 // order (most recently used is first). 160 // order (most recently used is first).
217 ClientStateList clients_visible_mru_; 161 ClientStateList clients_visible_mru_;
218 ClientStateList clients_nonvisible_mru_; 162 ClientStateList clients_nonvisible_mru_;
219 163
220 // A list of all clients that don't have a surface. 164 // A list of all clients that don't have a surface.
221 ClientStateList clients_nonsurface_; 165 ClientStateList clients_nonsurface_;
222 166
223 // All context groups' tracking structures 167 // All context groups' tracking structures
224 TrackingGroupMap tracking_groups_; 168 TrackingGroupMap tracking_groups_;
225 169
226 base::CancelableClosure delayed_manage_callback_; 170 base::CancelableClosure delayed_manage_callback_;
227 bool manage_immediate_scheduled_; 171 bool manage_immediate_scheduled_;
172 bool disable_schedule_manage_;
228 173
229 uint64 max_surfaces_with_frontbuffer_soft_limit_; 174 uint64 max_surfaces_with_frontbuffer_soft_limit_;
230 175
231 // The priority cutoff used for all renderers. 176 // The maximum amount of memory that may be allocated for a single client.
232 gpu::MemoryAllocation::PriorityCutoff priority_cutoff_; 177 uint64 client_hard_limit_bytes_;
233
234 // The maximum amount of memory that may be allocated for GPU resources
235 uint64 bytes_available_gpu_memory_;
236 bool bytes_available_gpu_memory_overridden_;
237
238 // The minimum and default allocations for a single client.
239 uint64 bytes_minimum_per_client_;
240 uint64 bytes_default_per_client_;
241 178
242 // The current total memory usage, and historical maximum memory usage 179 // The current total memory usage, and historical maximum memory usage
243 uint64 bytes_allocated_managed_current_; 180 uint64 bytes_allocated_managed_current_;
244 uint64 bytes_allocated_unmanaged_current_; 181 uint64 bytes_allocated_unmanaged_current_;
245 uint64 bytes_allocated_historical_max_; 182 uint64 bytes_allocated_historical_max_;
246 183
247 // If bytes_allocated_unmanaged_current_ leaves the interval [low_, high_),
248 // then ScheduleManage to take the change into account.
249 uint64 bytes_allocated_unmanaged_high_;
250 uint64 bytes_allocated_unmanaged_low_;
251
252 // Update bytes_allocated_unmanaged_low/high_ in intervals of step_.
253 uint64 bytes_unmanaged_limit_step_;
254
255 // Used to disable automatic changes to Manage() in testing.
256 bool disable_schedule_manage_;
257
258 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); 184 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager);
259 }; 185 };
260 186
261 } // namespace content 187 } // namespace content
262 188
263 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ 189 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_
OLDNEW
« no previous file with comments | « content/common/gpu/OWNERS ('k') | content/common/gpu/gpu_memory_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698