Commit 96c21ee8 authored by Gordon Guan's avatar Gordon Guan Committed by Commit Bot

Integrate DiscardableMemory using MADV_FREE with renderer

Generalize usage of discardable memory in the renderer process to use
higher-level discardable memory primitives (DiscardableMemoryAllocator
and DiscardableMemory).

Implement a factory method to create a discardable memory allocator
implementation in renderer context depending on platform support.

Note that usage of MADV_FREE DiscardableMemory is gated by a feature
flag. Discardable memory should behave exactly as before this
change if the feature flag is not enabled.

Binary-Size: Unused ForTest method not being removed by linker
Bug: 1014513
Change-Id: I94afd2347a6ecbe254cd2d1a3ad667a6624293ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1850758
Commit-Queue: Gordon Guan <gordonguan@google.com>
Reviewed-by: default avatarPeng Huang <penghuang@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarBenoit L <lizeb@chromium.org>
Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713010}
parent 788ddcbe
...@@ -42,6 +42,10 @@ class BASE_EXPORT DiscardableMemoryAllocator { ...@@ -42,6 +42,10 @@ class BASE_EXPORT DiscardableMemoryAllocator {
// been discarded. // been discarded.
virtual size_t GetBytesAllocated() const = 0; virtual size_t GetBytesAllocated() const = 0;
// Release any memory used in the implementation of discardable memory that is
// not immediately being used.
virtual void ReleaseFreeMemory() = 0;
private: private:
DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAllocator); DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAllocator);
}; };
......
...@@ -32,6 +32,11 @@ class BASE_EXPORT MadvFreeDiscardableMemoryAllocatorPosix ...@@ -32,6 +32,11 @@ class BASE_EXPORT MadvFreeDiscardableMemoryAllocatorPosix
size_t GetBytesAllocated() const override; size_t GetBytesAllocated() const override;
void ReleaseFreeMemory() override {
// Do nothing, since MADV_FREE discardable memory does not keep any memory
// overhead that can be released.
}
private: private:
std::atomic<size_t> bytes_allocated_{0}; std::atomic<size_t> bytes_allocated_{0};
......
...@@ -25,6 +25,10 @@ class TestDiscardableMemoryAllocator : public DiscardableMemoryAllocator { ...@@ -25,6 +25,10 @@ class TestDiscardableMemoryAllocator : public DiscardableMemoryAllocator {
size_t GetBytesAllocated() const override; size_t GetBytesAllocated() const override;
void ReleaseFreeMemory() override {
// Do nothing since it is backed by heap memory.
}
private: private:
DISALLOW_COPY_AND_ASSIGN(TestDiscardableMemoryAllocator); DISALLOW_COPY_AND_ASSIGN(TestDiscardableMemoryAllocator);
}; };
......
...@@ -46,7 +46,7 @@ class DISCARDABLE_MEMORY_EXPORT ClientDiscardableSharedMemoryManager ...@@ -46,7 +46,7 @@ class DISCARDABLE_MEMORY_EXPORT ClientDiscardableSharedMemoryManager
base::trace_event::ProcessMemoryDump* pmd) override; base::trace_event::ProcessMemoryDump* pmd) override;
// Release memory and associated resources that have been purged. // Release memory and associated resources that have been purged.
void ReleaseFreeMemory(); void ReleaseFreeMemory() override;
bool LockSpan(DiscardableSharedMemoryHeap::Span* span); bool LockSpan(DiscardableSharedMemoryHeap::Span* span);
void UnlockSpan(DiscardableSharedMemoryHeap::Span* span); void UnlockSpan(DiscardableSharedMemoryHeap::Span* span);
......
...@@ -95,6 +95,10 @@ class DISCARDABLE_MEMORY_EXPORT DiscardableSharedMemoryManager ...@@ -95,6 +95,10 @@ class DISCARDABLE_MEMORY_EXPORT DiscardableSharedMemoryManager
// Returns bytes of allocated discardable memory. // Returns bytes of allocated discardable memory.
size_t GetBytesAllocated() const override; size_t GetBytesAllocated() const override;
void ReleaseFreeMemory() override {
// Do nothing since we already subscribe to memory pressure notifications.
}
private: private:
class MemorySegment : public base::RefCountedThreadSafe<MemorySegment> { class MemorySegment : public base::RefCountedThreadSafe<MemorySegment> {
public: public:
......
...@@ -66,6 +66,8 @@ target(link_target_type, "renderer") { ...@@ -66,6 +66,8 @@ target(link_target_type, "renderer") {
"context_menu_params_builder.h", "context_menu_params_builder.h",
"crash_helpers.cc", "crash_helpers.cc",
"crash_helpers.h", "crash_helpers.h",
"discardable_memory_utils.cc",
"discardable_memory_utils.h",
"dom_automation_controller.cc", "dom_automation_controller.cc",
"dom_automation_controller.h", "dom_automation_controller.h",
"drop_data_builder.cc", "drop_data_builder.cc",
...@@ -438,6 +440,7 @@ target(link_target_type, "renderer") { ...@@ -438,6 +440,7 @@ target(link_target_type, "renderer") {
deps += [ deps += [
"//third_party/android_ndk:cpu_features", "//third_party/android_ndk:cpu_features",
"//third_party/ashmem",
"//third_party/libphonenumber", "//third_party/libphonenumber",
] ]
} else { } else {
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <utility>
#include "base/command_line.h"
#include "content/child/child_process.h"
#include "content/child/child_thread_impl.h"
#include "content/public/common/content_switches.h"
#include "content/renderer/discardable_memory_utils.h"
#if defined(OS_POSIX)
#include <sys/mman.h>
#include <sys/utsname.h>
#include "base/memory/madv_free_discardable_memory_allocator_posix.h"
#include "base/memory/madv_free_discardable_memory_posix.h"
#endif
#if defined(OS_ANDROID)
#include <third_party/ashmem/ashmem.h>
#endif
namespace content {
static const base::Feature kMadvFreeDiscardableMemoryFeature{
"MadvFreeDiscardableMemory", base::FEATURE_DISABLED_BY_DEFAULT};
namespace {
DiscardableMemoryBacking GetPlatformDiscardableMemoryBacking() {
#if defined(OS_ANDROID)
if (ashmem_device_is_supported())
return DiscardableMemoryBacking::kSharedMemory;
#endif
bool madv_free_supported = false;
#if defined(OS_POSIX)
madv_free_supported =
base::GetMadvFreeSupport() == base::MadvFreeSupport::kSupported;
#endif
if (base::FeatureList::IsEnabled(kMadvFreeDiscardableMemoryFeature) &&
madv_free_supported) {
return DiscardableMemoryBacking::kMadvFree;
}
return DiscardableMemoryBacking::kSharedMemory;
}
} // namespace
DiscardableMemoryBacking GetDiscardableMemoryBacking() {
static DiscardableMemoryBacking backing =
GetPlatformDiscardableMemoryBacking();
return backing;
}
std::unique_ptr<base::DiscardableMemoryAllocator>
CreateDiscardableMemoryAllocator() {
if (GetDiscardableMemoryBacking() == DiscardableMemoryBacking::kMadvFree) {
#if defined(OS_POSIX)
DVLOG(1) << "Using MADV_FREE for discardable memory";
return std::make_unique<base::MadvFreeDiscardableMemoryAllocatorPosix>();
#endif
}
DVLOG(1) << "Using shared memory for discardable memory";
mojo::PendingRemote<discardable_memory::mojom::DiscardableSharedMemoryManager>
manager_remote;
ChildThread::Get()->BindHostReceiver(
manager_remote.InitWithNewPipeAndPassReceiver());
return std::make_unique<
discardable_memory::ClientDiscardableSharedMemoryManager>(
std::move(manager_remote), ChildProcess::current()->io_task_runner());
}
} // namespace content
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_DISCARDABLE_MEMORY_UTILS_H_
#define CONTENT_RENDERER_DISCARDABLE_MEMORY_UTILS_H_
#include <stddef.h>
#include <memory>
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/discardable_memory.h"
#include "base/memory/discardable_memory_allocator.h"
#include "base/memory/madv_free_discardable_memory_posix.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"
#include "components/discardable_memory/client/client_discardable_shared_memory_manager.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h"
namespace content {
enum class DiscardableMemoryBacking { kSharedMemory, kMadvFree };
CONTENT_EXPORT DiscardableMemoryBacking GetDiscardableMemoryBacking();
CONTENT_EXPORT std::unique_ptr<base::DiscardableMemoryAllocator>
CreateDiscardableMemoryAllocator();
} // namespace content
#endif // CONTENT_RENDERER_DISCARDABLE_MEMORY_UTILS_H_
...@@ -940,20 +940,13 @@ void RenderThreadImpl::Init() { ...@@ -940,20 +940,13 @@ void RenderThreadImpl::Init() {
#endif #endif
categorized_worker_pool_->Start(num_raster_threads); categorized_worker_pool_->Start(num_raster_threads);
mojo::PendingRemote<discardable_memory::mojom::DiscardableSharedMemoryManager> discardable_memory_allocator_ = CreateDiscardableMemoryAllocator();
manager_remote;
ChildThread::Get()->BindHostReceiver(
manager_remote.InitWithNewPipeAndPassReceiver());
discardable_shared_memory_manager_ = std::make_unique<
discardable_memory::ClientDiscardableSharedMemoryManager>(
std::move(manager_remote), GetIOTaskRunner());
// TODO(boliu): In single process, browser main loop should set up the // TODO(boliu): In single process, browser main loop should set up the
// discardable memory manager, and should skip this if kSingleProcess. // discardable memory manager, and should skip this if kSingleProcess.
// See crbug.com/503724. // See crbug.com/503724.
base::DiscardableMemoryAllocator::SetInstance( base::DiscardableMemoryAllocator::SetInstance(
discardable_shared_memory_manager_.get()); discardable_memory_allocator_.get());
#if defined(OS_LINUX) #if defined(OS_LINUX)
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
...@@ -1692,8 +1685,7 @@ bool RenderThreadImpl::GetRendererMemoryMetrics( ...@@ -1692,8 +1685,7 @@ bool RenderThreadImpl::GetRendererMemoryMetrics(
size_t malloc_usage = metric->GetMallocUsage(); size_t malloc_usage = metric->GetMallocUsage();
memory_metrics->malloc_mb = malloc_usage / 1024 / 1024; memory_metrics->malloc_mb = malloc_usage / 1024 / 1024;
size_t discardable_usage = size_t discardable_usage = discardable_memory_allocator_->GetBytesAllocated();
discardable_shared_memory_manager_->GetBytesAllocated();
memory_metrics->discardable_kb = discardable_usage / 1024; memory_metrics->discardable_kb = discardable_usage / 1024;
size_t v8_usage = 0; size_t v8_usage = 0;
...@@ -2368,7 +2360,7 @@ void RenderThreadImpl::OnRendererForegrounded() { ...@@ -2368,7 +2360,7 @@ void RenderThreadImpl::OnRendererForegrounded() {
void RenderThreadImpl::ReleaseFreeMemory() { void RenderThreadImpl::ReleaseFreeMemory() {
base::allocator::ReleaseFreeMemory(); base::allocator::ReleaseFreeMemory();
discardable_shared_memory_manager_->ReleaseFreeMemory(); discardable_memory_allocator_->ReleaseFreeMemory();
// Do not call into blink if it is not initialized. // Do not call into blink if it is not initialized.
if (blink_platform_impl_) { if (blink_platform_impl_) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/cancelable_callback.h" #include "base/cancelable_callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/discardable_memory_allocator.h"
#include "base/memory/memory_pressure_listener.h" #include "base/memory/memory_pressure_listener.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
#include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_thread.h"
#include "content/public/renderer/url_loader_throttle_provider.h" #include "content/public/renderer/url_loader_throttle_provider.h"
#include "content/renderer/compositor/compositor_dependencies.h" #include "content/renderer/compositor/compositor_dependencies.h"
#include "content/renderer/discardable_memory_utils.h"
#include "content/renderer/media/audio/audio_input_ipc_factory.h" #include "content/renderer/media/audio/audio_input_ipc_factory.h"
#include "content/renderer/media/audio/audio_output_ipc_factory.h" #include "content/renderer/media/audio/audio_output_ipc_factory.h"
#include "gpu/ipc/client/gpu_channel_host.h" #include "gpu/ipc/client/gpu_channel_host.h"
...@@ -78,10 +80,6 @@ namespace cc { ...@@ -78,10 +80,6 @@ namespace cc {
class TaskGraphRunner; class TaskGraphRunner;
} }
namespace discardable_memory {
class ClientDiscardableSharedMemoryManager;
}
namespace gpu { namespace gpu {
class GpuChannelHost; class GpuChannelHost;
} }
...@@ -257,9 +255,9 @@ class CONTENT_EXPORT RenderThreadImpl ...@@ -257,9 +255,9 @@ class CONTENT_EXPORT RenderThreadImpl
bool web_test_mode() const { return web_test_mode_; } bool web_test_mode() const { return web_test_mode_; }
void enable_web_test_mode() { web_test_mode_ = true; } void enable_web_test_mode() { web_test_mode_ = true; }
discardable_memory::ClientDiscardableSharedMemoryManager* base::DiscardableMemoryAllocator* GetDiscardableMemoryAllocatorForTest()
GetDiscardableSharedMemoryManagerForTest() { const {
return discardable_shared_memory_manager_.get(); return discardable_memory_allocator_.get();
} }
RendererBlinkPlatformImpl* blink_platform_impl() const { RendererBlinkPlatformImpl* blink_platform_impl() const {
...@@ -538,8 +536,8 @@ class CONTENT_EXPORT RenderThreadImpl ...@@ -538,8 +536,8 @@ class CONTENT_EXPORT RenderThreadImpl
void OnRendererInterfaceReceiver( void OnRendererInterfaceReceiver(
mojo::PendingAssociatedReceiver<mojom::Renderer> receiver); mojo::PendingAssociatedReceiver<mojom::Renderer> receiver);
std::unique_ptr<discardable_memory::ClientDiscardableSharedMemoryManager> std::unique_ptr<base::DiscardableMemoryAllocator>
discardable_shared_memory_manager_; discardable_memory_allocator_;
// These objects live solely on the render thread. // These objects live solely on the render thread.
std::unique_ptr<blink::scheduler::WebThreadScheduler> main_thread_scheduler_; std::unique_ptr<blink::scheduler::WebThreadScheduler> main_thread_scheduler_;
......
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/discardable_memory.h" #include "base/memory/discardable_memory.h"
#include "base/memory/discardable_memory_allocator.h"
#include "base/memory/madv_free_discardable_memory_allocator_posix.h"
#include "base/memory/madv_free_discardable_memory_posix.h"
#include "base/memory/memory_pressure_listener.h" #include "base/memory/memory_pressure_listener.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -23,6 +26,7 @@ ...@@ -23,6 +26,7 @@
#include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h" #include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "content/renderer/discardable_memory_utils.h"
#include "content/shell/browser/shell.h" #include "content/shell/browser/shell.h"
#include "gpu/ipc/common/gpu_memory_buffer_impl.h" #include "gpu/ipc/common/gpu_memory_buffer_impl.h"
#include "ui/gfx/buffer_format_util.h" #include "ui/gfx/buffer_format_util.h"
...@@ -34,7 +38,7 @@ namespace { ...@@ -34,7 +38,7 @@ namespace {
class RenderThreadImplDiscardableMemoryBrowserTest : public ContentBrowserTest { class RenderThreadImplDiscardableMemoryBrowserTest : public ContentBrowserTest {
public: public:
RenderThreadImplDiscardableMemoryBrowserTest() RenderThreadImplDiscardableMemoryBrowserTest()
: child_discardable_shared_memory_manager_(nullptr) {} : discardable_memory_allocator_(nullptr) {}
// Overridden from BrowserTestBase: // Overridden from BrowserTestBase:
void SetUpCommandLine(base::CommandLine* command_line) override { void SetUpCommandLine(base::CommandLine* command_line) override {
...@@ -48,19 +52,17 @@ class RenderThreadImplDiscardableMemoryBrowserTest : public ContentBrowserTest { ...@@ -48,19 +52,17 @@ class RenderThreadImplDiscardableMemoryBrowserTest : public ContentBrowserTest {
base::Unretained(this))); base::Unretained(this)));
} }
discardable_memory::ClientDiscardableSharedMemoryManager* base::DiscardableMemoryAllocator* discardable_memory_allocator() {
child_discardable_shared_memory_manager() { return discardable_memory_allocator_;
return child_discardable_shared_memory_manager_;
} }
private: private:
void SetUpOnRenderThread() { void SetUpOnRenderThread() {
child_discardable_shared_memory_manager_ = discardable_memory_allocator_ =
RenderThreadImpl::current()->GetDiscardableSharedMemoryManagerForTest(); RenderThreadImpl::current()->GetDiscardableMemoryAllocatorForTest();
} }
discardable_memory::ClientDiscardableSharedMemoryManager* base::DiscardableMemoryAllocator* discardable_memory_allocator_;
child_discardable_shared_memory_manager_;
}; };
IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest, IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest,
...@@ -68,8 +70,7 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest, ...@@ -68,8 +70,7 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest,
const size_t kSize = 1024 * 1024; // 1MiB. const size_t kSize = 1024 * 1024; // 1MiB.
std::unique_ptr<base::DiscardableMemory> memory = std::unique_ptr<base::DiscardableMemory> memory =
child_discardable_shared_memory_manager() discardable_memory_allocator()->AllocateLockedDiscardableMemory(kSize);
->AllocateLockedDiscardableMemory(kSize);
ASSERT_TRUE(memory); ASSERT_TRUE(memory);
void* addr = memory->data(); void* addr = memory->data();
...@@ -77,13 +78,17 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest, ...@@ -77,13 +78,17 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest,
memory->Unlock(); memory->Unlock();
// Purge all unlocked memory. // Simulate memory being discarded as if under memory pressure.
discardable_memory::DiscardableSharedMemoryManager::Get()->SetMemoryLimit(0); memory->DiscardForTesting();
// Should fail as memory should have been purged. // Should fail as memory should have been purged.
EXPECT_FALSE(memory->Lock()); EXPECT_FALSE(memory->Lock());
} }
// Ensure that address space mapped by allocating discardable memory is unmapped
// after discarding under memory pressure, by creating and discarding a large
// amount of discardable memory.
//
// Disable the test for the Android asan build. // Disable the test for the Android asan build.
// See http://crbug.com/667837 for detail. // See http://crbug.com/667837 for detail.
#if !(defined(OS_ANDROID) && defined(ADDRESS_SANITIZER)) #if !(defined(OS_ANDROID) && defined(ADDRESS_SANITIZER))
...@@ -92,11 +97,21 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest, ...@@ -92,11 +97,21 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest,
const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB. const size_t kLargeSize = 4 * 1024 * 1024; // 4MiB.
const size_t kNumberOfInstances = 1024 + 1; // >4GiB total. const size_t kNumberOfInstances = 1024 + 1; // >4GiB total.
DiscardableMemoryBacking impl = GetDiscardableMemoryBacking();
// TODO(gordonguan): When MADV_FREE DiscardableMemory is discarded, the
// backing memory is freed, but remains mapped in memory. It is only
// unmapped when the object is destroyed, or on the next Lock() after
// discard. Therefore, an abundance of discarded but mapped discardable
// memory instances may cause an out-of-memory condition.
if (impl != DiscardableMemoryBacking::kSharedMemory)
return;
std::vector<std::unique_ptr<base::DiscardableMemory>> instances; std::vector<std::unique_ptr<base::DiscardableMemory>> instances;
for (size_t i = 0; i < kNumberOfInstances; ++i) { for (size_t i = 0; i < kNumberOfInstances; ++i) {
std::unique_ptr<base::DiscardableMemory> memory = std::unique_ptr<base::DiscardableMemory> memory =
child_discardable_shared_memory_manager() discardable_memory_allocator()->AllocateLockedDiscardableMemory(
->AllocateLockedDiscardableMemory(kLargeSize); kLargeSize);
ASSERT_TRUE(memory); ASSERT_TRUE(memory);
void* addr = memory->data(); void* addr = memory->data();
ASSERT_NE(nullptr, addr); ASSERT_NE(nullptr, addr);
...@@ -110,18 +125,26 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest, ...@@ -110,18 +125,26 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest,
ReleaseFreeDiscardableMemory) { ReleaseFreeDiscardableMemory) {
const size_t kSize = 1024 * 1024; // 1MiB. const size_t kSize = 1024 * 1024; // 1MiB.
DiscardableMemoryBacking impl = GetDiscardableMemoryBacking();
std::unique_ptr<base::DiscardableMemory> memory = std::unique_ptr<base::DiscardableMemory> memory =
child_discardable_shared_memory_manager() discardable_memory_allocator()->AllocateLockedDiscardableMemory(kSize);
->AllocateLockedDiscardableMemory(kSize);
EXPECT_TRUE(memory); EXPECT_TRUE(memory);
EXPECT_GE(discardable_memory_allocator()->GetBytesAllocated(), kSize);
memory.reset(); memory.reset();
EXPECT_EQ(discardable_memory_allocator()->GetBytesAllocated(), 0U);
if (impl != DiscardableMemoryBacking::kSharedMemory)
return;
EXPECT_GE(discardable_memory::DiscardableSharedMemoryManager::Get() EXPECT_GE(discardable_memory::DiscardableSharedMemoryManager::Get()
->GetBytesAllocated(), ->GetBytesAllocated(),
kSize); kSize);
child_discardable_shared_memory_manager()->ReleaseFreeMemory(); static_cast<discardable_memory::ClientDiscardableSharedMemoryManager*>(
discardable_memory_allocator())
->ReleaseFreeMemory();
// Busy wait for host memory usage to be reduced. // Busy wait for host memory usage to be reduced.
base::TimeTicks end = base::TimeTicks end =
...@@ -141,15 +164,12 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest, ...@@ -141,15 +164,12 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest,
const size_t kSize = 1024 * 1024; // 1MiB. const size_t kSize = 1024 * 1024; // 1MiB.
std::unique_ptr<base::DiscardableMemory> memory = std::unique_ptr<base::DiscardableMemory> memory =
child_discardable_shared_memory_manager() discardable_memory_allocator()->AllocateLockedDiscardableMemory(kSize);
->AllocateLockedDiscardableMemory(kSize);
EXPECT_TRUE(memory); EXPECT_TRUE(memory);
memory.reset(); memory.reset();
EXPECT_GE(discardable_memory::DiscardableSharedMemoryManager::Get() EXPECT_GE(discardable_memory_allocator()->GetBytesAllocated(), kSize);
->GetBytesAllocated(),
kSize);
// Call RenderThreadImpl::ReleaseFreeMemory through a fake memory pressure // Call RenderThreadImpl::ReleaseFreeMemory through a fake memory pressure
// notification. // notification.
...@@ -158,8 +178,7 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest, ...@@ -158,8 +178,7 @@ IN_PROC_BROWSER_TEST_F(RenderThreadImplDiscardableMemoryBrowserTest,
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
RunAllTasksUntilIdle(); RunAllTasksUntilIdle();
EXPECT_EQ(0U, discardable_memory::DiscardableSharedMemoryManager::Get() EXPECT_EQ(0U, discardable_memory_allocator()->GetBytesAllocated());
->GetBytesAllocated());
} }
} // namespace } // namespace
......
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