* of memory, where the unfilled superblocks will be a small percentage of
* the total allocations.
*/
-static int mspan_size_classes[] = {
+static uint16 mspan_size_classes[] = {
8, 16, 24, 32, 40, 48, 56, 64, /* 8 classes separated by 8 bytes */
80, 96, 112, 128, /* 4 classes separated by 16 bytes */
160, 192, 224, 256, /* 4 classes separated by 32 bytes */
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23
};
+#define MSPAN_SIZE_CLASS_MAP_QUANTUM 8
/*
* We divide partially-filled superblocks into four fullness classes.
relptr_store(base, mgr->freecontext, cxt);
}
+/*
+ * Allocate memory.
+ */
+void *
+mspan_alloc(dsm_segment *seg, mspan_context *cxt, Size size, int flags)
+{
+ char *base = (seg != NULL ? dsm_segment_address(seg) : NULL);
+ uint16 size_class;
+
+ /* If it's bigger than the largest size class, allocate whole pages. */
+ if (size > mspan_size_classes[lengthof(mspan_size_classes) - 1])
+ {
+ Size pages = (size + MSPAN_PAGE_SIZE - 1) >> MSPAN_PAGE_BITS;
+ mspan *span;
+
+ span = mspan_find_free_span(base, mgr, pages, 0);
+ if (span != NULL)
+ {
+ /* XXX. Allocate the span, splitting it if required. */
+ /*
+ * XXX. Note that if we split a span than abutts the boundary,
+ * we should instead destroy it and move back the boundary.
+ */
+ }
+ else if (base != NULL)
+ {
+ /* XXX. Allocate from the boundary. */
+ }
+ else
+ {
+ /* XXX. Allocate a new segment via malloc. */
+ /*
+ * XXX. How exactly are we going to give the segments we malloc
+ * back to the OS? How are we even going to know where they are?
+ * We can add them to the freelists as a big old span, but that's
+ * not going to help much in terms of identifying them later.
+ */
+ }
+ }
+
+ /* Map allocation to a size class. */
+ if (size < lengthof(mspan_size_class_map) * MSPAN_SIZE_CLASS_MAP_QUANTUM)
+ {
+ int mapidx;
+
+ mapidx = (size + MSPAN_SIZE_CLASS_MAP_QUANTUM - 1) /
+ MSPAN_SIZE_CLASS_MAP_QUANTUM;
+ size_class = mspan_size_class_map[mapidx];
+ }
+ else
+ {
+ uint16 min = mspan_size_class_map[lengthof(mspan_size_class_map) - 1];
+ uint16 max = lengthof(mspan_size_classes) - 1;
+
+ for (;;)
+ {
+ uint16 mid = (min + max) / 2;
+
+ /* XXX bsearch */
+ }
+ }
+
+ /* XXX Search superblocks, etc. */
+}
+
/*
* Allocate new space for a new context descriptor.
*