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

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 448173002: Re-land: base: Introduce an explicit call for reducing emulated discardable memory usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: disable EmulatedDiscardableMemoryDiscardedWhenWidgetsHidden with lsan Created 6 years, 4 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 (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 #include "content/renderer/render_thread_impl.h" 5 #include "content/renderer/render_thread_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/allocator/allocator_extension.h" 12 #include "base/allocator/allocator_extension.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/debug/trace_event.h" 14 #include "base/debug/trace_event.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/discardable_memory.h" 17 #include "base/memory/discardable_memory.h"
18 #include "base/memory/discardable_memory_emulated.h"
18 #include "base/memory/shared_memory.h" 19 #include "base/memory/shared_memory.h"
19 #include "base/metrics/field_trial.h" 20 #include "base/metrics/field_trial.h"
20 #include "base/metrics/histogram.h" 21 #include "base/metrics/histogram.h"
21 #include "base/metrics/stats_table.h" 22 #include "base/metrics/stats_table.h"
22 #include "base/path_service.h" 23 #include "base/path_service.h"
23 #include "base/strings/string16.h" 24 #include "base/strings/string16.h"
24 #include "base/strings/string_number_conversions.h" 25 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/string_tokenizer.h" 26 #include "base/strings/string_tokenizer.h"
26 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
27 #include "base/threading/thread_local.h" 28 #include "base/threading/thread_local.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 const int kIdleCPUUsageThresholdInPercents = 3; 173 const int kIdleCPUUsageThresholdInPercents = 3;
173 const int kMinRasterThreads = 1; 174 const int kMinRasterThreads = 1;
174 const int kMaxRasterThreads = 64; 175 const int kMaxRasterThreads = 64;
175 176
176 // Maximum allocation size allowed for image scaling filters that 177 // Maximum allocation size allowed for image scaling filters that
177 // require pre-scaling. Skia will fallback to a filter that doesn't 178 // require pre-scaling. Skia will fallback to a filter that doesn't
178 // require pre-scaling if the default filter would require an 179 // require pre-scaling if the default filter would require an
179 // allocation that exceeds this limit. 180 // allocation that exceeds this limit.
180 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024; 181 const size_t kImageCacheSingleAllocationByteLimit = 64 * 1024 * 1024;
181 182
183 const size_t kEmulatedDiscardableMemoryBytesToKeepWhenWidgetsHidden =
184 4 * 1024 * 1024;
185
182 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access 186 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
183 // incorrectly from the wrong thread. 187 // incorrectly from the wrong thread.
184 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > 188 base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> >
185 lazy_tls = LAZY_INSTANCE_INITIALIZER; 189 lazy_tls = LAZY_INSTANCE_INITIALIZER;
186 190
187 class RenderViewZoomer : public RenderViewVisitor { 191 class RenderViewZoomer : public RenderViewVisitor {
188 public: 192 public:
189 RenderViewZoomer(const std::string& scheme, 193 RenderViewZoomer(const std::string& scheme,
190 const std::string& host, 194 const std::string& host,
191 double zoom_level) : scheme_(scheme), 195 double zoom_level) : scheme_(scheme),
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 supported_types.end(), 542 supported_types.end(),
539 requested_type) != supported_types.end()) { 543 requested_type) != supported_types.end()) {
540 type = requested_type; 544 type = requested_type;
541 } else { 545 } else {
542 LOG(ERROR) << "Requested discardable memory type is not supported."; 546 LOG(ERROR) << "Requested discardable memory type is not supported.";
543 } 547 }
544 } 548 }
545 549
546 base::DiscardableMemory::SetPreferredType(type); 550 base::DiscardableMemory::SetPreferredType(type);
547 551
548 // Allow discardable memory implementations to register memory pressure
549 // listeners.
550 base::DiscardableMemory::RegisterMemoryPressureListeners();
551
552 // AllocateGpuMemoryBuffer must be used exclusively on one thread but 552 // AllocateGpuMemoryBuffer must be used exclusively on one thread but
553 // it doesn't have to be the same thread RenderThreadImpl is created on. 553 // it doesn't have to be the same thread RenderThreadImpl is created on.
554 allocate_gpu_memory_buffer_thread_checker_.DetachFromThread(); 554 allocate_gpu_memory_buffer_thread_checker_.DetachFromThread();
555 555
556 if (command_line.HasSwitch(switches::kNumRasterThreads)) { 556 if (command_line.HasSwitch(switches::kNumRasterThreads)) {
557 int num_raster_threads; 557 int num_raster_threads;
558 std::string string_value = 558 std::string string_value =
559 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); 559 command_line.GetSwitchValueASCII(switches::kNumRasterThreads);
560 if (base::StringToInt(string_value, &num_raster_threads) && 560 if (base::StringToInt(string_value, &num_raster_threads) &&
561 num_raster_threads >= kMinRasterThreads && 561 num_raster_threads >= kMinRasterThreads &&
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 1616
1617 void RenderThreadImpl::WidgetDestroyed() { 1617 void RenderThreadImpl::WidgetDestroyed() {
1618 widget_count_--; 1618 widget_count_--;
1619 } 1619 }
1620 1620
1621 void RenderThreadImpl::WidgetHidden() { 1621 void RenderThreadImpl::WidgetHidden() {
1622 DCHECK_LT(hidden_widget_count_, widget_count_); 1622 DCHECK_LT(hidden_widget_count_, widget_count_);
1623 hidden_widget_count_++; 1623 hidden_widget_count_++;
1624 1624
1625 if (widget_count_ && hidden_widget_count_ == widget_count_) { 1625 if (widget_count_ && hidden_widget_count_ == widget_count_) {
1626 // TODO(reveman): Remove this when we have a better mechanism to prevent
1627 // total discardable memory used by all renderers from growing too large.
1628 base::internal::DiscardableMemoryEmulated::
1629 ReduceMemoryUsageUntilWithinLimit(
1630 kEmulatedDiscardableMemoryBytesToKeepWhenWidgetsHidden);
1631
1626 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) 1632 if (GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden())
1627 ScheduleIdleHandler(kInitialIdleHandlerDelayMs); 1633 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
1628 } 1634 }
1629 } 1635 }
1630 1636
1631 void RenderThreadImpl::WidgetRestored() { 1637 void RenderThreadImpl::WidgetRestored() {
1632 DCHECK_GT(hidden_widget_count_, 0); 1638 DCHECK_GT(hidden_widget_count_, 0);
1633 hidden_widget_count_--; 1639 hidden_widget_count_--;
1634 1640
1635 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { 1641 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
1636 return; 1642 return;
1637 } 1643 }
1638 1644
1639 ScheduleIdleHandler(kLongIdleHandlerDelayMs); 1645 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
1640 } 1646 }
1641 1647
1642 } // namespace content 1648 } // namespace content
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_win.cc ('k') | content/renderer/render_thread_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698