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

Side by Side Diff: base/memory/discardable_memory_android.cc

Issue 25293002: Add DiscardableMemoryAllocator to work around FD limit issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Shorten critical section + add unit test Created 7 years, 2 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
« no previous file with comments | « base/memory/discardable_memory_allocator_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/memory/discardable_memory_android.h" 5 #include "base/memory/discardable_memory_android.h"
6 6
7 #include <sys/mman.h> 7 #include <sys/mman.h>
8 #include <unistd.h> 8 #include <unistd.h>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 15 matching lines...) Expand all
26 // Total number of discardable memory in the process. 26 // Total number of discardable memory in the process.
27 int g_num_discardable_memory = 0; 27 int g_num_discardable_memory = 0;
28 28
29 // Upper limit on the number of discardable memory to avoid hitting file 29 // Upper limit on the number of discardable memory to avoid hitting file
30 // descriptor limit. 30 // descriptor limit.
31 const int kDiscardableMemoryNumLimit = 128; 31 const int kDiscardableMemoryNumLimit = 128;
32 32
33 class DiscardableMemoryAndroid : public DiscardableMemory { 33 class DiscardableMemoryAndroid : public DiscardableMemory {
34 public: 34 public:
35 DiscardableMemoryAndroid(int fd, void* address, size_t size) 35 DiscardableMemoryAndroid(int fd, void* address, size_t size)
36 : fd_(fd), 36 : DiscardableMemory(size),
37 fd_(fd),
37 memory_(address), 38 memory_(address),
38 size_(size) { 39 size_(size) {
39 DCHECK_GE(fd_, 0); 40 DCHECK_GE(fd_, 0);
40 DCHECK(memory_); 41 DCHECK(memory_);
41 } 42 }
42 43
43 virtual ~DiscardableMemoryAndroid() { 44 virtual ~DiscardableMemoryAndroid() {
44 internal::DeleteAshmemRegion(fd_, size_, memory_); 45 internal::DeleteAshmemRegion(fd_, size_, memory_);
45 } 46 }
46 47
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 DLOG(ERROR) << "Failed to unpin memory."; 162 DLOG(ERROR) << "Failed to unpin memory.";
162 #if !defined(NDEBUG) 163 #if !defined(NDEBUG)
163 // This allows us to catch accesses to unlocked memory. 164 // This allows us to catch accesses to unlocked memory.
164 DCHECK_EQ(0, mprotect(address, size, PROT_NONE)); 165 DCHECK_EQ(0, mprotect(address, size, PROT_NONE));
165 #endif 166 #endif
166 return !failed; 167 return !failed;
167 } 168 }
168 169
169 } // namespace internal 170 } // namespace internal
170 } // namespace base 171 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_allocator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698