~ubuntu-branches/ubuntu/wily/google-perftools/wily

« back to all changes in this revision

Viewing changes to src/system-alloc.cc

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2009-09-19 00:10:06 UTC
  • mto: (3.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20090919001006-m997dckgoqs3sru9
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
// ---
31
31
// Author: Sanjay Ghemawat
32
32
 
33
 
#include "config.h"
 
33
#include <config.h>
34
34
#if defined HAVE_STDINT_H
35
35
#include <stdint.h>
36
36
#elif defined HAVE_INTTYPES_H
89
89
 
90
90
// Configuration parameters.
91
91
 
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.");
100
106
 
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];
133
139
 
134
140
bool RegisterSystemAllocator(SysAllocator *a, int priority) {
135
141
  SpinLockHolder lock_holder(&spinlock);
144
150
 
145
151
void* SbrkSysAllocator::Alloc(size_t size, size_t *actual_size,
146
152
                              size_t alignment) {
 
153
#ifndef HAVE_SBRK
 
154
  failed_ = true;
 
155
  return NULL;
 
156
#else
 
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) {
 
164
    return NULL;
 
165
  }
 
166
 
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;
200
220
    ptr += alignment - (ptr & (alignment-1));
201
221
  }
202
222
  return reinterpret_cast<void*>(ptr);
 
223
#endif  // HAVE_SBRK
203
224
}
204
225
 
205
226
void SbrkSysAllocator::DumpStats(TCMalloc_Printer* printer) {