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

John Criswell criswell at cs.uiuc.edu
Fri May 27 13:46:36 PDT 2005



Changes in directory llvm-poolalloc/runtime/FL2Allocator:

PoolAllocator.cpp updated: 1.49 -> 1.50
---
Log message:

Change the stagger value to be unsigned to prevent wrap-around bugs.
Wrap the stagger value back to zero if we stagger more than the size of
the pool.  This should prevent waste of the virtual address space in
case that the program has a lot of pools.
Added comments and renamed variables to be more meaningful.


---
Diffs of the changes:  (+23 -6)

 PoolAllocator.cpp |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)


Index: llvm-poolalloc/runtime/FL2Allocator/PoolAllocator.cpp
diff -u llvm-poolalloc/runtime/FL2Allocator/PoolAllocator.cpp:1.49 llvm-poolalloc/runtime/FL2Allocator/PoolAllocator.cpp:1.50
--- llvm-poolalloc/runtime/FL2Allocator/PoolAllocator.cpp:1.49	Fri May 27 15:21:35 2005
+++ llvm-poolalloc/runtime/FL2Allocator/PoolAllocator.cpp	Fri May 27 15:46:20 2005
@@ -10,6 +10,8 @@
 // This file is one possible implementation of the LLVM pool allocator runtime
 // library.
 //
+// FIXME:
+//  The pointer compression functions are not thread safe.
 //===----------------------------------------------------------------------===//
 
 #include "PoolAllocator.h"
@@ -883,7 +885,8 @@
                   unsigned DeclaredSize, unsigned ObjAlignment) {
   poolinit_internal(Pool, DeclaredSize, ObjAlignment);
 
-  static int count=0;
+  // The number of nodes to stagger in the mmap'ed pool
+  static unsigned stagger=0;
 
   // Create the pool.  We have to do this eagerly (instead of on the first
   // allocation), because code may want to eagerly copy the pool base into a
@@ -897,14 +900,28 @@
       break;
     }
 
+  //
+  // Wrap the stagger value back to zero if we're past the size of the pool.
+  // This way, we always reserve less than 2*POOLSIZE of the virtual address
+  // space.
+  //
+  if ((stagger * DeclaredSize) >= POOLSIZE)
+    stagger = 0;
+
   if (Pool->Slabs == 0) {
+    //
     // Didn't find an existing pool, create one.
+    //
+    // To create a pool, we stagger the beginning of the pool so that pools
+    // do not end up starting on the same page boundary (creating extra cache
+    // conflicts).
+    //
     Pool->Slabs = (PoolSlab<CompressedPoolTraits>*)
-                      AllocateSpaceWithMMAP(POOLSIZE + (DeclaredSize * count), true);
-    Pool->Slabs += (DeclaredSize * count);
-#if 1
-    count++;
-#endif
+                      AllocateSpaceWithMMAP(POOLSIZE + (DeclaredSize * stagger), true);
+    Pool->Slabs += (DeclaredSize * stagger);
+
+    // Increase the stagger amount by one node.
+    stagger++;
     DO_IF_TRACE(fprintf(stderr, "RESERVED ADDR SPACE: %p -> %p\n",
                         Pool->Slabs, (char*)Pool->Slabs+POOLSIZE));
   }






More information about the llvm-commits mailing list