size_classes.sh revision 12a6845b6c91cf76caf3199495d76b16bba1f2fe
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 cat <<EOF 39#if (LG_TINY_MIN == ${lg_t} && LG_QUANTUM == ${lg_q} && LG_PAGE == ${lg_p}) 40#define SIZE_CLASSES_DEFINED 41EOF 42 pow2 ${lg_q}; q=${pow2_result} 43 pow2 ${lg_t}; t=${pow2_result} 44 pow2 ${lg_p}; p=${pow2_result} 45 bin=0 46 psz=0 47 sz=${t} 48 delta=$((${sz} - ${psz})) 49cat <<EOF 50/* SIZE_CLASS(bin, delta, sz) */ 51#define SIZE_CLASSES \\ 52EOF 53 54 # Tiny size classes. 55 while [ ${sz} -lt ${q} ] ; do 56 cat <<EOF 57 SIZE_CLASS(${bin}, ${delta}, ${sz}) \\ 58EOF 59 bin=$((${bin} + 1)) 60 psz=${sz} 61 sz=$((${sz} + ${sz})) 62 delta=$((${sz} - ${psz})) 63 done 64 # Quantum-multiple size classes. For each doubling of sz, as many as 4 65 # size classes exist. Their spacing is the greater of: 66 # - q 67 # - sz/4, where sz is a power of 2 68 while [ ${sz} -lt ${p} ] ; do 69 if [ ${sz} -ge $((${q} * 4)) ] ; then 70 i=$((${sz} / 4)) 71 else 72 i=${q} 73 fi 74 next_2pow=$((${sz} * 2)) 75 while [ ${sz} -lt $next_2pow ] ; do 76 cat <<EOF 77 SIZE_CLASS(${bin}, ${delta}, ${sz}) \\ 78EOF 79 bin=$((${bin} + 1)) 80 psz=${sz} 81 sz=$((${sz} + ${i})) 82 delta=$((${sz} - ${psz})) 83 done 84 done 85 cat <<EOF 86 87#define NBINS ${bin} 88#define SMALL_MAXCLASS ${psz} 89#endif 90 91EOF 92 lg_p=$((${lg_p} + 1)) 93 done 94 lg_t=$((${lg_t} + 1)) 95 done 96 lg_q=$((${lg_q} + 1)) 97done 98 99cat <<EOF 100#ifndef SIZE_CLASSES_DEFINED 101# error "No size class definitions match configuration" 102#endif 103#undef SIZE_CLASSES_DEFINED 104/* 105 * The small_size2bin lookup table uses uint8_t to encode each bin index, so we 106 * cannot support more than 256 small size classes. Further constrain NBINS to 107 * 255 to support prof_promote, since all small size classes, plus a "not 108 * small" size class must be stored in 8 bits of arena_chunk_map_t's bits 109 * field. 110 */ 111#if (NBINS > 255) 112# error "Too many small size classes" 113#endif 114 115#endif /* JEMALLOC_H_TYPES */ 116/******************************************************************************/ 117#ifdef JEMALLOC_H_STRUCTS 118 119 120#endif /* JEMALLOC_H_STRUCTS */ 121/******************************************************************************/ 122#ifdef JEMALLOC_H_EXTERNS 123 124 125#endif /* JEMALLOC_H_EXTERNS */ 126/******************************************************************************/ 127#ifdef JEMALLOC_H_INLINES 128 129 130#endif /* JEMALLOC_H_INLINES */ 131/******************************************************************************/ 132EOF 133