Hack.
authorRobert Haas <[email protected]>
Tue, 21 Jan 2014 14:13:16 +0000 (09:13 -0500)
committerRobert Haas <[email protected]>
Thu, 6 Feb 2014 14:23:01 +0000 (09:23 -0500)
src/backend/utils/mmgr/mspan.c

index 372bd9f2e6d5770916f538e6f30e2eb0ab3ef5d8..c0a81e5253ceb38e1644ba2867b42d1df7114669 100644 (file)
@@ -501,6 +501,33 @@ mspan_allocate_context_descriptor(char *base, mspan_manager *mgr)
 static char *
 mspan_allocate_from_superblock(char *base, mspan *superblock)
 {
+       char   *spanbase;
+       uint16  object_size;
+       uint16  total;
+
+       /* Quick exit if there are no free objects. */
+       object_size = mspan_size_classes[superblock->span_type];
+       total = MSPAN_SUPERBLOCK_SIZE / object_size;
+       if (superblock->nused >= total)
+               return NULL;
+
+       /* Try to reuse a previously-freed object. */
+       spanbase = base + superblock->first_page * MSPAN_PAGE_SIZE;
+       if (superblock->firstfree != MSPAN_FIRSTFREE_NONE)
+       {
+               uint16 *firstfree;
+
+               firstfree =
+                       (uint16 *) (spanbase + (superblock->firstfree * object_size));
+               superblock->firstfree = *firstfree;
+               return (char *) firstfree;
+       }
+
+       /*
+        * Carve out space from the uninitialized portion of the span.  This
+        * should always work, since we already verified that nused < total.
+        */
+
        /*
         * XXX. Implementation needed.
         */