libroot/malloc: Do not use B_MAX_CPU_COUNT

This commit is contained in:
Pawel Dziepak 2013-12-06 21:05:05 +01:00
parent 3106f832a9
commit f6b71d5518
4 changed files with 43 additions and 24 deletions

View File

@ -57,15 +57,6 @@ class hoardHeap {
// empty.
enum { MAX_EMPTY_SUPERBLOCKS = EMPTY_FRACTION };
// The maximum number of thread heaps we allow. (NOT the maximum
// number of threads -- Hoard imposes no such limit.) This must be
// a power of two! NB: This number is twice the maximum number of
// PROCESSORS supported by Hoard.
enum { MAX_HEAPS = B_MAX_CPU_COUNT * 2 };
// ANDing with this rounds to MAX_HEAPS.
enum { MAX_HEAPS_MASK = MAX_HEAPS - 1 };
//
// The number of size classes. This combined with the
// SIZE_CLASS_BASE determine the maximum size of an object.

View File

@ -35,25 +35,45 @@
using namespace BPrivate;
processHeap::processHeap(void)
: _buffer(NULL), _bufferCount(0)
processHeap::processHeap()
:
kMaxThreadHeaps(_numProcessors * 2),
theap((HEAPTYPE*)hoardSbrk(sizeof(HEAPTYPE) * kMaxThreadHeaps)),
#if HEAP_FRAG_STATS
, _currentAllocated(0),
_currentAllocated(0),
_currentRequested(0),
_maxAllocated(0), _inUseAtMaxAllocated(0), _maxRequested(0)
_maxAllocated(0),
_inUseAtMaxAllocated(0),
_maxRequested(0),
#endif
#if HEAP_LOG
_log((Log<MemoryRequest>*)
hoardSbrk(sizeof(Log<MemoryRequest>) * (kMaxThreadHeaps + 1))),
#endif
_buffer(NULL),
_bufferCount(0)
{
if (theap == NULL)
return;
new(theap) HEAPTYPE[kMaxThreadHeaps];
#if HEAP_LOG
if (_log == NULL)
return;
new(_log) Log<MemoryRequest>[kMaxThreadHeaps + 1];
#endif
int i;
// The process heap is heap 0.
setIndex(0);
for (i = 0; i < MAX_HEAPS; i++) {
for (i = 0; i < kMaxThreadHeaps; i++) {
// Set every thread's process heap to this one.
theap[i].setpHeap(this);
// Set every thread heap's index.
theap[i].setIndex(i + 1);
}
#if HEAP_LOG
for (i = 0; i < MAX_HEAPS + 1; i++) {
for (i = 0; i < kMaxThreadHeaps + 1; i++) {
char fname[255];
sprintf(fname, "log%d", i);
unlink(fname);
@ -74,7 +94,7 @@ processHeap::stats(void)
#if HEAP_STATS
int umax = 0;
int amax = 0;
for (int j = 0; j < MAX_HEAPS; j++) {
for (int j = 0; j < kMaxThreadHeaps; j++) {
for (int i = 0; i < SIZE_CLASSES; i++) {
amax += theap[j].maxAllocated(i) * sizeFromClass(i);
umax += theap[j].maxInUse(i) * sizeFromClass(i);
@ -98,7 +118,7 @@ processHeap::stats(void)
#if HEAP_LOG
printf("closing logs.\n");
fflush(stdout);
for (int i = 0; i < MAX_HEAPS + 1; i++) {
for (int i = 0; i < kMaxThreadHeaps + 1; i++) {
_log[i].close();
}
#endif

View File

@ -51,7 +51,7 @@ class processHeap : public hoardHeap {
// we parcel out.
enum { REFILL_NUMBER_OF_SUPERBLOCKS = 16 };
processHeap(void);
processHeap();
~processHeap(void)
{
#if HEAP_STATS
@ -132,8 +132,14 @@ class processHeap : public hoardHeap {
processHeap(const processHeap &);
const processHeap & operator=(const processHeap &);
// The maximum number of thread heaps we allow. (NOT the maximum
// number of threads -- Hoard imposes no such limit.) This must be
// a power of two! NB: This number is twice the maximum number of
// PROCESSORS supported by Hoard.
const int kMaxThreadHeaps;
// The per-thread heaps.
HEAPTYPE theap[MAX_HEAPS];
HEAPTYPE* theap;
#if HEAP_FRAG_STATS
// Statistics required to compute fragmentation. We cannot
@ -152,7 +158,7 @@ class processHeap : public hoardHeap {
#endif
#if HEAP_LOG
Log < MemoryRequest > _log[MAX_HEAPS + 1];
Log < MemoryRequest >* _log;
#endif
// A lock for the superblock buffer.
@ -166,8 +172,9 @@ class processHeap : public hoardHeap {
HEAPTYPE &
processHeap::getHeap(int i)
{
assert(theap != NULL);
assert(i >= 0);
assert(i < MAX_HEAPS);
assert(i < kMaxThreadHeaps);
return theap[i];
}
@ -176,8 +183,9 @@ processHeap::getHeap(int i)
Log<MemoryRequest > &
processHeap::getLog(int i)
{
assert(_log != NULL);
assert(i >= 0);
assert(i < MAX_HEAPS + 1);
assert(i < kMaxThreadHeaps + 1);
return _log[i];
}
#endif
@ -192,7 +200,7 @@ processHeap::getHeapIndex(void)
// In fact, for efficiency, we just round up to the highest power of two,
// times two.
int tid = find_thread(NULL) & _numProcessorsMask;
assert(tid < MAX_HEAPS);
assert(tid < kMaxThreadHeaps);
return tid;
}

View File

@ -250,7 +250,7 @@ inline static processHeap *
getAllocator(void)
{
static char *buffer = (char *)hoardSbrk(sizeof(processHeap));
static processHeap *theAllocator = new (buffer) processHeap;
static processHeap *theAllocator = new (buffer) processHeap();
return theAllocator;
}