Hack.
authorRobert Haas <[email protected]>
Fri, 13 Dec 2013 13:55:54 +0000 (08:55 -0500)
committerRobert Haas <[email protected]>
Thu, 6 Feb 2014 14:23:00 +0000 (09:23 -0500)
src/backend/utils/mmgr/mspan.c

index 9960216c1705bda95a87f494ed7d14f797dd3722..b22f4558e0d098c671b308c952296e3b365b3d39 100644 (file)
@@ -275,6 +275,7 @@ mspan_alloc(dsm_segment *seg, mspan_context *cxt, Size size, int flags)
        /* If it's bigger than the largest size class, allocate whole pages. */
        if (size > mspan_size_classes[lengthof(mspan_size_classes) - 1])
        {
+               mspan_manager *mgr = relptr_access(base, cxt->manager);
                Size    pages = (size + MSPAN_PAGE_SIZE - 1) >> MSPAN_PAGE_BITS;
                mspan  *span;
 
@@ -317,15 +318,29 @@ mspan_alloc(dsm_segment *seg, mspan_context *cxt, Size size, int flags)
                uint16  min = mspan_size_class_map[lengthof(mspan_size_class_map) - 1];
                uint16  max = lengthof(mspan_size_classes) - 1;
 
-               for (;;)
+               while (min < max)
                {
                        uint16  mid = (min + max) / 2;
+                       uint16  class_size = mspan_size_classes[mid];
 
-                       /* XXX bsearch */
+                       if (class_size < size)
+                               min = mid + 1;
+                       else
+                               max = mid;
                }
+
+               size_class = min;
        }
+       Assert(size <= mspan_size_classes[size_class]);
+
+       /*
+        * XXX Search existing superblocks for a chunk of memory.
+        */
 
-       /* XXX Search superblocks, etc. */
+       /*
+        * XXX If we couldn't find memory in an existing superblock, allocate
+        * a new superblock for the appropriate size class.
+        */
 }
 
 /*
@@ -451,7 +466,7 @@ mspan_destroy_span(char *base, mspan *span)
        /*
         * XXX. As a special case, the superblock descriptor for a span of
         * spans is always stored within the span itself.  Return the span
-        * to be destroyed to the superblock, and then, there's only 1 remaining
+        * to be destroyed to the superblock, and then, if there's only 1 remaining
         * span outstanding, nuke the whole superblock.
         */
 }