* Some minor cleanup and improved comments.
* Fixed check in hoardSbrk(): resize_area() was invoked, even if the area was already large enough. * Increased the initial heap size to 64 pages. Apparently the hoard implementation is rather generous and the first malloc() (caused by __init_heap()) already required enlarging the area. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34336 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -51,11 +51,12 @@ struct free_chunk {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const size_t kInitialHeapSize = 50 * B_PAGE_SIZE;
|
static const size_t kInitialHeapSize = 64 * B_PAGE_SIZE;
|
||||||
// that's about what hoard allocates anyway
|
// that's about what hoard allocates anyway (should be kHeapIncrement
|
||||||
|
// aligned)
|
||||||
|
|
||||||
static const size_t kHeapIncrement = 16 * B_PAGE_SIZE;
|
static const size_t kHeapIncrement = 16 * B_PAGE_SIZE;
|
||||||
// the steps in which to increase the heap size
|
// the steps in which to increase the heap size (must be a power of 2)
|
||||||
|
|
||||||
static area_id sHeapArea;
|
static area_id sHeapArea;
|
||||||
static hoardLockType sHeapLock;
|
static hoardLockType sHeapLock;
|
||||||
@@ -104,7 +105,7 @@ __init_heap(void)
|
|||||||
|
|
||||||
atfork(&init_after_fork);
|
atfork(&init_after_fork);
|
||||||
// Note: Needs malloc(). Hence we need to be fully initialized.
|
// Note: Needs malloc(). Hence we need to be fully initialized.
|
||||||
// ToDo: We should actually also install a hook that is called before
|
// TODO: We should actually also install a hook that is called before
|
||||||
// fork() is being executed. In a multithreaded app it would need to
|
// fork() is being executed. In a multithreaded app it would need to
|
||||||
// acquire *all* allocator locks, so that we don't fork() an
|
// acquire *all* allocator locks, so that we don't fork() an
|
||||||
// inconsistent state.
|
// inconsistent state.
|
||||||
@@ -196,12 +197,13 @@ hoardSbrk(long size)
|
|||||||
size_t oldHeapSize = sFreeHeapSize;
|
size_t oldHeapSize = sFreeHeapSize;
|
||||||
sFreeHeapSize += size;
|
sFreeHeapSize += size;
|
||||||
|
|
||||||
// round to next page size
|
// round to next heap increment aligned size
|
||||||
size_t pageSize = (sFreeHeapSize + kHeapIncrement - 1)
|
size_t incrementAlignedSize = (sFreeHeapSize + kHeapIncrement - 1)
|
||||||
& ~(kHeapIncrement - 1);
|
& ~(kHeapIncrement - 1);
|
||||||
|
|
||||||
if (pageSize < sHeapAreaSize) {
|
if (incrementAlignedSize <= sHeapAreaSize) {
|
||||||
SERIAL_PRINT(("HEAP-%ld: heap area large enough for %ld\n", find_thread(NULL), size));
|
SERIAL_PRINT(("HEAP-%ld: heap area large enough for %ld\n",
|
||||||
|
find_thread(NULL), size));
|
||||||
// the area is large enough already
|
// the area is large enough already
|
||||||
hoardUnlock(sHeapLock);
|
hoardUnlock(sHeapLock);
|
||||||
return (void *)(sFreeHeapBase + oldHeapSize);
|
return (void *)(sFreeHeapBase + oldHeapSize);
|
||||||
@@ -210,16 +212,17 @@ hoardSbrk(long size)
|
|||||||
// We need to grow the area
|
// We need to grow the area
|
||||||
|
|
||||||
SERIAL_PRINT(("HEAP-%ld: need to resize heap area to %ld (%ld requested)\n",
|
SERIAL_PRINT(("HEAP-%ld: need to resize heap area to %ld (%ld requested)\n",
|
||||||
find_thread(NULL), pageSize, size));
|
find_thread(NULL), incrementAlignedSize, size));
|
||||||
|
|
||||||
if (resize_area(sHeapArea, pageSize) < B_OK) {
|
if (resize_area(sHeapArea, incrementAlignedSize) < B_OK) {
|
||||||
// out of memory - ToDo: as a fall back, we could try to allocate another area
|
// out of memory - TODO: as a fall back, we could try to allocate
|
||||||
|
// another area
|
||||||
sFreeHeapSize = oldHeapSize;
|
sFreeHeapSize = oldHeapSize;
|
||||||
hoardUnlock(sHeapLock);
|
hoardUnlock(sHeapLock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sHeapAreaSize = pageSize;
|
sHeapAreaSize = incrementAlignedSize;
|
||||||
|
|
||||||
hoardUnlock(sHeapLock);
|
hoardUnlock(sHeapLock);
|
||||||
return (void *)(sFreeHeapBase + oldHeapSize);
|
return (void *)(sFreeHeapBase + oldHeapSize);
|
||||||
|
|||||||
Reference in New Issue
Block a user