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

Side by Side Diff: content/browser/renderer_host/renderer_frame_manager.cc

Issue 248193003: Limit renderer saved frames to avoid running out of fds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
« no previous file with comments | « no previous file | content/common/host_shared_bitmap_manager.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "content/browser/renderer_host/renderer_frame_manager.h" 5 #include "content/browser/renderer_host/renderer_frame_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/shared_memory.h"
10 #include "base/sys_info.h" 11 #include "base/sys_info.h"
12 #include "content/common/host_shared_bitmap_manager.h"
11 13
12 namespace content { 14 namespace content {
13 15
14 RendererFrameManager* RendererFrameManager::GetInstance() { 16 RendererFrameManager* RendererFrameManager::GetInstance() {
15 return Singleton<RendererFrameManager>::get(); 17 return Singleton<RendererFrameManager>::get();
16 } 18 }
17 19
18 void RendererFrameManager::AddFrame(RendererFrameManagerClient* frame, 20 void RendererFrameManager::AddFrame(RendererFrameManagerClient* frame,
19 bool locked) { 21 bool locked) {
20 RemoveFrame(frame); 22 RemoveFrame(frame);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #if defined(OS_ANDROID) 66 #if defined(OS_ANDROID)
65 1; 67 1;
66 #else 68 #else
67 std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256)); 69 std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256));
68 #endif 70 #endif
69 } 71 }
70 72
71 RendererFrameManager::~RendererFrameManager() {} 73 RendererFrameManager::~RendererFrameManager() {}
72 74
73 void RendererFrameManager::CullUnlockedFrames() { 75 void RendererFrameManager::CullUnlockedFrames() {
76 uint32 saved_frame_limit = max_number_of_saved_frames();
77
78 if (saved_frame_limit > 2) {
79 // Reduce the number of saved frames to attempt to limit browser to using at
80 // most 1/8 of the available shared memory handles. This is only a soft
81 // limit, and it may go over as necessary.
82 const float kHandleMaxFraction = 1 / 8.0f;
83 float memory_handle_fraction =
84 HostSharedBitmapManager::current()->AllocatedBitmapCount() * 1.0f /
85 base::SharedMemory::GetHandleLimit();
86 float fraction_to_reduce =
87 std::min(1.0f, memory_handle_fraction / kHandleMaxFraction);
88 saved_frame_limit -=
89 static_cast<uint32>((saved_frame_limit - 2) * fraction_to_reduce);
piman 2014/04/23 00:32:02 I'm not sure I agree with this computation. If we'
90 }
piman 2014/04/23 00:32:02 RenderWidgetHostViewAuraTest.DiscardDelegatedFrame
74 while (!unlocked_frames_.empty() && 91 while (!unlocked_frames_.empty() &&
75 unlocked_frames_.size() + locked_frames_.size() > 92 unlocked_frames_.size() + locked_frames_.size() > saved_frame_limit) {
76 max_number_of_saved_frames()) {
77 size_t old_size = unlocked_frames_.size(); 93 size_t old_size = unlocked_frames_.size();
78 // Should remove self from list. 94 // Should remove self from list.
79 unlocked_frames_.back()->EvictCurrentFrame(); 95 unlocked_frames_.back()->EvictCurrentFrame();
80 DCHECK_EQ(unlocked_frames_.size() + 1, old_size); 96 DCHECK_EQ(unlocked_frames_.size() + 1, old_size);
81 } 97 }
82 } 98 }
83 99
84 } // namespace content 100 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/common/host_shared_bitmap_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698