Add --with-lg-tiny-min, generalize --with-lg-quantum.

This commit is contained in:
Jason Evans 2014-10-10 22:34:25 -07:00
parent 2eb941a3d3
commit 81e547566e
6 changed files with 105 additions and 16 deletions

32
INSTALL
View File

@ -230,10 +230,9 @@ any of the following arguments (not a definitive list) to 'configure':
roughly <lg-size-class-group>=4, depending on page size. roughly <lg-size-class-group>=4, depending on page size.
--with-lg-quantum=<lg-quantum> --with-lg-quantum=<lg-quantum>
Specify the base 2 log of the minimum allocation alignment (only Specify the base 2 log of the minimum allocation alignment. jemalloc needs
<lg-quantum>=3 and <lg-quantum>=4 are supported). jemalloc needs to know to know the minimum alignment that meets the following C standard
the minimum alignment that meets the following C standard requirement requirement (quoted from the April 12, 2011 draft of the C11 standard):
(quoted from the April 12, 2011 draft of the C11 standard):
The pointer returned if the allocation succeeds is suitably aligned so The pointer returned if the allocation succeeds is suitably aligned so
that it may be assigned to a pointer to any type of object with a that it may be assigned to a pointer to any type of object with a
@ -247,8 +246,8 @@ any of the following arguments (not a definitive list) to 'configure':
(<lg-quantum>=4), but the glibc developers chose not to meet this requirement (<lg-quantum>=4), but the glibc developers chose not to meet this requirement
for performance reasons. An old discussion can be found at for performance reasons. An old discussion can be found at
https://sourceware.org/bugzilla/show_bug.cgi?id=206 . Unlike glibc, https://sourceware.org/bugzilla/show_bug.cgi?id=206 . Unlike glibc,
jemalloc does follow the C standard by default (caveat: jemalloc technically jemalloc does follow the C standard by default (caveat: jemalloc
cheats by only providing 8-byte alignment for 8-byte allocation requests), technically cheats if --with-lg-tiny-min is smaller than --with-lg-quantum),
but the fact that Linux systems already work around this allocator but the fact that Linux systems already work around this allocator
noncompliance means that it is generally safe in practice to let jemalloc's noncompliance means that it is generally safe in practice to let jemalloc's
minimum alignment follow glibc's lead. If you specify --with-lg-quantum=3 minimum alignment follow glibc's lead. If you specify --with-lg-quantum=3
@ -256,6 +255,27 @@ any of the following arguments (not a definitive list) to 'configure':
are not 16-byte-aligned (24, 40, and 56, assuming are not 16-byte-aligned (24, 40, and 56, assuming
--with-lg-size-class-group=2). --with-lg-size-class-group=2).
--with-lg-tiny-min=<lg-tiny-min>
Specify the base 2 log of the minimum tiny size class to support. Tiny
size classes are powers of 2 less than the quantum, and are only
incorporated if <lg-tiny-min> is less than <lg-quantum> (see
--with-lg-quantum). Tiny size classes technically violate the C standard
requirement for minimum alignment, and crashes could conceivably result if
the compiler were to generate instructions that made alignment assumptions,
both because illegal instruction traps could result, and because accesses
could straddle page boundaries and cause segmentation faults due to
accessing unmapped addresses.
The default of <lg-tiny-min>=3 works well in practice even on architectures
that technically require 16-byte alignment, probably for the same reason
--with-lg-quantum=3 works. Smaller tiny size classes can, and will, cause
crashes (see https://bugzilla.mozilla.org/show_bug.cgi?id=691003 for an
example).
This option is rarely useful, and is mainly provided as documentation of a
subtle implementation detail. If you do use this option, specify a
value in [3, ..., <lg-quantum>].
The following environment variables (not a definitive list) impact configure's The following environment variables (not a definitive list) impact configure's
behavior: behavior:

View File

@ -207,7 +207,7 @@ dnl CPU-specific settings.
CPU_SPINWAIT="" CPU_SPINWAIT=""
case "${host_cpu}" in case "${host_cpu}" in
i686|x86_64) i686|x86_64)
AC_CACHE_CHECK([whether pause instruction is compilable], [je_cv_pause], AC_CACHE_VAL([je_cv_pause],
[JE_COMPILABLE([pause instruction], [], [JE_COMPILABLE([pause instruction], [],
[[__asm__ volatile("pause"); return 0;]], [[__asm__ volatile("pause"); return 0;]],
[je_cv_pause])]) [je_cv_pause])])
@ -970,10 +970,21 @@ else
fi fi
fi fi
AC_ARG_WITH([lg_tiny_min],
[AS_HELP_STRING([--with-lg-tiny-min=<lg-tiny-min>],
[Base 2 log of minimum tiny size class to support])],
[LG_TINY_MIN="$with_lg_tiny_min"],
[LG_TINY_MIN="3"])
AC_DEFINE_UNQUOTED([LG_TINY_MIN], [$LG_TINY_MIN])
AC_ARG_WITH([lg_quantum], AC_ARG_WITH([lg_quantum],
[AS_HELP_STRING([--with-lg-quantum=<lg-quantum>], [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
[Base 2 log of minimum allocation alignment])], [Base 2 log of minimum allocation alignment])],
[AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])]) [LG_QUANTA="$with_lg_quantum"],
[LG_QUANTA="3 4"])
if test "x$with_lg_quantum" != "x" ; then
AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
fi
AC_ARG_WITH([lg_page], AC_ARG_WITH([lg_page],
[AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])], [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
@ -1480,11 +1491,13 @@ AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
]) ])
AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [ AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
mkdir -p "${objroot}include/jemalloc/internal" mkdir -p "${objroot}include/jemalloc/internal"
"${srcdir}/include/jemalloc/internal/size_classes.sh" ${LG_PAGE_SIZES} ${LG_SIZE_CLASS_GROUP} > "${objroot}include/jemalloc/internal/size_classes.h" "${srcdir}/include/jemalloc/internal/size_classes.sh" "${LG_QUANTA}" ${LG_TINY_MIN} "${LG_PAGE_SIZES}" ${LG_SIZE_CLASS_GROUP} > "${objroot}include/jemalloc/internal/size_classes.h"
], [ ], [
srcdir="${srcdir}" srcdir="${srcdir}"
objroot="${objroot}" objroot="${objroot}"
LG_PAGE_SIZES=${LG_PAGE_SIZES} LG_QUANTA="${LG_QUANTA}"
LG_TINY_MIN=${LG_TINY_MIN}
LG_PAGE_SIZES="${LG_PAGE_SIZES}"
LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP} LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP}
]) ])
AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [ AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [

View File

@ -181,7 +181,6 @@ typedef unsigned index_t;
(((unsigned)(flags >> 8)) - 1) (((unsigned)(flags >> 8)) - 1)
/* Smallest size class to support. */ /* Smallest size class to support. */
#define LG_TINY_MIN 3
#define TINY_MIN (1U << LG_TINY_MIN) #define TINY_MIN (1U << LG_TINY_MIN)
/* /*

View File

@ -144,6 +144,9 @@
/* Support lazy locking (avoid locking unless a second thread is launched). */ /* Support lazy locking (avoid locking unless a second thread is launched). */
#undef JEMALLOC_LAZY_LOCK #undef JEMALLOC_LAZY_LOCK
/* Minimum size class to support is 2^LG_TINY_MIN bytes. */
#undef LG_TINY_MIN
/* /*
* Minimum allocation alignment is 2^LG_QUANTUM bytes (ignoring tiny size * Minimum allocation alignment is 2^LG_QUANTUM bytes (ignoring tiny size
* classes). * classes).

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Usage: size_classes.sh <lg_parr> <lg_g> # Usage: size_classes.sh <lg_qarr> <lg_tmin> <lg_parr> <lg_g>
# The following limits are chosen such that they cover all supported platforms. # The following limits are chosen such that they cover all supported platforms.
@ -8,19 +8,19 @@
lg_zarr="2 3" lg_zarr="2 3"
# Quanta. # Quanta.
lg_qarr="3 4" lg_qarr=$1
# The range of tiny size classes is [2^lg_tmin..2^(lg_q-1)]. # The range of tiny size classes is [2^lg_tmin..2^(lg_q-1)].
lg_tmin=3 lg_tmin=$2
# Maximum lookup size. # Maximum lookup size.
lg_kmax=12 lg_kmax=12
# Page sizes. # Page sizes.
lg_parr=`echo $1 | tr ',' ' '` lg_parr=`echo $3 | tr ',' ' '`
# Size class group size (number of size classes for each size doubling). # Size class group size (number of size classes for each size doubling).
lg_g=$2 lg_g=$4
pow2() { pow2() {
e=$1 e=$1

View File

@ -60,15 +60,69 @@ const size_t index2size_tab[NSIZES] = {
JEMALLOC_ALIGNED(CACHELINE) JEMALLOC_ALIGNED(CACHELINE)
const uint8_t size2index_tab[] = { const uint8_t size2index_tab[] = {
#if LG_TINY_MIN == 0
#warning "Dangerous LG_TINY_MIN"
#define S2B_0(i) i,
#elif LG_TINY_MIN == 1
#warning "Dangerous LG_TINY_MIN"
#define S2B_1(i) i,
#elif LG_TINY_MIN == 2
#warning "Dangerous LG_TINY_MIN"
#define S2B_2(i) i,
#elif LG_TINY_MIN == 3
#define S2B_3(i) i, #define S2B_3(i) i,
#elif LG_TINY_MIN == 4
#define S2B_4(i) i,
#elif LG_TINY_MIN == 5
#define S2B_5(i) i,
#elif LG_TINY_MIN == 6
#define S2B_6(i) i,
#elif LG_TINY_MIN == 7
#define S2B_7(i) i,
#elif LG_TINY_MIN == 8
#define S2B_8(i) i,
#elif LG_TINY_MIN == 9
#define S2B_9(i) i,
#elif LG_TINY_MIN == 10
#define S2B_10(i) i,
#elif LG_TINY_MIN == 11
#define S2B_11(i) i,
#else
#error "Unsupported LG_TINY_MIN"
#endif
#if LG_TINY_MIN < 1
#define S2B_1(i) S2B_0(i) S2B_0(i)
#endif
#if LG_TINY_MIN < 2
#define S2B_2(i) S2B_1(i) S2B_1(i)
#endif
#if LG_TINY_MIN < 3
#define S2B_3(i) S2B_2(i) S2B_2(i)
#endif
#if LG_TINY_MIN < 4
#define S2B_4(i) S2B_3(i) S2B_3(i) #define S2B_4(i) S2B_3(i) S2B_3(i)
#endif
#if LG_TINY_MIN < 5
#define S2B_5(i) S2B_4(i) S2B_4(i) #define S2B_5(i) S2B_4(i) S2B_4(i)
#endif
#if LG_TINY_MIN < 6
#define S2B_6(i) S2B_5(i) S2B_5(i) #define S2B_6(i) S2B_5(i) S2B_5(i)
#endif
#if LG_TINY_MIN < 7
#define S2B_7(i) S2B_6(i) S2B_6(i) #define S2B_7(i) S2B_6(i) S2B_6(i)
#endif
#if LG_TINY_MIN < 8
#define S2B_8(i) S2B_7(i) S2B_7(i) #define S2B_8(i) S2B_7(i) S2B_7(i)
#endif
#if LG_TINY_MIN < 9
#define S2B_9(i) S2B_8(i) S2B_8(i) #define S2B_9(i) S2B_8(i) S2B_8(i)
#endif
#if LG_TINY_MIN < 10
#define S2B_10(i) S2B_9(i) S2B_9(i) #define S2B_10(i) S2B_9(i) S2B_9(i)
#endif
#if LG_TINY_MIN < 11
#define S2B_11(i) S2B_10(i) S2B_10(i) #define S2B_11(i) S2B_10(i) S2B_10(i)
#endif
#define S2B_no(i) #define S2B_no(i)
#define SC(index, lg_grp, lg_delta, ndelta, bin, lg_delta_lookup) \ #define SC(index, lg_grp, lg_delta, ndelta, bin, lg_delta_lookup) \
S2B_##lg_delta_lookup(index) S2B_##lg_delta_lookup(index)