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

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, 7 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
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 61 }
60 } 62 }
61 63
62 RendererFrameManager::RendererFrameManager() { 64 RendererFrameManager::RendererFrameManager() {
63 max_number_of_saved_frames_ = 65 max_number_of_saved_frames_ =
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
71 max_handles_ = base::SharedMemory::GetHandleLimit() / 8.0f;
69 } 72 }
70 73
71 RendererFrameManager::~RendererFrameManager() {} 74 RendererFrameManager::~RendererFrameManager() {}
72 75
73 void RendererFrameManager::CullUnlockedFrames() { 76 void RendererFrameManager::CullUnlockedFrames() {
77 uint32 saved_frame_limit = max_number_of_saved_frames();
78
79 if (unlocked_frames_.size() + locked_frames_.size() > 0) {
80 float handles_per_frame =
81 HostSharedBitmapManager::current()->AllocatedBitmapCount() * 1.0f /
82 (unlocked_frames_.size() + locked_frames_.size());
83
84 saved_frame_limit = std::max(
85 1,
86 static_cast<int>(std::min(static_cast<float>(saved_frame_limit),
87 max_handles_ / handles_per_frame)));
88 }
74 while (!unlocked_frames_.empty() && 89 while (!unlocked_frames_.empty() &&
75 unlocked_frames_.size() + locked_frames_.size() > 90 unlocked_frames_.size() + locked_frames_.size() > saved_frame_limit) {
76 max_number_of_saved_frames()) {
77 size_t old_size = unlocked_frames_.size(); 91 size_t old_size = unlocked_frames_.size();
78 // Should remove self from list. 92 // Should remove self from list.
79 unlocked_frames_.back()->EvictCurrentFrame(); 93 unlocked_frames_.back()->EvictCurrentFrame();
80 DCHECK_EQ(unlocked_frames_.size() + 1, old_size); 94 DCHECK_EQ(unlocked_frames_.size() + 1, old_size);
81 } 95 }
82 } 96 }
83 97
84 } // namespace content 98 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/renderer_frame_manager.h ('k') | content/common/host_shared_bitmap_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698