90
90
// Configuration parameters.
92
DEFINE_int32(malloc_devmem_start, 0,
92
DEFINE_int32(malloc_devmem_start,
93
EnvToInt("TCMALLOC_DEVMEM_START", 0),
93
94
"Physical memory starting location in MB for /dev/mem allocation."
94
95
" Setting this to 0 disables /dev/mem allocation");
95
DEFINE_int32(malloc_devmem_limit, 0,
96
DEFINE_int32(malloc_devmem_limit,
97
EnvToInt("TCMALLOC_DEVMEM_LIMIT", 0),
96
98
"Physical memory limit location in MB for /dev/mem allocation."
97
99
" Setting this to 0 means no limit.");
98
DEFINE_bool(malloc_skip_mmap, false,
100
DEFINE_bool(malloc_skip_sbrk,
101
EnvToBool("TCMALLOC_SKIP_SBRK", false),
102
"Whether sbrk can be used to obtain memory.");
103
DEFINE_bool(malloc_skip_mmap,
104
EnvToBool("TCMALLOC_SKIP_MMAP", false),
99
105
"Whether mmap can be used to obtain memory.");
101
107
// static allocators
129
135
static const int kStaticAllocators = 3;
130
136
// kMaxDynamicAllocators + kStaticAllocators;
131
137
static const int kMaxAllocators = 5;
132
SysAllocator *allocators[kMaxAllocators];
138
static SysAllocator *allocators[kMaxAllocators];
134
140
bool RegisterSystemAllocator(SysAllocator *a, int priority) {
135
141
SpinLockHolder lock_holder(&spinlock);
145
151
void* SbrkSysAllocator::Alloc(size_t size, size_t *actual_size,
146
152
size_t alignment) {
157
// Check if we should use sbrk allocation.
158
// FLAGS_malloc_skip_sbrk starts out as false (its uninitialized
159
// state) and eventually gets initialized to the specified value. Note
160
// that this code runs for a while before the flags are initialized.
161
// That means that even if this flag is set to true, some (initial)
162
// memory will be allocated with sbrk before the flag takes effect.
163
if (FLAGS_malloc_skip_sbrk) {
147
167
// sbrk will release memory if passed a negative number, so we do
148
168
// a strict check here
149
169
if (static_cast<ptrdiff_t>(size + alignment) < 0) return NULL;