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

Side by Side Diff: base/memory/discardable_memory.h

Issue 15650016: [Not for review] Discardable memory emulation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 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 | « no previous file | base/memory/discardable_memory.cc » ('j') | base/memory/discardable_memory.cc » ('J')
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 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_H_ 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_H_
6 #define BASE_MEMORY_DISCARDABLE_MEMORY_H_ 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 enum LockDiscardableMemoryStatus { 14 enum LockDiscardableMemoryStatus {
15 DISCARDABLE_MEMORY_FAILED = -1, 15 DISCARDABLE_MEMORY_FAILED = -1,
16 DISCARDABLE_MEMORY_PURGED = 0, 16 DISCARDABLE_MEMORY_PURGED = 0,
17 DISCARDABLE_MEMORY_SUCCESS = 1 17 DISCARDABLE_MEMORY_SUCCESS = 1
18 }; 18 };
19 19
20 #if !defined(OS_ANDROID) && !defined(OS_MACOSX)
nduca 2013/05/29 13:57:00 so, on windows 8, we have discardable memory but p
Ian Vollick 2013/06/06 00:21:47 I *think* this is done, but please let me know if
21 // Used to emulate discardable memory on unsupported platforms.
22 class DiscardableMemoryProvider;
23 #endif
24
20 // Platform abstraction for discardable memory. DiscardableMemory is used to 25 // Platform abstraction for discardable memory. DiscardableMemory is used to
21 // cache large objects without worrying about blowing out memory, both on mobile 26 // cache large objects without worrying about blowing out memory, both on mobile
22 // devices where there is no swap, and desktop devices where unused free memory 27 // devices where there is no swap, and desktop devices where unused free memory
23 // should be used to help the user experience. This is preferable to releasing 28 // should be used to help the user experience. This is preferable to releasing
24 // memory in response to an OOM signal because it is simpler, though it has less 29 // memory in response to an OOM signal because it is simpler, though it has less
25 // flexibility as to which objects get discarded. 30 // flexibility as to which objects get discarded.
26 // 31 //
27 // Discardable memory has two states: locked and unlocked. While the memory is 32 // Discardable memory has two states: locked and unlocked. While the memory is
28 // locked, it will not be discarded. Unlocking the memory allows the OS to 33 // locked, it will not be discarded. Unlocking the memory allows the OS to
29 // reclaim it if needed. Locks do not nest. 34 // reclaim it if needed. Locks do not nest.
(...skipping 17 matching lines...) Expand all
47 public: 52 public:
48 DiscardableMemory(); 53 DiscardableMemory();
49 54
50 // If the discardable memory is locked, the destructor will unlock it. 55 // If the discardable memory is locked, the destructor will unlock it.
51 // The opened file will also be closed after this. 56 // The opened file will also be closed after this.
52 ~DiscardableMemory(); 57 ~DiscardableMemory();
53 58
54 // Check whether the system supports discardable memory. 59 // Check whether the system supports discardable memory.
55 static bool Supported(); 60 static bool Supported();
56 61
62 #if !defined(OS_ANDROID) && !defined(OS_MACOSX)
63 // Installs a provider to emulate discardable memory on unsupported platforms.
64 static void SetProvider(DiscardableMemoryProvider* provider);
65 #endif
66
57 // Initialize the DiscardableMemory object. On success, this function returns 67 // Initialize the DiscardableMemory object. On success, this function returns
58 // true and the memory is locked. This should only be called once. 68 // true and the memory is locked. This should only be called once.
59 // This call could fail because of platform-specific limitations and the user 69 // This call could fail because of platform-specific limitations and the user
60 // should stop using the DiscardableMemory afterwards. 70 // should stop using the DiscardableMemory afterwards.
61 bool InitializeAndLock(size_t size); 71 bool InitializeAndLock(size_t size);
62 72
63 // Lock the memory so that it will not be purged by the system. Returns 73 // Lock the memory so that it will not be purged by the system. Returns
64 // DISCARDABLE_MEMORY_SUCCESS on success. If the return value is 74 // DISCARDABLE_MEMORY_SUCCESS on success. If the return value is
65 // DISCARDABLE_MEMORY_FAILED then this object should be discarded and 75 // DISCARDABLE_MEMORY_FAILED then this object should be discarded and
66 // a new one should be created. If the return value is 76 // a new one should be created. If the return value is
(...skipping 29 matching lines...) Expand all
96 void Unmap(); 106 void Unmap();
97 107
98 // Reserve a file descriptor. When reaching the fd limit, this call returns 108 // Reserve a file descriptor. When reaching the fd limit, this call returns
99 // false and initialization should fail. 109 // false and initialization should fail.
100 bool ReserveFileDescriptor(); 110 bool ReserveFileDescriptor();
101 111
102 // Release a file descriptor so that others can reserve it. 112 // Release a file descriptor so that others can reserve it.
103 void ReleaseFileDescriptor(); 113 void ReleaseFileDescriptor();
104 #endif // OS_ANDROID 114 #endif // OS_ANDROID
105 115
116 #if defined(OS_ANDROID) || defined(OS_MACOSX)
jonathan.backer 2013/05/29 14:02:54 Maybe a #define DISCARDABLE_MEMORY_SUPPORTED defin
Ian Vollick 2013/06/06 00:21:47 Done.
106 void* memory_; 117 void* memory_;
107 size_t size_; 118 size_t size_;
108 bool is_locked_; 119 bool is_locked_;
109 #if defined(OS_ANDROID) 120 #if defined(OS_ANDROID)
110 int fd_; 121 int fd_;
111 #endif // OS_ANDROID 122 #endif // OS_ANDROID
123 #endif // OS_ANDROID || OS_MACOSX
112 124
113 DISALLOW_COPY_AND_ASSIGN(DiscardableMemory); 125 DISALLOW_COPY_AND_ASSIGN(DiscardableMemory);
114 }; 126 };
115 127
128 #if !defined(OS_ANDROID) && !defined(OS_MACOSX)
129 class BASE_EXPORT DiscardableMemoryProvider {
130 public:
131 virtual bool Register(const DiscardableMemory*, size_t size) = 0;
132 virtual void Unregister(const DiscardableMemory*) = 0;
133 virtual LockDiscardableMemoryStatus Lock(const DiscardableMemory*) = 0;
134 virtual void Unlock(const DiscardableMemory*) = 0;
135 virtual void* Memory(const DiscardableMemory*) const = 0;
136 virtual bool PurgeForTestingSupported() const = 0;
137 virtual void PurgeForTesting() = 0;
138 };
139 #endif
140
116 } // namespace base 141 } // namespace base
117 142
118 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ 143 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/discardable_memory.cc » ('j') | base/memory/discardable_memory.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698