Commit 7b96fa78 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Make RenderThreadImpl::ReleaseFreeMemory call RenderThreadImpl::ClearMemory

Most of the callers of ReleaseFreeMemory() have been usually invoking ClearMemory() together.
So it would be good if we call ClearMemory() inside ReleaseFreeMemory(). It will help
to return more free memory through ReleaseFreeMemory(). This CL makes
ReleaseFreeMemory() purge more free memory through calling ClearMemory(). But this CL just
calls SkGraphics::PurgeAllCaches() directly, since ClearMemory() doesn't do much stuff.
And, this CL removes ClearMemory() that is no longer needed.

The test case is implemented by referring to
RenderThreadImplDiscardableMemoryBrowserTest.ReleaseFreeDiscardableMemory(). It
calls RenderThreadImpl::ReleaseFreeMemory through a fake memory pressure
notification. Besides RenderThreadImplClearMemoryBrowserTest.MAYBE_ClearMemory
should be also removed because ClearMemory() is removed.

Test: RenderThreadImplDiscardableMemoryBrowserTest.ReleaseFreeMemory()

Bug: None
Change-Id: If82e204b6d8785e8d97cd57fe7eac9f0f852a7a8
Reviewed-on: https://chromium-review.googlesource.com/945748
Commit-Queue: Gyuyoung Kim <gyuyoung.kim@lge.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540775}
parent b4321cf1
......@@ -2437,10 +2437,8 @@ void RenderThreadImpl::OnMemoryPressure(
static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level));
}
if (memory_pressure_level ==
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL)
ReleaseFreeMemory();
ClearMemory();
}
}
void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) {
......@@ -2465,7 +2463,6 @@ void RenderThreadImpl::OnPurgeMemory() {
OnTrimMemoryImmediately();
ReleaseFreeMemory();
ClearMemory();
if (blink_platform_impl_)
blink::WebMemoryCoordinator::OnPurgeMemory();
}
......@@ -2482,14 +2479,6 @@ void RenderThreadImpl::RecordPurgeMemory(RendererMemoryMetrics before) {
mbytes);
}
void RenderThreadImpl::ClearMemory() {
// Do not call into blink if it is not initialized.
if (blink_platform_impl_) {
// Purge Skia font cache, resource cache, and image filter.
SkGraphics::PurgeAllCaches();
}
}
scoped_refptr<base::TaskRunner> RenderThreadImpl::GetFileThreadTaskRunner() {
return blink_platform_impl_->BaseFileTaskRunner();
}
......@@ -2607,8 +2596,12 @@ void RenderThreadImpl::ReleaseFreeMemory() {
base::allocator::ReleaseFreeMemory();
discardable_shared_memory_manager_->ReleaseFreeMemory();
if (blink_platform_impl_)
// Do not call into blink if it is not initialized.
if (blink_platform_impl_) {
// Purge Skia font cache, resource cache, and image filter.
SkGraphics::PurgeAllCaches();
blink::DecommitFreeableMemory();
}
}
RenderThreadImpl::PendingFrameCreate::PendingFrameCreate(
......
......@@ -564,8 +564,6 @@ class CONTENT_EXPORT RenderThreadImpl
void RecordPurgeMemory(RendererMemoryMetrics before);
void ClearMemory();
void Init(
const scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue);
......
......@@ -20,7 +20,6 @@
#include "base/test/scoped_feature_list.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "content/app/mojo/mojo_init.h"
#include "content/common/in_process_child_thread_params.h"
#include "content/common/service_manager/child_connection.h"
......@@ -37,10 +36,8 @@
#include "content/public/test/test_browser_thread_bundle.h"
#include "content/public/test/test_content_client_initializer.h"
#include "content/public/test/test_launcher.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_service_manager_context.h"
#include "content/renderer/render_process_impl.h"
#include "content/shell/browser/shell.h"
#include "content/test/mock_render_process.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
......@@ -50,11 +47,9 @@
#include "ipc/ipc_channel_mojo.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/outgoing_broker_client_invitation.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/platform/scheduler/renderer/renderer_scheduler.h"
#include "third_party/WebKit/public/platform/scheduler/test/renderer_scheduler_test_support.h"
#include "third_party/skia/include/core/SkGraphics.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/buffer_format_util.h"
......@@ -418,38 +413,5 @@ INSTANTIATE_TEST_CASE_P(
gfx::BufferFormat::RGBA_8888,
gfx::BufferFormat::BGRA_8888,
gfx::BufferFormat::YVU_420)));
class RenderThreadImplClearMemoryBrowserTest : public ContentBrowserTest {
protected:
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(embedded_test_server()->Start());
}
};
#if defined(OS_ANDROID) || defined(OS_MACOSX) || defined(IS_CHROMECAST)
#define MAYBE_ClearMemory DISABLED_ClearMemory
#else
#define MAYBE_ClearMemory ClearMemory
#endif
IN_PROC_BROWSER_TEST_F(RenderThreadImplClearMemoryBrowserTest,
MAYBE_ClearMemory) {
TestNavigationObserver observer(shell()->web_contents());
GURL url(embedded_test_server()->GetURL("/simple_page.html"));
NavigateToURL(shell(), url);
EXPECT_GT(static_cast<int>(SkGraphics::GetFontCacheUsed()), 0);
EXPECT_GT(SkGraphics::GetFontCacheCountUsed(), 0);
// TODO(gyuyoung): How to call RenderThreadImpl::ClearMemory() from here?
// Instead we call same function that RenderThreadImpl::ClearMemory() calls at
// the moment.
SkGraphics::PurgeAllCaches();
EXPECT_EQ(static_cast<int>(SkGraphics::GetFontCacheUsed()), 0);
EXPECT_EQ(SkGraphics::GetFontCacheCountUsed(), 0);
}
} // namespace
} // namespace content
......@@ -14,6 +14,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/memory/discardable_memory.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/discardable_memory/client/client_discardable_shared_memory_manager.h"
......@@ -22,6 +23,7 @@
#include "content/public/common/content_switches.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "content/shell/browser/shell.h"
#include "gpu/ipc/client/gpu_memory_buffer_impl.h"
#include "ui/gfx/buffer_format_util.h"
......@@ -138,5 +140,33 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest,
EXPECT_LT(base::TimeTicks::Now(), end);
}
IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest,
ReleaseFreeMemory) {
const size_t kSize = 1024 * 1024; // 1MiB.
std::unique_ptr<base::DiscardableMemory> memory =
child_discardable_shared_memory_manager()
->AllocateLockedDiscardableMemory(kSize);
EXPECT_TRUE(memory);
memory.reset();
EXPECT_GE(BrowserMainLoop::GetInstance()
->discardable_shared_memory_manager()
->GetBytesAllocated(),
kSize);
// Call RenderThreadImpl::ReleaseFreeMemory through a fake memory pressure
// notification.
base::MemoryPressureListener::SimulatePressureNotification(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
base::RunLoop().RunUntilIdle();
RunAllTasksUntilIdle();
EXPECT_EQ(0U, BrowserMainLoop::GetInstance()
->discardable_shared_memory_manager()
->GetBytesAllocated());
}
} // namespace
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment