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

Unified Diff: base/memory/discardable_memory_android.cc

Issue 195863005: Use DiscardableMemoryManager on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix base.gypi Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: base/memory/discardable_memory_android.cc
diff --git a/base/memory/discardable_memory_android.cc b/base/memory/discardable_memory_android.cc
index fa89c189db7be5170ecf30ea3a2a882c24fc87db..9ef08ac858dea98fe31c1d9d7314171b6eba455d 100644
--- a/base/memory/discardable_memory_android.cc
+++ b/base/memory/discardable_memory_android.cc
@@ -10,6 +10,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/discardable_memory_allocator_android.h"
+#include "base/memory/discardable_memory_ashmem.h"
#include "base/memory/discardable_memory_emulated.h"
#include "base/memory/discardable_memory_malloc.h"
@@ -18,13 +19,22 @@ namespace {
const char kAshmemAllocatorName[] = "DiscardableMemoryAllocator";
-struct DiscardableMemoryAllocatorWrapper {
- DiscardableMemoryAllocatorWrapper()
+// When ashmem is used, have the DiscardableMemoryManager trigger userspace
+// eviction when address space usage gets too high, e.g. 512 MBytes on 32 bit
+// systems vs 16 GBytes on 64 bits.
+const size_t kAshmemMaxAddressSpaceUsage =
+ ((sizeof(void*) == 4) ? 512 : 16 * 1024) * 1024 * 1024;
reveman 2014/04/26 00:13:37 I would prefer if used the same constant on 64bit
Philippe 2014/04/28 12:23:14 Done.
+
+// Holds the state used for ashmem allocations.
+struct AshmemGlobalContext {
+ AshmemGlobalContext()
: allocator(kAshmemAllocatorName,
GetOptimalAshmemRegionSizeForAllocator()) {
+ manager.SetMemoryLimit(kAshmemMaxAddressSpaceUsage);
}
internal::DiscardableMemoryAllocator allocator;
+ internal::DiscardableMemoryManager manager;
private:
// Returns 64 MBytes for a 512 MBytes device, 128 MBytes for 1024 MBytes...
@@ -35,8 +45,7 @@ struct DiscardableMemoryAllocatorWrapper {
}
};
-LazyInstance<DiscardableMemoryAllocatorWrapper>::Leaky g_context =
- LAZY_INSTANCE_INITIALIZER;
+LazyInstance<AshmemGlobalContext>::Leaky g_context = LAZY_INSTANCE_INITIALIZER;
} // namespace
@@ -69,7 +78,14 @@ scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
case DISCARDABLE_MEMORY_TYPE_MAC:
return scoped_ptr<DiscardableMemory>();
case DISCARDABLE_MEMORY_TYPE_ANDROID: {
- return g_context.Pointer()->allocator.Allocate(size);
+ AshmemGlobalContext* const global_context = g_context.Pointer();
+ scoped_ptr<internal::DiscardableMemoryAshmem> memory(
+ new internal::DiscardableMemoryAshmem(
+ size, &global_context->allocator, &global_context->manager));
+ if (!memory->Initialize())
+ return scoped_ptr<DiscardableMemory>();
+
+ return memory.PassAs<DiscardableMemory>();
}
case DISCARDABLE_MEMORY_TYPE_EMULATED: {
scoped_ptr<internal::DiscardableMemoryEmulated> memory(

Powered by Google App Engine
This is Rietveld 408576698