size_classes.sh revision 72ca7220f21ef32f17d12cfde1bd9732d56fb872
1#!/bin/sh 2 3# The following limits are chosen such that they cover all supported platforms. 4 5# Range of quanta. 6lg_qmin=3 7lg_qmax=4 8 9# The range of tiny size classes is [2^lg_tmin..2^(lg_q-1)]. 10lg_tmin=3 11 12# Range of page sizes. 13lg_pmin=12 14lg_pmax=16 15 16pow2() { 17 e=$1 18 pow2_result=1 19 while [ ${e} -gt 0 ] ; do 20 pow2_result=$((${pow2_result} + ${pow2_result})) 21 e=$((${e} - 1)) 22 done 23} 24 25cat <<EOF 26/* This file was automatically generated by size_classes.sh. */ 27/******************************************************************************/ 28#ifdef JEMALLOC_H_TYPES 29 30EOF 31 32lg_q=${lg_qmin} 33while [ ${lg_q} -le ${lg_qmax} ] ; do 34 lg_t=${lg_tmin} 35 while [ ${lg_t} -le ${lg_q} ] ; do 36 lg_p=${lg_pmin} 37 while [ ${lg_p} -le ${lg_pmax} ] ; do 38 echo "#if (LG_TINY_MIN == ${lg_t} && LG_QUANTUM == ${lg_q} && LG_PAGE == ${lg_p})" 39 echo "#define SIZE_CLASSES_DEFINED" 40 pow2 ${lg_q}; q=${pow2_result} 41 pow2 ${lg_t}; t=${pow2_result} 42 pow2 ${lg_p}; p=${pow2_result} 43 bin=0 44 psz=0 45 sz=${t} 46 delta=$((${sz} - ${psz})) 47 echo "/* SIZE_CLASS(bin, delta, sz) */" 48 echo "#define SIZE_CLASSES \\" 49 50 # Tiny size classes. 51 while [ ${sz} -lt ${q} ] ; do 52 echo " SIZE_CLASS(${bin}, ${delta}, ${sz}) \\" 53 bin=$((${bin} + 1)) 54 psz=${sz} 55 sz=$((${sz} + ${sz})) 56 delta=$((${sz} - ${psz})) 57 done 58 # Quantum-multiple size classes. For each doubling of sz, as many as 4 59 # size classes exist. Their spacing is the greater of: 60 # - q 61 # - sz/4, where sz is a power of 2 62 while [ ${sz} -lt ${p} ] ; do 63 if [ ${sz} -ge $((${q} * 4)) ] ; then 64 i=$((${sz} / 4)) 65 else 66 i=${q} 67 fi 68 next_2pow=$((${sz} * 2)) 69 while [ ${sz} -lt $next_2pow ] ; do 70 echo " SIZE_CLASS(${bin}, ${delta}, ${sz}) \\" 71 bin=$((${bin} + 1)) 72 psz=${sz} 73 sz=$((${sz} + ${i})) 74 delta=$((${sz} - ${psz})) 75 done 76 done 77 echo 78 echo "#define NBINS ${bin}" 79 echo "#define SMALL_MAXCLASS ${psz}" 80 echo "#endif" 81 echo 82 lg_p=$((${lg_p} + 1)) 83 done 84 lg_t=$((${lg_t} + 1)) 85 done 86 lg_q=$((${lg_q} + 1)) 87done 88 89cat <<EOF 90#ifndef SIZE_CLASSES_DEFINED 91# error "No size class definitions match configuration" 92#endif 93#undef SIZE_CLASSES_DEFINED 94/* 95 * The small_size2bin lookup table uses uint8_t to encode each bin index, so we 96 * cannot support more than 256 small size classes. Further constrain NBINS to 97 * 255 to support prof_promote, since all small size classes, plus a "not 98 * small" size class must be stored in 8 bits of arena_chunk_map_t's bits 99 * field. 100 */ 101#if (NBINS > 255) 102# error "Too many small size classes" 103#endif 104 105#endif /* JEMALLOC_H_TYPES */ 106/******************************************************************************/ 107#ifdef JEMALLOC_H_STRUCTS 108 109 110#endif /* JEMALLOC_H_STRUCTS */ 111/******************************************************************************/ 112#ifdef JEMALLOC_H_EXTERNS 113 114 115#endif /* JEMALLOC_H_EXTERNS */ 116/******************************************************************************/ 117#ifdef JEMALLOC_H_INLINES 118 119 120#endif /* JEMALLOC_H_INLINES */ 121/******************************************************************************/ 122EOF 123