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

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

Issue 17106004: Add discardable memory emulation for non-android/mac platforms (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix MemoryAfterUnlock test Created 7 years, 1 month 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
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"
(...skipping 20 matching lines...) Expand all
31 // 31 //
32 // Notes: 32 // Notes:
33 // - The paging behavior of memory while it is locked is not specified. While 33 // - The paging behavior of memory while it is locked is not specified. While
34 // mobile platforms will not swap it out, it may qualify for swapping 34 // mobile platforms will not swap it out, it may qualify for swapping
35 // on desktop platforms. It is not expected that this will matter, as the 35 // on desktop platforms. It is not expected that this will matter, as the
36 // preferred pattern of usage for DiscardableMemory is to lock down the 36 // preferred pattern of usage for DiscardableMemory is to lock down the
37 // memory, use it as quickly as possible, and then unlock it. 37 // memory, use it as quickly as possible, and then unlock it.
38 // - Because of memory alignment, the amount of memory allocated can be 38 // - Because of memory alignment, the amount of memory allocated can be
39 // larger than the requested memory size. It is not very efficient for 39 // larger than the requested memory size. It is not very efficient for
40 // small allocations. 40 // small allocations.
41 // - A discardable memory instance is not thread safe. It is the
42 // responsibility of users of discardable memory to ensure there are no
43 // races.
41 // 44 //
42 // References: 45 // References:
43 // - Linux: http://lwn.net/Articles/452035/ 46 // - Linux: http://lwn.net/Articles/452035/
44 // - Mac: http://trac.webkit.org/browser/trunk/Source/WebCore/platform/mac/Pur geableBufferMac.cpp 47 // - Mac: http://trac.webkit.org/browser/trunk/Source/WebCore/platform/mac/Pur geableBufferMac.cpp
45 // the comment starting with "vm_object_purgable_control" at 48 // the comment starting with "vm_object_purgable_control" at
46 // http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/v m_object.c 49 // http://www.opensource.apple.com/source/xnu/xnu-792.13.8/osfmk/vm/v m_object.c
47 class BASE_EXPORT DiscardableMemory { 50 class BASE_EXPORT DiscardableMemory {
48 public: 51 public:
49 virtual ~DiscardableMemory() {} 52 virtual ~DiscardableMemory() {}
50 53
51 // Returns whether the system supports discardable memory. 54 // Check whether the system supports discardable memory natively. Returns
52 static bool Supported(); 55 // false if the support is emulated.
56 static bool SupportedNatively();
53 57
54 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size); 58 static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size);
55 59
56 // Locks the memory so that it will not be purged by the system. Returns 60 // Locks the memory so that it will not be purged by the system. Returns
57 // DISCARDABLE_MEMORY_SUCCESS on success. If the return value is 61 // DISCARDABLE_MEMORY_SUCCESS on success. If the return value is
58 // DISCARDABLE_MEMORY_FAILED then this object should be discarded and 62 // DISCARDABLE_MEMORY_FAILED then this object should be discarded and
59 // a new one should be created. If the return value is 63 // a new one should be created. If the return value is
60 // DISCARDABLE_MEMORY_PURGED then the memory is present but any data that 64 // DISCARDABLE_MEMORY_PURGED then the memory is present but any data that
61 // was in it is gone. 65 // was in it is gone.
62 virtual LockDiscardableMemoryStatus Lock() WARN_UNUSED_RESULT = 0; 66 virtual LockDiscardableMemoryStatus Lock() WARN_UNUSED_RESULT = 0;
(...skipping 13 matching lines...) Expand all
76 static bool PurgeForTestingSupported(); 80 static bool PurgeForTestingSupported();
77 81
78 // Purge all discardable memory in the system. This call has global effects 82 // Purge all discardable memory in the system. This call has global effects
79 // across all running processes, so it should only be used for testing! 83 // across all running processes, so it should only be used for testing!
80 static void PurgeForTesting(); 84 static void PurgeForTesting();
81 }; 85 };
82 86
83 } // namespace base 87 } // namespace base
84 88
85 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_ 89 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698