OLD | NEW |
---|---|
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_PROCESS_MEMORY_H_ | 5 #ifndef BASE_PROCESS_MEMORY_H_ |
6 #define BASE_PROCESS_MEMORY_H_ | 6 #define BASE_PROCESS_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/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 | 12 |
13 #if defined(OS_WIN) | 13 #if defined(OS_WIN) |
14 #include <windows.h> | 14 #include <windows.h> |
15 #endif | 15 #endif |
16 | 16 |
17 #if defined(USE_TCMALLOC) | |
18 extern "C" { | |
19 typedef void* (*tc_malloc_skip_new_handler_function)(size_t size); | |
20 } | |
21 #endif | |
22 | |
17 namespace base { | 23 namespace base { |
18 | 24 |
19 // Enables low fragmentation heap (LFH) for every heaps of this process. This | 25 // Enables low fragmentation heap (LFH) for every heaps of this process. This |
20 // won't have any effect on heaps created after this function call. It will not | 26 // won't have any effect on heaps created after this function call. It will not |
21 // modify data allocated in the heaps before calling this function. So it is | 27 // modify data allocated in the heaps before calling this function. So it is |
22 // better to call this function early in initialization and again before | 28 // better to call this function early in initialization and again before |
23 // entering the main loop. | 29 // entering the main loop. |
24 // Note: Returns true on Windows 2000 without doing anything. | 30 // Note: Returns true on Windows 2000 without doing anything. |
25 BASE_EXPORT bool EnableLowFragmentationHeap(); | 31 BASE_EXPORT bool EnableLowFragmentationHeap(); |
26 | 32 |
(...skipping 19 matching lines...) Expand all Loading... | |
46 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will | 52 // This adjusts /proc/<pid>/oom_score_adj so the Linux OOM killer will |
47 // prefer to kill certain process types over others. The range for the | 53 // prefer to kill certain process types over others. The range for the |
48 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. | 54 // adjustment is [-1000, 1000], with [0, 1000] being user accessible. |
49 // If the Linux system doesn't support the newer oom_score_adj range | 55 // If the Linux system doesn't support the newer oom_score_adj range |
50 // of [0, 1000], then we revert to using the older oom_adj, and | 56 // of [0, 1000], then we revert to using the older oom_adj, and |
51 // translate the given value into [0, 15]. Some aliasing of values | 57 // translate the given value into [0, 15]. Some aliasing of values |
52 // may occur in that case, of course. | 58 // may occur in that case, of course. |
53 BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score); | 59 BASE_EXPORT bool AdjustOOMScore(ProcessId process, int score); |
54 #endif | 60 #endif |
55 | 61 |
62 // Special allocator functions for callers that want to check for OOM. | |
63 // These will not abort if the allocation fails even if | |
64 // EnableTerminationOnOutOfMemory has been called. | |
65 // This can be useful for huge and/or unpredictable size memory allocations. | |
66 // Return value tells whether the allocation succeed. If it fails |result| is | |
67 // set to NULL, otherwise it holds the memory address. | |
jln (very slow on Chromium)
2014/01/29 01:34:35
Could you add a comment along the lines of: "Pleas
| |
68 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedMalloc(size_t size, | |
69 void** result); | |
70 BASE_EXPORT WARN_UNUSED_RESULT bool UncheckedCalloc(size_t num_items, | |
71 size_t size, | |
72 void** result); | |
73 | |
74 // FIXME: make Skia use the new interface and remove these. | |
willchan no longer on Chromium
2014/01/16 01:30:05
Nit: Please use TODO(username). Doesn't mean you h
| |
56 #if defined(OS_MACOSX) | 75 #if defined(OS_MACOSX) |
57 // Very large images or svg canvases can cause huge mallocs. Skia | |
58 // does tricks on tcmalloc-based systems to allow malloc to fail with | |
59 // a NULL rather than hit the oom crasher. This replicates that for | |
60 // OSX. | |
61 // | |
62 // IF YOU USE THIS WITHOUT CONSULTING YOUR FRIENDLY OSX DEVELOPER, | |
63 // YOUR CODE IS LIKELY TO BE REVERTED. THANK YOU. | |
64 BASE_EXPORT void* UncheckedMalloc(size_t size); | 76 BASE_EXPORT void* UncheckedMalloc(size_t size); |
65 BASE_EXPORT void* UncheckedCalloc(size_t num_items, size_t size); | 77 BASE_EXPORT void* UncheckedCalloc(size_t num_items, size_t size); |
66 #endif // defined(OS_MACOSX) | 78 #endif |
79 | |
80 #if defined(USE_TCMALLOC) | |
81 BASE_EXPORT void SetTCMallocSkipNewHandlerFunction( | |
82 tc_malloc_skip_new_handler_function function); | |
83 #endif | |
67 | 84 |
68 } // namespace base | 85 } // namespace base |
69 | 86 |
70 #endif // BASE_PROCESS_MEMORY_H_ | 87 #endif // BASE_PROCESS_MEMORY_H_ |
OLD | NEW |