summaryrefslogtreecommitdiffstats
path: root/src/lib/stdlib.C
diff options
context:
space:
mode:
authorDoug Gilbert <dgilbert@us.ibm.com>2011-09-26 13:36:33 -0500
committerDouglas R. Gilbert <dgilbert@us.ibm.com>2011-10-25 11:16:20 -0500
commit5ab488739184f2b2649193e3f9da695ee334d04f (patch)
tree3d47e74b8dd290598527988adccff0ff57c72dc0 /src/lib/stdlib.C
parentd127ad9d985ffd7a42dba798bee66654242c4fe6 (diff)
downloadtalos-hostboot-5ab488739184f2b2649193e3f9da695ee334d04f.tar.gz
talos-hostboot-5ab488739184f2b2649193e3f9da695ee334d04f.zip
new HEAP manager to reduce fragmentation
Change-Id: Ibe725a43e6366d9113ec99df1cc6aafa7bbb770e Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/431 Tested-by: Jenkins Server Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com> Reviewed-by: Douglas R. Gilbert <dgilbert@us.ibm.com>
Diffstat (limited to 'src/lib/stdlib.C')
-rw-r--r--src/lib/stdlib.C80
1 files changed, 36 insertions, 44 deletions
diff --git a/src/lib/stdlib.C b/src/lib/stdlib.C
index b7cf92455..d9fa9e9fc 100644
--- a/src/lib/stdlib.C
+++ b/src/lib/stdlib.C
@@ -25,63 +25,55 @@
#include <string.h>
#include <kernel/heapmgr.H>
#include <kernel/pagemgr.H>
+#include <kernel/console.H>
+
+
+#ifdef MEM_ALLOC_PROFILE
+// alloc profile
+uint16_t g_0 = 0;
+uint16_t g_8 = 0;
+uint16_t g_16 = 0;
+uint16_t g_32 = 0;
+uint16_t g_64 = 0;
+uint16_t g_128 = 0;
+uint16_t g_256 = 0;
+uint16_t g_512 = 0;
+uint16_t g_1k = 0;
+uint16_t g_2k = 0;
+uint16_t g_big = 0;
+#endif
void* malloc(size_t s)
{
- if (s > HeapManager::MAX_ALLOC_SIZE)
- {
- size_t pages = (s + 8 + (PAGESIZE - 1))
- / PAGESIZE;
- void* v = PageManager::allocatePage(pages);
- size_t* len = (size_t*)v;
- *len = pages << 8;
- len++;
- return len;
- }
- else
- return HeapManager::allocate(s);
+#ifdef MEM_ALLOC_PROFILE
+ if(s == 0) ++g_0;
+ else if (s <= 8) ++g_8;
+ else if (s <= 16) ++g_16;
+ else if (s <= 32) ++g_32;
+ else if (s <= 64) ++g_64;
+ else if (s <= 128) ++g_128;
+ else if (s <= 256) ++g_256;
+ else if (s <= 512) ++g_512;
+ else if (s <= 1024) ++g_1k;
+ else if (s <= 2048) ++g_2k;
+ else ++g_big;
+#endif
+ return HeapManager::allocate(s);
}
+
void free(void* p)
{
if (NULL == p) return;
- size_t* len = (size_t*)p;
- len--;
-
- if ((*len) > 0xff)
- {
- PageManager::freePage(len, (*len) >> 8);
- }
- else
- {
- HeapManager::free(p);
- }
+ HeapManager::free(p);
}
+
void* realloc(void* p, size_t s)
{
if (NULL == p) return malloc(s);
-
- size_t* len = (size_t*)p;
- len--;
-
- size_t cur_size;
- if ((*len) > 0xff)
- {
- cur_size = ((*len) >> 8) * PAGESIZE - 8;
- }
- else
- {
- cur_size = (1 << (*len + 4)) - 8;
- }
-
- if (s <= cur_size)
- return p;
- void* new_p = malloc(s);
- memcpy(new_p, p, cur_size);
- free(p);
+ return HeapManager::realloc(p,s);
+}
- return new_p;
-}
OpenPOWER on IntegriCloud