0
Files
src/content/renderer/discardable_memory_utils.cc
Gordon Guan f2f7a840f9 discardable-memory: Add discardable memory backing field trial
Add detection code for a field trial comparing different
implementations of discardable memory, targeting a very
specific subset of devices and platforms which possess
required capabilities. Further details in bug if required.

Bug: 1014513
Change-Id: Id81a19b06e0c94fa6090ef1d5f6d2cd7fdd80e1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1922749
Commit-Queue: Gordon Guan <gordonguan@google.com>
Reviewed-by: Egor Pasko <pasko@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719665}
2019-11-27 18:26:44 +00:00

49 lines
1.5 KiB
C++

// 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 "base/memory/discardable_memory.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 {
std::unique_ptr<base::DiscardableMemoryAllocator>
CreateDiscardableMemoryAllocator() {
#if defined(OS_POSIX)
if (base::GetDiscardableMemoryBacking() ==
base::DiscardableMemoryBacking::kMadvFree) {
DVLOG(1) << "Using MADV_FREE for discardable memory";
return std::make_unique<base::MadvFreeDiscardableMemoryAllocatorPosix>();
}
#endif // defined(OS_POSIX)
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