+ *
+ * Also if the allocation size is more than kalloc_kernmap_size
+ * then allocate from kernel map rather than kalloc_map.
+ */
+
+#if KALLOC_MINSIZE == 16 && KALLOC_LOG2_MINALIGN == 4
+
+/*
+ * "Legacy" aka "power-of-2" backing zones with 16-byte minimum
+ * size and alignment. Users of this profile would probably
+ * benefit from some tuning.
+ */
+
+#define K_ZONE_SIZES \
+ 16, \
+ 32, \
+/* 6 */ 64, \
+ 128, \
+ 256, \
+/* 9 */ 512, \
+ 1024, \
+ 2048, \
+/* C */ 4096
+
+
+#define K_ZONE_NAMES \
+ "kalloc.16", \
+ "kalloc.32", \
+/* 6 */ "kalloc.64", \
+ "kalloc.128", \
+ "kalloc.256", \
+/* 9 */ "kalloc.512", \
+ "kalloc.1024", \
+ "kalloc.2048", \
+/* C */ "kalloc.4096"
+
+#define K_ZONE_MAXIMA \
+ 1024, \
+ 4096, \
+/* 6 */ 4096, \
+ 4096, \
+ 4096, \
+/* 9 */ 1024, \
+ 1024, \
+ 1024, \
+/* C */ 1024
+
+#elif KALLOC_MINSIZE == 8 && KALLOC_LOG2_MINALIGN == 3
+
+/*
+ * Tweaked for ARM (and x64) in 04/2011
+ */
+
+#define K_ZONE_SIZES \
+/* 3 */ 8, \
+ 16, 24, \
+ 32, 40, 48, \
+/* 6 */ 64, 88, 112, \
+ 128, 192, \
+ 256, 384, \
+/* 9 */ 512, 768, \
+ 1024, 1536, \
+ 2048, 3072, \
+ 4096, 6144
+
+#define K_ZONE_NAMES \
+/* 3 */ "kalloc.8", \
+ "kalloc.16", "kalloc.24", \
+ "kalloc.32", "kalloc.40", "kalloc.48", \
+/* 6 */ "kalloc.64", "kalloc.88", "kalloc.112", \
+ "kalloc.128", "kalloc.192", \
+ "kalloc.256", "kalloc.384", \
+/* 9 */ "kalloc.512", "kalloc.768", \
+ "kalloc.1024", "kalloc.1536", \
+ "kalloc.2048", "kalloc.3072", \
+ "kalloc.4096", "kalloc.6144"
+
+#define K_ZONE_MAXIMA \
+/* 3 */ 1024, \
+ 1024, 1024, \
+ 4096, 4096, 4096, \
+/* 6 */ 4096, 4096, 4096, \
+ 4096, 4096, \
+ 4096, 4096, \
+/* 9 */ 1024, 1024, \
+ 1024, 1024, \
+ 1024, 1024, \
+/* C */ 1024, 64
+
+#else
+#error missing zone size parameters for kalloc
+#endif
+
+#define KALLOC_MINALIGN (1 << KALLOC_LOG2_MINALIGN)
+
+static const int k_zone_size[] = {
+ K_ZONE_SIZES,
+ 8192,
+ 16384,
+/* F */ 32768
+};
+
+#define N_K_ZONE (sizeof (k_zone_size) / sizeof (k_zone_size[0]))
+
+/*
+ * Many kalloc() allocations are for small structures containing a few
+ * pointers and longs - the k_zone_dlut[] direct lookup table, indexed by
+ * size normalized to the minimum alignment, finds the right zone index
+ * for them in one dereference.
+ */
+
+#define INDEX_ZDLUT(size) \
+ (((size) + KALLOC_MINALIGN - 1) / KALLOC_MINALIGN)
+#define N_K_ZDLUT (2048 / KALLOC_MINALIGN)
+ /* covers sizes [0 .. 2048 - KALLOC_MINALIGN] */
+#define MAX_SIZE_ZDLUT ((N_K_ZDLUT - 1) * KALLOC_MINALIGN)
+
+static int8_t k_zone_dlut[N_K_ZDLUT]; /* table of indices into k_zone[] */
+
+/*
+ * If there's no hit in the DLUT, then start searching from k_zindex_start.