aboutsummaryrefslogtreecommitdiff
path: root/include/jemalloc/internal/size_classes.sh
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2012-02-28 16:50:47 -0800
committerJason Evans <je@fb.com>2012-02-28 16:50:47 -0800
commitb172610317babc7f365584ddd7fdaf4eb8d9d04c (patch)
tree9c16ec02092d0a6f781072721679dcce7f3497dd /include/jemalloc/internal/size_classes.sh
parent5389146191b279ca3b90028357dd6ad66b283def (diff)
downloadjemalloc-b172610317babc7f365584ddd7fdaf4eb8d9d04c.tar.gz
Simplify small size class infrastructure.
Program-generate small size class tables for all valid combinations of LG_TINY_MIN, LG_QUANTUM, and PAGE_SHIFT. Use the appropriate table to generate all relevant data structures, and remove the distinction between tiny/quantum/cacheline/subpage bins. Remove --enable-dynamic-page-shift. This option didn't prove useful in practice, and it prevented optimizations. Add Tilera architecture support.
Diffstat (limited to 'include/jemalloc/internal/size_classes.sh')
-rwxr-xr-xinclude/jemalloc/internal/size_classes.sh132
1 files changed, 132 insertions, 0 deletions
diff --git a/include/jemalloc/internal/size_classes.sh b/include/jemalloc/internal/size_classes.sh
new file mode 100755
index 0000000..d8306a5
--- /dev/null
+++ b/include/jemalloc/internal/size_classes.sh
@@ -0,0 +1,132 @@
+#!/bin/sh
+
+# The following limits are chosen such that they cover all supported platforms.
+
+# Range of quanta.
+lg_qmin=3
+lg_qmax=4
+
+# The range of tiny size classes is [2^lg_tmin..2^(lg_q-1)].
+lg_tmin=3
+
+# Range of page sizes.
+lg_pmin=12
+lg_pmax=16
+
+function pow2() {
+ e=$1
+ pow2_result=1
+ while [ ${e} -gt 0 ] ; do
+ pow2_result=`expr ${pow2_result} + ${pow2_result}`
+ e=`expr ${e} - 1`
+ done
+}
+
+cat <<EOF
+/* This file was automatically generated by size_classes.sh. */
+/******************************************************************************/
+#ifdef JEMALLOC_H_TYPES
+
+EOF
+
+lg_q=${lg_qmin}
+while [ ${lg_q} -le ${lg_qmax} ] ; do
+ lg_t=${lg_tmin}
+ while [ ${lg_t} -le ${lg_q} ] ; do
+ lg_p=${lg_pmin}
+ while [ ${lg_p} -le ${lg_pmax} ] ; do
+ cat <<EOF
+#if (LG_TINY_MIN == ${lg_t} && LG_QUANTUM == ${lg_q} && PAGE_SHIFT == ${lg_p})
+#define SIZE_CLASSES_DEFINED
+EOF
+ pow2 ${lg_q}; q=${pow2_result}
+ pow2 ${lg_t}; t=${pow2_result}
+ pow2 ${lg_p}; p=${pow2_result}
+ bin=0
+ psz=0
+ sz=${t}
+ delta=`expr ${sz} - ${psz}`
+cat <<EOF
+/* SIZE_CLASS(bin, delta, sz) */
+#define SIZE_CLASSES \\
+EOF
+
+ # Tiny size classes.
+ while [ ${sz} -lt ${q} ] ; do
+ cat <<EOF
+ SIZE_CLASS(${bin}, ${delta}, ${sz}) \\
+EOF
+ bin=`expr ${bin} + 1`
+ psz=${sz}
+ sz=`expr ${sz} + ${sz}`
+ delta=`expr ${sz} - ${psz}`
+ done
+ # Quantum-multiple size classes. For each doubling of sz, as many as 4
+ # size classes exist. Their spacing is the greater of:
+ # - q
+ # - sz/4, where sz is a power of 2
+ while [ ${sz} -lt ${p} ] ; do
+ if [ ${sz} -ge `expr ${q} \* 4` ] ; then
+ i=`expr ${sz} / 4`
+ else
+ i=${q}
+ fi
+ next_2pow=`expr ${sz} \* 2`
+ while [ ${sz} -lt $next_2pow ] ; do
+ cat <<EOF
+ SIZE_CLASS(${bin}, ${delta}, ${sz}) \\
+EOF
+ bin=`expr ${bin} + 1`
+ psz=${sz}
+ sz=`expr ${sz} + ${i}`
+ delta=`expr ${sz} - ${psz}`
+ done
+ done
+ cat <<EOF
+
+#define NBINS ${bin}
+#define SMALL_MAXCLASS ${psz}
+#endif
+
+EOF
+ lg_p=`expr ${lg_p} + 1`
+ done
+ lg_t=`expr ${lg_t} + 1`
+ done
+ lg_q=`expr ${lg_q} + 1`
+done
+
+cat <<EOF
+#ifndef SIZE_CLASSES_DEFINED
+# error "No size class definitions match configuration"
+#endif
+#undef SIZE_CLASSES_DEFINED
+/*
+ * The small_size2bin lookup table uses uint8_t to encode each bin index, so we
+ * cannot support more than 256 small size classes. Further constrain NBINS to
+ * 255 to support prof_promote, since all small size classes, plus a "not
+ * small" size class must be stored in 8 bits of arena_chunk_map_t's bits
+ * field.
+ */
+#if (NBINS > 255)
+# error "Too many small size classes"
+#endif
+
+#endif /* JEMALLOC_H_TYPES */
+/******************************************************************************/
+#ifdef JEMALLOC_H_STRUCTS
+
+
+#endif /* JEMALLOC_H_STRUCTS */
+/******************************************************************************/
+#ifdef JEMALLOC_H_EXTERNS
+
+
+#endif /* JEMALLOC_H_EXTERNS */
+/******************************************************************************/
+#ifdef JEMALLOC_H_INLINES
+
+
+#endif /* JEMALLOC_H_INLINES */
+/******************************************************************************/
+EOF