[llvm-commits] CVS: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp

John Criswell criswell at cs.uiuc.edu
Tue Nov 11 10:13:01 PST 2003


Changes in directory poolalloc/runtime/FreeListAllocator:

PoolAllocator.cpp updated: 1.8 -> 1.9

---
Log message:

When allocating arrays, round the number of nodes per slab up to the
maximum that the slab can hold.  This keeps us from wasting space by
allowing us to re-use the entire slab used by a previous array.

The NodesPerSlab value will become more important later when we allow
slabs to contain multiple, contiguous memory pages.



---
Diffs of the changes:  (+19 -4)

Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.8 poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.9
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.8	Tue Nov 11 09:59:55 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp	Tue Nov 11 10:12:14 2003
@@ -36,6 +36,9 @@
 struct SlabHeader *
 createSlab (unsigned int NodeSize, unsigned int NodesPerSlab = 0)
 {
+  // Maximum number of nodes per slab
+  unsigned int MaxNodesPerSlab;
+
   // Pointer to the new Slab
   struct SlabHeader * NewSlab;
 
@@ -46,10 +49,22 @@
   //
   // Determine how many nodes should exist within a slab.
   //
-  if (NodesPerSlab == 0)
-  {
-    NodesPerSlab = (PageSize - sizeof (struct SlabHeader)) / (sizeof (unsigned char *) + NodeSize);
-  }
+  MaxNodesPerSlab = (PageSize - sizeof (struct SlabHeader)) / (sizeof (unsigned char *) + NodeSize);
+  assert ((MaxNodesPerSlab >= NodesPerSlab) && "Too many nodes requested");
+
+  //
+  // Regardless of what the caller asked for, allocate the maximum number of
+  // nodes available in a page.
+  //
+  // This is the default behavior for regular nodes, and for arrays, we want to
+  // round up to the nearest slab so that we don't waste space when we use the
+  // array memory.
+  //
+  // FIXME:
+  //  Specifying the number of nodes that you want will come into play once
+  //  we allow pool allocations to span multiple memory pages.
+  //
+  NodesPerSlab = MaxNodesPerSlab;
 
   //
   // Determine the size of the slab.





More information about the llvm-commits mailing list