2012-02-29 08:50:47 +08:00
|
|
|
#!/bin/sh
|
2014-10-10 08:54:06 +08:00
|
|
|
#
|
2014-10-11 13:34:25 +08:00
|
|
|
# Usage: size_classes.sh <lg_qarr> <lg_tmin> <lg_parr> <lg_g>
|
2012-02-29 08:50:47 +08:00
|
|
|
|
|
|
|
# The following limits are chosen such that they cover all supported platforms.
|
|
|
|
|
2014-05-29 07:11:55 +08:00
|
|
|
# Pointer sizes.
|
|
|
|
lg_zarr="2 3"
|
|
|
|
|
|
|
|
# Quanta.
|
2014-10-11 13:34:25 +08:00
|
|
|
lg_qarr=$1
|
2012-02-29 08:50:47 +08:00
|
|
|
|
|
|
|
# The range of tiny size classes is [2^lg_tmin..2^(lg_q-1)].
|
2014-10-11 13:34:25 +08:00
|
|
|
lg_tmin=$2
|
2012-02-29 08:50:47 +08:00
|
|
|
|
2014-05-29 07:11:55 +08:00
|
|
|
# Maximum lookup size.
|
|
|
|
lg_kmax=12
|
|
|
|
|
|
|
|
# Page sizes.
|
2014-10-11 13:34:25 +08:00
|
|
|
lg_parr=`echo $3 | tr ',' ' '`
|
2014-05-29 07:11:55 +08:00
|
|
|
|
|
|
|
# Size class group size (number of size classes for each size doubling).
|
2014-10-11 13:34:25 +08:00
|
|
|
lg_g=$4
|
2012-02-29 08:50:47 +08:00
|
|
|
|
2012-03-13 02:33:59 +08:00
|
|
|
pow2() {
|
2012-02-29 08:50:47 +08:00
|
|
|
e=$1
|
|
|
|
pow2_result=1
|
|
|
|
while [ ${e} -gt 0 ] ; do
|
2012-04-04 04:20:21 +08:00
|
|
|
pow2_result=$((${pow2_result} + ${pow2_result}))
|
|
|
|
e=$((${e} - 1))
|
2012-02-29 08:50:47 +08:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2014-05-29 07:11:55 +08:00
|
|
|
lg() {
|
|
|
|
x=$1
|
|
|
|
lg_result=0
|
|
|
|
while [ ${x} -gt 1 ] ; do
|
|
|
|
lg_result=$((${lg_result} + 1))
|
|
|
|
x=$((${x} / 2))
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-04-09 05:17:57 +08:00
|
|
|
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}))
|
|
|
|
}
|
|
|
|
|
2016-04-07 20:04:12 +08:00
|
|
|
run_size() {
|
|
|
|
lg_p=$1
|
|
|
|
lg_grp=$2
|
|
|
|
lg_delta=$3
|
|
|
|
ndelta=$4
|
|
|
|
|
|
|
|
pow2 ${lg_p}; p=${pow2_result}
|
2016-04-09 05:17:57 +08:00
|
|
|
reg_size_compute ${lg_grp} ${lg_delta} ${ndelta}
|
2016-04-07 20:04:12 +08:00
|
|
|
|
|
|
|
# Compute smallest run size that is an integer multiple of reg_size.
|
|
|
|
try_run_size=${p}
|
|
|
|
try_nregs=$((${try_run_size} / ${reg_size}))
|
|
|
|
perfect=0
|
|
|
|
while [ ${perfect} -eq 0 ] ; do
|
|
|
|
perfect_run_size=${try_run_size}
|
|
|
|
perfect_nregs=${try_nregs}
|
|
|
|
|
|
|
|
try_run_size=$((${try_run_size} + ${p}))
|
|
|
|
try_nregs=$((${try_run_size} / ${reg_size}))
|
|
|
|
if [ ${perfect_run_size} -eq $((${perfect_nregs} * ${reg_size})) ] ; then
|
|
|
|
perfect=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
run_size_pgs=$((${perfect_run_size} / ${p}))
|
|
|
|
}
|
|
|
|
|
2014-05-29 07:11:55 +08:00
|
|
|
size_class() {
|
|
|
|
index=$1
|
|
|
|
lg_grp=$2
|
|
|
|
lg_delta=$3
|
|
|
|
ndelta=$4
|
|
|
|
lg_p=$5
|
|
|
|
lg_kmax=$6
|
|
|
|
|
2016-04-18 07:16:11 +08:00
|
|
|
if [ ${lg_delta} -ge ${lg_p} ] ; then
|
|
|
|
psz="yes"
|
|
|
|
else
|
|
|
|
pow2 ${lg_p}; p=${pow2_result}
|
|
|
|
pow2 ${lg_grp}; grp=${pow2_result}
|
|
|
|
pow2 ${lg_delta}; delta=${pow2_result}
|
|
|
|
sz=$((${grp} + ${delta} * ${ndelta}))
|
|
|
|
npgs=$((${sz} / ${p}))
|
|
|
|
if [ ${sz} -eq $((${npgs} * ${p})) ] ; then
|
|
|
|
psz="yes"
|
|
|
|
else
|
|
|
|
psz="no"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2014-05-29 07:11:55 +08:00
|
|
|
lg ${ndelta}; lg_ndelta=${lg_result}; pow2 ${lg_ndelta}
|
|
|
|
if [ ${pow2_result} -lt ${ndelta} ] ; then
|
|
|
|
rem="yes"
|
|
|
|
else
|
|
|
|
rem="no"
|
|
|
|
fi
|
|
|
|
|
|
|
|
lg_size=${lg_grp}
|
|
|
|
if [ $((${lg_delta} + ${lg_ndelta})) -eq ${lg_grp} ] ; then
|
|
|
|
lg_size=$((${lg_grp} + 1))
|
|
|
|
else
|
|
|
|
lg_size=${lg_grp}
|
|
|
|
rem="yes"
|
|
|
|
fi
|
|
|
|
|
2014-10-06 08:54:10 +08:00
|
|
|
if [ ${lg_size} -lt $((${lg_p} + ${lg_g})) ] ; then
|
2014-05-29 07:11:55 +08:00
|
|
|
bin="yes"
|
2016-04-07 20:04:12 +08:00
|
|
|
run_size ${lg_p} ${lg_grp} ${lg_delta} ${ndelta}; pgs=${run_size_pgs}
|
2014-05-29 07:11:55 +08:00
|
|
|
else
|
|
|
|
bin="no"
|
2016-04-07 20:04:12 +08:00
|
|
|
pgs=0
|
2014-05-29 07:11:55 +08:00
|
|
|
fi
|
|
|
|
if [ ${lg_size} -lt ${lg_kmax} \
|
|
|
|
-o ${lg_size} -eq ${lg_kmax} -a ${rem} = "no" ] ; then
|
|
|
|
lg_delta_lookup=${lg_delta}
|
|
|
|
else
|
|
|
|
lg_delta_lookup="no"
|
|
|
|
fi
|
2016-04-18 07:16:11 +08:00
|
|
|
printf ' SC(%3d, %6d, %8d, %6d, %3s, %3s, %3d, %2s) \\\n' ${index} ${lg_grp} ${lg_delta} ${ndelta} ${psz} ${bin} ${pgs} ${lg_delta_lookup}
|
2014-05-29 07:11:55 +08:00
|
|
|
# Defined upon return:
|
2016-04-18 07:16:11 +08:00
|
|
|
# - psz ("yes" or "no")
|
2014-05-29 07:11:55 +08:00
|
|
|
# - bin ("yes" or "no")
|
2016-04-07 20:04:12 +08:00
|
|
|
# - pgs
|
|
|
|
# - lg_delta_lookup (${lg_delta} or "no")
|
2014-05-29 07:11:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sep_line() {
|
2016-04-18 07:16:11 +08:00
|
|
|
echo " \\"
|
2014-05-29 07:11:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size_classes() {
|
|
|
|
lg_z=$1
|
|
|
|
lg_q=$2
|
|
|
|
lg_t=$3
|
|
|
|
lg_p=$4
|
|
|
|
lg_g=$5
|
|
|
|
|
|
|
|
pow2 $((${lg_z} + 3)); ptr_bits=${pow2_result}
|
|
|
|
pow2 ${lg_g}; g=${pow2_result}
|
|
|
|
|
|
|
|
echo "#define SIZE_CLASSES \\"
|
2016-04-18 07:16:11 +08:00
|
|
|
echo " /* index, lg_grp, lg_delta, ndelta, psz, bin, pgs, lg_delta_lookup */ \\"
|
2014-05-29 07:11:55 +08:00
|
|
|
|
|
|
|
ntbins=0
|
|
|
|
nlbins=0
|
|
|
|
lg_tiny_maxclass='"NA"'
|
|
|
|
nbins=0
|
2016-04-18 07:16:11 +08:00
|
|
|
npsizes=0
|
2014-05-29 07:11:55 +08:00
|
|
|
|
|
|
|
# Tiny size classes.
|
|
|
|
ndelta=0
|
|
|
|
index=0
|
|
|
|
lg_grp=${lg_t}
|
|
|
|
lg_delta=${lg_grp}
|
|
|
|
while [ ${lg_grp} -lt ${lg_q} ] ; do
|
|
|
|
size_class ${index} ${lg_grp} ${lg_delta} ${ndelta} ${lg_p} ${lg_kmax}
|
|
|
|
if [ ${lg_delta_lookup} != "no" ] ; then
|
|
|
|
nlbins=$((${index} + 1))
|
|
|
|
fi
|
2016-04-18 07:16:11 +08:00
|
|
|
if [ ${psz} = "yes" ] ; then
|
|
|
|
npsizes=$((${npsizes} + 1))
|
|
|
|
fi
|
2014-05-29 07:11:55 +08:00
|
|
|
if [ ${bin} != "no" ] ; then
|
|
|
|
nbins=$((${index} + 1))
|
|
|
|
fi
|
|
|
|
ntbins=$((${ntbins} + 1))
|
|
|
|
lg_tiny_maxclass=${lg_grp} # Final written value is correct.
|
|
|
|
index=$((${index} + 1))
|
|
|
|
lg_delta=${lg_grp}
|
|
|
|
lg_grp=$((${lg_grp} + 1))
|
|
|
|
done
|
|
|
|
|
|
|
|
# First non-tiny group.
|
|
|
|
if [ ${ntbins} -gt 0 ] ; then
|
|
|
|
sep_line
|
|
|
|
# The first size class has an unusual encoding, because the size has to be
|
|
|
|
# split between grp and delta*ndelta.
|
|
|
|
lg_grp=$((${lg_grp} - 1))
|
|
|
|
ndelta=1
|
|
|
|
size_class ${index} ${lg_grp} ${lg_delta} ${ndelta} ${lg_p} ${lg_kmax}
|
|
|
|
index=$((${index} + 1))
|
|
|
|
lg_grp=$((${lg_grp} + 1))
|
|
|
|
lg_delta=$((${lg_delta} + 1))
|
2016-04-18 07:16:11 +08:00
|
|
|
if [ ${psz} = "yes" ] ; then
|
|
|
|
npsizes=$((${npsizes} + 1))
|
|
|
|
fi
|
2014-05-29 07:11:55 +08:00
|
|
|
fi
|
|
|
|
while [ ${ndelta} -lt ${g} ] ; do
|
|
|
|
size_class ${index} ${lg_grp} ${lg_delta} ${ndelta} ${lg_p} ${lg_kmax}
|
|
|
|
index=$((${index} + 1))
|
|
|
|
ndelta=$((${ndelta} + 1))
|
2016-04-18 07:16:11 +08:00
|
|
|
if [ ${psz} = "yes" ] ; then
|
|
|
|
npsizes=$((${npsizes} + 1))
|
|
|
|
fi
|
2014-05-29 07:11:55 +08:00
|
|
|
done
|
|
|
|
|
|
|
|
# All remaining groups.
|
|
|
|
lg_grp=$((${lg_grp} + ${lg_g}))
|
2016-02-26 07:29:49 +08:00
|
|
|
while [ ${lg_grp} -lt $((${ptr_bits} - 1)) ] ; do
|
2014-05-29 07:11:55 +08:00
|
|
|
sep_line
|
|
|
|
ndelta=1
|
2016-02-26 07:29:49 +08:00
|
|
|
if [ ${lg_grp} -eq $((${ptr_bits} - 2)) ] ; then
|
2014-05-29 07:11:55 +08:00
|
|
|
ndelta_limit=$((${g} - 1))
|
|
|
|
else
|
|
|
|
ndelta_limit=${g}
|
|
|
|
fi
|
|
|
|
while [ ${ndelta} -le ${ndelta_limit} ] ; do
|
|
|
|
size_class ${index} ${lg_grp} ${lg_delta} ${ndelta} ${lg_p} ${lg_kmax}
|
|
|
|
if [ ${lg_delta_lookup} != "no" ] ; then
|
|
|
|
nlbins=$((${index} + 1))
|
|
|
|
# Final written value is correct:
|
|
|
|
lookup_maxclass="((((size_t)1) << ${lg_grp}) + (((size_t)${ndelta}) << ${lg_delta}))"
|
|
|
|
fi
|
2016-04-18 07:16:11 +08:00
|
|
|
if [ ${psz} = "yes" ] ; then
|
|
|
|
npsizes=$((${npsizes} + 1))
|
|
|
|
fi
|
2014-05-29 07:11:55 +08:00
|
|
|
if [ ${bin} != "no" ] ; then
|
|
|
|
nbins=$((${index} + 1))
|
|
|
|
# Final written value is correct:
|
|
|
|
small_maxclass="((((size_t)1) << ${lg_grp}) + (((size_t)${ndelta}) << ${lg_delta}))"
|
2014-10-10 08:54:06 +08:00
|
|
|
if [ ${lg_g} -gt 0 ] ; then
|
|
|
|
lg_large_minclass=$((${lg_grp} + 1))
|
|
|
|
else
|
|
|
|
lg_large_minclass=$((${lg_grp} + 2))
|
|
|
|
fi
|
2014-05-29 07:11:55 +08:00
|
|
|
fi
|
2015-09-12 07:18:53 +08:00
|
|
|
# Final written value is correct:
|
|
|
|
huge_maxclass="((((size_t)1) << ${lg_grp}) + (((size_t)${ndelta}) << ${lg_delta}))"
|
2014-05-29 07:11:55 +08:00
|
|
|
index=$((${index} + 1))
|
|
|
|
ndelta=$((${ndelta} + 1))
|
|
|
|
done
|
|
|
|
lg_grp=$((${lg_grp} + 1))
|
|
|
|
lg_delta=$((${lg_delta} + 1))
|
|
|
|
done
|
|
|
|
echo
|
2014-10-06 08:54:10 +08:00
|
|
|
nsizes=${index}
|
2014-05-29 07:11:55 +08:00
|
|
|
|
|
|
|
# Defined upon completion:
|
|
|
|
# - ntbins
|
|
|
|
# - nlbins
|
|
|
|
# - nbins
|
2014-10-06 08:54:10 +08:00
|
|
|
# - nsizes
|
2016-04-18 07:16:11 +08:00
|
|
|
# - npsizes
|
2014-05-29 07:11:55 +08:00
|
|
|
# - lg_tiny_maxclass
|
|
|
|
# - lookup_maxclass
|
|
|
|
# - small_maxclass
|
2014-10-06 08:54:10 +08:00
|
|
|
# - lg_large_minclass
|
2015-09-12 07:18:53 +08:00
|
|
|
# - huge_maxclass
|
2014-05-29 07:11:55 +08:00
|
|
|
}
|
|
|
|
|
2012-02-29 08:50:47 +08:00
|
|
|
cat <<EOF
|
|
|
|
/* This file was automatically generated by size_classes.sh. */
|
|
|
|
/******************************************************************************/
|
|
|
|
#ifdef JEMALLOC_H_TYPES
|
|
|
|
|
2014-05-29 07:11:55 +08:00
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*
|
|
|
|
* LG_SIZE_CLASS_GROUP: Lg of size class count for each size doubling.
|
2016-04-18 07:16:11 +08:00
|
|
|
* SIZE_CLASSES: Complete table of SC(index, lg_grp, lg_delta, ndelta, psz,
|
|
|
|
* bin, pgs, lg_delta_lookup) tuples.
|
2014-05-29 07:11:55 +08:00
|
|
|
* 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
|
2016-04-18 07:16:11 +08:00
|
|
|
* psz: 'yes' if a multiple of the page size, 'no' otherwise.
|
2014-05-29 07:11:55 +08:00
|
|
|
* bin: 'yes' if a small bin size class, 'no' otherwise.
|
2016-04-07 20:04:12 +08:00
|
|
|
* pgs: Run page count if a small bin size class, 0 otherwise.
|
2014-05-29 07:11:55 +08:00
|
|
|
* 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.
|
2014-10-06 08:54:10 +08:00
|
|
|
* NSIZES: Number of size classes.
|
2016-04-18 07:16:11 +08:00
|
|
|
* NPSIZES: Number of size classes that are a multiple of (1U << LG_PAGE).
|
2014-05-29 07:11:55 +08:00
|
|
|
* LG_TINY_MAXCLASS: Lg of maximum tiny size class.
|
|
|
|
* LOOKUP_MAXCLASS: Maximum size class included in lookup table.
|
|
|
|
* SMALL_MAXCLASS: Maximum small size class.
|
2014-10-06 08:54:10 +08:00
|
|
|
* LG_LARGE_MINCLASS: Lg of minimum large size class.
|
2015-09-12 07:18:53 +08:00
|
|
|
* HUGE_MAXCLASS: Maximum (huge) size class.
|
2014-05-29 07:11:55 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define LG_SIZE_CLASS_GROUP ${lg_g}
|
|
|
|
|
2012-02-29 08:50:47 +08:00
|
|
|
EOF
|
|
|
|
|
2014-05-29 07:11:55 +08:00
|
|
|
for lg_z in ${lg_zarr} ; do
|
|
|
|
for lg_q in ${lg_qarr} ; do
|
|
|
|
lg_t=${lg_tmin}
|
|
|
|
while [ ${lg_t} -le ${lg_q} ] ; do
|
|
|
|
# Iterate through page sizes and compute how many bins there are.
|
|
|
|
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}"
|
2014-10-06 08:54:10 +08:00
|
|
|
echo "#define NSIZES ${nsizes}"
|
2016-04-18 07:16:11 +08:00
|
|
|
echo "#define NPSIZES ${npsizes}"
|
2014-05-29 07:11:55 +08:00
|
|
|
echo "#define LG_TINY_MAXCLASS ${lg_tiny_maxclass}"
|
|
|
|
echo "#define LOOKUP_MAXCLASS ${lookup_maxclass}"
|
|
|
|
echo "#define SMALL_MAXCLASS ${small_maxclass}"
|
2014-10-06 08:54:10 +08:00
|
|
|
echo "#define LG_LARGE_MINCLASS ${lg_large_minclass}"
|
2015-09-12 07:18:53 +08:00
|
|
|
echo "#define HUGE_MAXCLASS ${huge_maxclass}"
|
2014-05-29 07:11:55 +08:00
|
|
|
echo "#endif"
|
|
|
|
echo
|
2012-02-29 08:50:47 +08:00
|
|
|
done
|
2014-05-29 07:11:55 +08:00
|
|
|
lg_t=$((${lg_t} + 1))
|
2012-02-29 08:50:47 +08:00
|
|
|
done
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
#ifndef SIZE_CLASSES_DEFINED
|
|
|
|
# error "No size class definitions match configuration"
|
|
|
|
#endif
|
|
|
|
#undef SIZE_CLASSES_DEFINED
|
|
|
|
/*
|
2014-10-06 08:54:10 +08:00
|
|
|
* The size2index_tab lookup table uses uint8_t to encode each bin index, so we
|
2012-02-29 08:50:47 +08:00
|
|
|
* cannot support more than 256 small size classes. Further constrain NBINS to
|
2014-04-12 05:24:51 +08:00
|
|
|
* 255 since all small size classes, plus a "not small" size class must be
|
2014-08-30 04:34:40 +08:00
|
|
|
* stored in 8 bits of arena_chunk_map_bits_t's bits field.
|
2012-02-29 08:50:47 +08:00
|
|
|
*/
|
|
|
|
#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
|