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

John Criswell criswell at cs.uiuc.edu
Thu Nov 13 11:34:01 PST 2003


Changes in directory poolalloc/runtime/FreeListAllocator:

PageManager.cpp updated: 1.4 -> 1.5
PageManager.h updated: 1.2 -> 1.3
PoolAllocator.cpp updated: 1.13 -> 1.14
PoolAllocator.h updated: 1.5 -> 1.6

---
Log message:

Remove the use of finding PageSize as a global variable.
That might have linking problems, and we'll probably want to do this anyway
for multi-page data blocks.



---
Diffs of the changes:  (+27 -15)

Index: poolalloc/runtime/FreeListAllocator/PageManager.cpp
diff -u poolalloc/runtime/FreeListAllocator/PageManager.cpp:1.4 poolalloc/runtime/FreeListAllocator/PageManager.cpp:1.5
--- poolalloc/runtime/FreeListAllocator/PageManager.cpp:1.4	Wed Nov 12 16:46:26 2003
+++ poolalloc/runtime/FreeListAllocator/PageManager.cpp	Thu Nov 13 11:33:30 2003
@@ -25,7 +25,7 @@
 // Empirically, this slows down the pool allocator a LOT.
 #define USE_MEMALIGN 0
 
-unsigned PageSize = 0;
+static unsigned PageSize = 0;
 
 // Explicitly use the malloc allocator here, to avoid depending on the C++
 // runtime library.
@@ -39,8 +39,13 @@
 //  This function initializes the Page Manager code.  It must be called before
 //  any other Page Manager functions are called.
 //
-void InitializePageManager() {
-  if (!PageSize) PageSize = sysconf(_SC_PAGESIZE);
+unsigned int InitializePageManager() {
+  if (!PageSize)
+  {
+    PageSize = sysconf(_SC_PAGESIZE);
+    FreePages = 0;
+  }
+  return PageSize;
 }
 
 #if !USE_MEMALIGN


Index: poolalloc/runtime/FreeListAllocator/PageManager.h
diff -u poolalloc/runtime/FreeListAllocator/PageManager.h:1.2 poolalloc/runtime/FreeListAllocator/PageManager.h:1.3
--- poolalloc/runtime/FreeListAllocator/PageManager.h:1.2	Tue Nov 11 14:13:42 2003
+++ poolalloc/runtime/FreeListAllocator/PageManager.h	Thu Nov 13 11:33:30 2003
@@ -18,13 +18,13 @@
 /// InitializePageManager - This function must be called before any other page
 /// manager accesses are performed.  It may be called multiple times.
 /// 
-void InitializePageManager();
+unsigned int InitializePageManager();
 
 /// PageSize - Contains the size of the unit of memory allocated by
 /// AllocatePage.  This is a value that is typically several kilobytes in size,
 /// and is guaranteed to be a power of two.
 ///
-extern unsigned PageSize;
+///extern unsigned PageSize;
 
 /// AllocatePage - This function returns a chunk of memory with size and
 /// alignment specified by getPageSize().


Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.13 poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.14
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.13	Tue Nov 11 20:46:21 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp	Thu Nov 13 11:33:30 2003
@@ -35,7 +35,7 @@
 //  Allocate memory for a new slab and initialize the slab.
 //
 struct SlabHeader *
-createSlab (unsigned int NodeSize, unsigned int NodesPerSlab = 0)
+createSlab (PoolTy * Pool, unsigned int NodesPerSlab = 0)
 {
   // Maximum number of nodes per page
   unsigned int MaxNodesPerPage;
@@ -43,6 +43,10 @@
   // Pointer to the new Slab
   struct SlabHeader * NewSlab;
 
+  // Save locally the node size
+  unsigned int NodeSize = Pool->NodeSize;
+  unsigned int PageSize = Pool->PageSize;
+
   //
   // Determine how many nodes can exist within a regular slab.
   //
@@ -53,7 +57,7 @@
   //
   if (NodeSize > PageSize)
   {
-    fprintf (stderr, "Node size is too big.\n");
+    fprintf (stderr, "Node size %d is larger than page size %d.\n", NodeSize, PageSize);
     fflush (stderr);
     abort();
   }
@@ -112,7 +116,7 @@
 //  Find the slab that owns this block.
 //
 struct SlabHeader *
-BlockOwner (NodePointer p)
+BlockOwner (unsigned int PageSize, NodePointer p)
 {
   //
   // Convert the node pointer into a slab pointer.
@@ -127,7 +131,7 @@
 //  This function finds the slab that owns this data block.
 //
 struct SlabHeader *
-DataOwner (void * p)
+DataOwner (unsigned int PageSize, void * p)
 {
   return reinterpret_cast<struct SlabHeader *>(reinterpret_cast<unsigned int>(p) & ~(PageSize - 1));
 }
@@ -179,7 +183,7 @@
   //
   // Initialize the page manager.
   //
-  InitializePageManager ();
+  Pool->PageSize = InitializePageManager ();
 
   return;
 }
@@ -237,7 +241,7 @@
   //
   if (Pool->Slabs == NULL)
   {
-    Pool->Slabs = createSlab (Pool->NodeSize);
+    Pool->Slabs = createSlab (Pool);
     (Pool->Slabs->NextFreeData)++;
     return (Pool->Slabs->Data);
   }
@@ -264,7 +268,7 @@
     //
     // Create a new slab and add it to the list.
     //
-    struct SlabHeader * NewSlab = createSlab (Pool->NodeSize);
+    struct SlabHeader * NewSlab = createSlab (Pool);
     NewSlab->Next = Pool->Slabs;
     Pool->Slabs = NewSlab;
 
@@ -286,7 +290,7 @@
   //
   // Determine which slab owns this block.
   //
-  struct SlabHeader * slabp = BlockOwner (Pool->FreeList);
+  struct SlabHeader * slabp = BlockOwner (Pool->PageSize, Pool->FreeList);
 
   //
   // Find the data block that corresponds with this pointer.
@@ -350,7 +354,7 @@
   //
   // Create a new slab and mark it as an array.
   //
-  struct SlabHeader * NewSlab = createSlab (Pool->NodeSize, ArraySize);
+  struct SlabHeader * NewSlab = createSlab (Pool, ArraySize);
   NewSlab->IsArray = 1;
 
   //
@@ -368,7 +372,7 @@
   //
   // Find the header of the memory block.
   //
-  struct SlabHeader * slabp = DataOwner (Block);
+  struct SlabHeader * slabp = DataOwner (Pool->PageSize, Block);
 
   //
   // If the owning slab is an array, add it back to the free array list.


Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.h
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.h:1.5 poolalloc/runtime/FreeListAllocator/PoolAllocator.h:1.6
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.h:1.5	Tue Nov 11 20:46:21 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.h	Thu Nov 13 11:33:30 2003
@@ -18,6 +18,9 @@
 #include "PoolSlab.h"
 
 typedef struct PoolTy {
+  // The size of a page on this system
+  unsigned int PageSize;
+
   // NodeSize - Keep track of the object size tracked by this pool
   unsigned NodeSize;
 





More information about the llvm-commits mailing list