Add config option to use dlmalloc instead of mheap

Configure w/ --enable-dlmalloc, see .../build-data/platforms/vpp.mk

src/vppinfra/dlmalloc.[ch] are slightly modified versions of the
well-known Doug Lea malloc. Main advantage: dlmalloc mspaces have no
inherent size limit.

Change-Id: I19b3f43f3c65bcfb82c1a265a97922d01912446e
Signed-off-by: Dave Barach <dave@barachs.net>
diff --git a/src/vlib/linux/physmem.c b/src/vlib/linux/physmem.c
index a708aae..6c6b072 100755
--- a/src/vlib/linux/physmem.c
+++ b/src/vlib/linux/physmem.c
@@ -69,10 +69,18 @@
 
   while (1)
     {
+#if USE_DLMALLOC == 0
+
       mheap_get_aligned (pr->heap, n_bytes,
 			 /* align */ alignment,
 			 /* align offset */ 0,
 			 &lo_offset);
+#else
+      lo_offset = (uword) mspace_get_aligned (pr->heap, n_bytes,
+					      alignment, ~0ULL /* offset */ );
+      if (lo_offset == 0)
+	lo_offset = ~0ULL;
+#endif
 
       /* Allocation failed? */
       if (lo_offset == ~0)
@@ -94,7 +102,13 @@
     {
       uword i;
       for (i = 0; i < vec_len (to_free); i++)
-	mheap_put (pr->heap, to_free[i]);
+	{
+#if USE_DLMALLOC == 0
+	  mheap_put (pr->heap, to_free[i]);
+#else
+	  mspace_put_no_offset (pr->heap, (void *) to_free[i]);
+#endif
+	}
       vec_free (to_free);
     }
 
@@ -106,7 +120,11 @@
 {
   vlib_physmem_region_t *pr = vlib_physmem_get_region (vm, idx);
   /* Return object to region's heap. */
+#if USE_DLMALLOC == 0
   mheap_put (pr->heap, x - pr->heap);
+#else
+  mspace_put_no_offset (pr->heap, x);
+#endif
 }
 
 static clib_error_t *
@@ -181,10 +199,15 @@
 
   if (flags & VLIB_PHYSMEM_F_INIT_MHEAP)
     {
+#if USE_DLMALLOC == 0
       pr->heap = mheap_alloc_with_flags (pr->mem, pr->size,
 					 /* Don't want mheap mmap/munmap with IO memory. */
 					 MHEAP_FLAG_DISABLE_VM |
 					 MHEAP_FLAG_THREAD_SAFE);
+#else
+      pr->heap = create_mspace_with_base (pr->mem, pr->size, 1 /* locked */ );
+      mspace_disable_expand (pr->heap);
+#endif
     }
 
   *idx = pr->index;