[haiku-commits] r34336 - haiku/trunk/src/system/libroot/posix/malloc

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 29 Nov 2009 10:20:58 +0100 (CET)

Author: bonefish
Date: 2009-11-29 10:20:58 +0100 (Sun, 29 Nov 2009)
New Revision: 34336
Changeset: http://dev.haiku-os.org/changeset/34336/haiku

Modified:
   haiku/trunk/src/system/libroot/posix/malloc/arch-specific.cpp
Log:
* 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.


Modified: haiku/trunk/src/system/libroot/posix/malloc/arch-specific.cpp
===================================================================
--- haiku/trunk/src/system/libroot/posix/malloc/arch-specific.cpp       
2009-11-29 02:15:54 UTC (rev 34335)
+++ haiku/trunk/src/system/libroot/posix/malloc/arch-specific.cpp       
2009-11-29 09:20:58 UTC (rev 34336)
@@ -51,11 +51,12 @@
 };
 
 
-static const size_t kInitialHeapSize = 50 * B_PAGE_SIZE;
-       // that's about what hoard allocates anyway
+static const size_t kInitialHeapSize = 64 * B_PAGE_SIZE;
+       // that's about what hoard allocates anyway (should be kHeapIncrement
+       // aligned)
 
 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 hoardLockType sHeapLock;
@@ -104,7 +105,7 @@
 
        atfork(&init_after_fork);
                // 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
                // acquire *all* allocator locks, so that we don't fork() an
                // inconsistent state.
@@ -196,12 +197,13 @@
        size_t oldHeapSize = sFreeHeapSize;
        sFreeHeapSize += size;
 
-       // round to next page size
-       size_t pageSize = (sFreeHeapSize + kHeapIncrement - 1)
+       // round to next heap increment aligned size
+       size_t incrementAlignedSize = (sFreeHeapSize + kHeapIncrement - 1)
                & ~(kHeapIncrement - 1);
 
-       if (pageSize < sHeapAreaSize) {
-               SERIAL_PRINT(("HEAP-%ld: heap area large enough for %ld\n", 
find_thread(NULL), size));
+       if (incrementAlignedSize <= sHeapAreaSize) {
+               SERIAL_PRINT(("HEAP-%ld: heap area large enough for %ld\n",
+                       find_thread(NULL), size));
                // the area is large enough already
                hoardUnlock(sHeapLock);
                return (void *)(sFreeHeapBase + oldHeapSize);
@@ -210,16 +212,17 @@
        // We need to grow the area
 
        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) {
-               // out of memory - ToDo: as a fall back, we could try to 
allocate another area
+       if (resize_area(sHeapArea, incrementAlignedSize) < B_OK) {
+               // out of memory - TODO: as a fall back, we could try to 
allocate
+               // another area
                sFreeHeapSize = oldHeapSize;
                hoardUnlock(sHeapLock);
                return NULL;
        }
 
-       sHeapAreaSize = pageSize;
+       sHeapAreaSize = incrementAlignedSize;
 
        hoardUnlock(sHeapLock);
        return (void *)(sFreeHeapBase + oldHeapSize);


Other related posts:

  • » [haiku-commits] r34336 - haiku/trunk/src/system/libroot/posix/malloc - ingo_weinhold