summaryrefslogtreecommitdiffstats
path: root/include/jemalloc/internal/size_classes.sh
diff options
context:
space:
mode:
Diffstat (limited to 'include/jemalloc/internal/size_classes.sh')
-rwxr-xr-xinclude/jemalloc/internal/size_classes.sh131
1 files changed, 87 insertions, 44 deletions
diff --git a/include/jemalloc/internal/size_classes.sh b/include/jemalloc/internal/size_classes.sh
index f6fbce4..998994d 100755
--- a/include/jemalloc/internal/size_classes.sh
+++ b/include/jemalloc/internal/size_classes.sh
@@ -40,6 +40,54 @@ lg() {
done
}
+lg_ceil() {
+ y=$1
+ lg ${y}; lg_floor=${lg_result}
+ pow2 ${lg_floor}; pow2_floor=${pow2_result}
+ if [ ${pow2_floor} -lt ${y} ] ; then
+ lg_ceil_result=$((${lg_floor} + 1))
+ else
+ lg_ceil_result=${lg_floor}
+ fi
+}
+
+reg_size_compute() {
+ lg_grp=$1
+ lg_delta=$2
+ ndelta=$3
+
+ pow2 ${lg_grp}; grp=${pow2_result}
+ pow2 ${lg_delta}; delta=${pow2_result}
+ reg_size=$((${grp} + ${delta}*${ndelta}))
+}
+
+slab_size() {
+ lg_p=$1
+ lg_grp=$2
+ lg_delta=$3
+ ndelta=$4
+
+ pow2 ${lg_p}; p=${pow2_result}
+ reg_size_compute ${lg_grp} ${lg_delta} ${ndelta}
+
+ # Compute smallest slab size that is an integer multiple of reg_size.
+ try_slab_size=${p}
+ try_nregs=$((${try_slab_size} / ${reg_size}))
+ perfect=0
+ while [ ${perfect} -eq 0 ] ; do
+ perfect_slab_size=${try_slab_size}
+ perfect_nregs=${try_nregs}
+
+ try_slab_size=$((${try_slab_size} + ${p}))
+ try_nregs=$((${try_slab_size} / ${reg_size}))
+ if [ ${perfect_slab_size} -eq $((${perfect_nregs} * ${reg_size})) ] ; then
+ perfect=1
+ fi
+ done
+
+ slab_size_pgs=$((${perfect_slab_size} / ${p}))
+}
+
size_class() {
index=$1
lg_grp=$2
@@ -80,8 +128,10 @@ size_class() {
if [ ${lg_size} -lt $((${lg_p} + ${lg_g})) ] ; then
bin="yes"
+ slab_size ${lg_p} ${lg_grp} ${lg_delta} ${ndelta}; pgs=${slab_size_pgs}
else
bin="no"
+ pgs=0
fi
if [ ${lg_size} -lt ${lg_kmax} \
-o ${lg_size} -eq ${lg_kmax} -a ${rem} = "no" ] ; then
@@ -89,10 +139,11 @@ size_class() {
else
lg_delta_lookup="no"
fi
- printf ' SC(%3d, %6d, %8d, %6d, %3s, %3s, %2s) \\\n' ${index} ${lg_grp} ${lg_delta} ${ndelta} ${psz} ${bin} ${lg_delta_lookup}
+ printf ' SC(%3d, %6d, %8d, %6d, %3s, %3s, %3d, %2s) \\\n' ${index} ${lg_grp} ${lg_delta} ${ndelta} ${psz} ${bin} ${pgs} ${lg_delta_lookup}
# Defined upon return:
# - psz ("yes" or "no")
# - bin ("yes" or "no")
+ # - pgs
# - lg_delta_lookup (${lg_delta} or "no")
}
@@ -110,8 +161,8 @@ size_classes() {
pow2 $((${lg_z} + 3)); ptr_bits=${pow2_result}
pow2 ${lg_g}; g=${pow2_result}
- echo "#define SIZE_CLASSES \\"
- echo " /* index, lg_grp, lg_delta, ndelta, psz, bin, lg_delta_lookup */ \\"
+ echo "#define SIZE_CLASSES \\"
+ echo " /* index, lg_grp, lg_delta, ndelta, psz, bin, pgs, lg_delta_lookup */ \\"
ntbins=0
nlbins=0
@@ -197,7 +248,7 @@ size_classes() {
fi
fi
# Final written value is correct:
- huge_maxclass="((((size_t)1) << ${lg_grp}) + (((size_t)${ndelta}) << ${lg_delta}))"
+ large_maxclass="((((size_t)1) << ${lg_grp}) + (((size_t)${ndelta}) << ${lg_delta}))"
index=$((${index} + 1))
ndelta=$((${ndelta} + 1))
done
@@ -206,53 +257,61 @@ size_classes() {
done
echo
nsizes=${index}
+ lg_ceil ${nsizes}; lg_ceil_nsizes=${lg_ceil_result}
# Defined upon completion:
# - ntbins
# - nlbins
# - nbins
# - nsizes
+ # - lg_ceil_nsizes
# - npsizes
# - lg_tiny_maxclass
# - lookup_maxclass
# - small_maxclass
# - lg_large_minclass
- # - huge_maxclass
+ # - large_maxclass
}
cat <<EOF
+#ifndef JEMALLOC_INTERNAL_SIZE_CLASSES_H
+#define JEMALLOC_INTERNAL_SIZE_CLASSES_H
+
/* This file was automatically generated by size_classes.sh. */
-/******************************************************************************/
-#ifdef JEMALLOC_H_TYPES
+
+#include "jemalloc/internal/jemalloc_internal_types.h"
/*
- * This header requires LG_SIZEOF_PTR, LG_TINY_MIN, LG_QUANTUM, and LG_PAGE to
- * be defined prior to inclusion, and it in turn defines:
+ * This header file defines:
*
* LG_SIZE_CLASS_GROUP: Lg of size class count for each size doubling.
+ * LG_TINY_MIN: Lg of minimum size class to support.
* SIZE_CLASSES: Complete table of SC(index, lg_grp, lg_delta, ndelta, psz,
- * bin, lg_delta_lookup) tuples.
+ * bin, pgs, lg_delta_lookup) tuples.
* index: Size class index.
* lg_grp: Lg group base size (no deltas added).
* lg_delta: Lg delta to previous size class.
* ndelta: Delta multiplier. size == 1<<lg_grp + ndelta<<lg_delta
* psz: 'yes' if a multiple of the page size, 'no' otherwise.
* bin: 'yes' if a small bin size class, 'no' otherwise.
+ * pgs: Slab page count if a small bin size class, 0 otherwise.
* lg_delta_lookup: Same as lg_delta if a lookup table size class, 'no'
* otherwise.
* NTBINS: Number of tiny bins.
* NLBINS: Number of bins supported by the lookup table.
* NBINS: Number of small size class bins.
* NSIZES: Number of size classes.
+ * LG_CEIL_NSIZES: Number of bits required to store NSIZES.
* NPSIZES: Number of size classes that are a multiple of (1U << LG_PAGE).
* LG_TINY_MAXCLASS: Lg of maximum tiny size class.
* LOOKUP_MAXCLASS: Maximum size class included in lookup table.
* SMALL_MAXCLASS: Maximum small size class.
* LG_LARGE_MINCLASS: Lg of minimum large size class.
- * HUGE_MAXCLASS: Maximum (huge) size class.
+ * LARGE_MAXCLASS: Maximum (large) size class.
*/
-#define LG_SIZE_CLASS_GROUP ${lg_g}
+#define LG_SIZE_CLASS_GROUP ${lg_g}
+#define LG_TINY_MIN ${lg_tmin}
EOF
@@ -264,17 +323,19 @@ for lg_z in ${lg_zarr} ; do
for lg_p in ${lg_parr} ; do
echo "#if (LG_SIZEOF_PTR == ${lg_z} && LG_TINY_MIN == ${lg_t} && LG_QUANTUM == ${lg_q} && LG_PAGE == ${lg_p})"
size_classes ${lg_z} ${lg_q} ${lg_t} ${lg_p} ${lg_g}
- echo "#define SIZE_CLASSES_DEFINED"
- echo "#define NTBINS ${ntbins}"
- echo "#define NLBINS ${nlbins}"
- echo "#define NBINS ${nbins}"
- echo "#define NSIZES ${nsizes}"
- echo "#define NPSIZES ${npsizes}"
- echo "#define LG_TINY_MAXCLASS ${lg_tiny_maxclass}"
- echo "#define LOOKUP_MAXCLASS ${lookup_maxclass}"
- echo "#define SMALL_MAXCLASS ${small_maxclass}"
- echo "#define LG_LARGE_MINCLASS ${lg_large_minclass}"
- echo "#define HUGE_MAXCLASS ${huge_maxclass}"
+ echo "#define SIZE_CLASSES_DEFINED"
+ echo "#define NTBINS ${ntbins}"
+ echo "#define NLBINS ${nlbins}"
+ echo "#define NBINS ${nbins}"
+ echo "#define NSIZES ${nsizes}"
+ echo "#define LG_CEIL_NSIZES ${lg_ceil_nsizes}"
+ echo "#define NPSIZES ${npsizes}"
+ echo "#define LG_TINY_MAXCLASS ${lg_tiny_maxclass}"
+ echo "#define LOOKUP_MAXCLASS ${lookup_maxclass}"
+ echo "#define SMALL_MAXCLASS ${small_maxclass}"
+ echo "#define LG_LARGE_MINCLASS ${lg_large_minclass}"
+ echo "#define LARGE_MINCLASS (ZU(1) << LG_LARGE_MINCLASS)"
+ echo "#define LARGE_MAXCLASS ${large_maxclass}"
echo "#endif"
echo
done
@@ -290,29 +351,11 @@ cat <<EOF
#undef SIZE_CLASSES_DEFINED
/*
* The size2index_tab 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 since all small size classes, plus a "not small" size class must be
- * stored in 8 bits of arena_chunk_map_bits_t's bits field.
+ * cannot support more than 256 small size classes.
*/
-#if (NBINS > 255)
+#if (NBINS > 256)
# 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 */
-/******************************************************************************/
+#endif /* JEMALLOC_INTERNAL_SIZE_CLASSES_H */
EOF