From c606a87d2a2a946793cf0a29ca69a1962caf6008 Mon Sep 17 00:00:00 2001 From: Jason Evans Date: Tue, 30 May 2017 09:54:49 -0700 Subject: [PATCH] Add the --disable-thp option to support cross compiling. This resolves #669. --- INSTALL.md | 7 +++++- configure.ac | 25 ++++++++++++++++--- doc/jemalloc.xml.in | 11 ++++++++ .../internal/jemalloc_internal_defs.h.in | 4 +-- .../jemalloc/internal/jemalloc_preamble.h.in | 14 +++++------ src/ctl.c | 3 +++ src/stats.c | 1 + test/unit/pages.c | 2 +- 8 files changed, 53 insertions(+), 14 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 25f625af..dff7cebb 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -157,6 +157,11 @@ any of the following arguments (not a definitive list) to 'configure': Statically link against the specified libunwind.a rather than dynamically linking with -lunwind. +* `--disable-thp` + + Disable transparent huge page (THP) integration. This option can be useful + when cross compiling. + * `--disable-fill` Disable support for junk/zero filling of memory. See the "opt.junk" and @@ -224,7 +229,7 @@ any of the following arguments (not a definitive list) to 'configure': * `--with-lg-page-sizes=` Specify the comma-separated base 2 logs of the page sizes to support. This - option may be useful when cross-compiling in combination with + option may be useful when cross compiling in combination with `--with-lg-page`, but its primary use case is for integration with FreeBSD's libc, wherein jemalloc is embedded. diff --git a/configure.ac b/configure.ac index 8be4be45..bed01b7a 100644 --- a/configure.ac +++ b/configure.ac @@ -1792,11 +1792,29 @@ if test "x${je_cv_madvise}" = "xyes" ; then madvise((void *)0, 0, MADV_HUGEPAGE); madvise((void *)0, 0, MADV_NOHUGEPAGE); ], [je_cv_thp]) - if test "x${je_cv_thp}" = "xyes" ; then - AC_DEFINE([JEMALLOC_THP], [ ]) - fi fi +dnl Enable transparent huge page support by default. +AC_ARG_ENABLE([thp], + [AS_HELP_STRING([--disable-thp], + [Disable transparent huge page support])], +[if test "x$enable_thp" = "xno" -o "x${je_cv_thp}" != "xyes" ; then + enable_thp="0" +else + enable_thp="1" +fi +], +[if test "x${je_cv_thp}" = "xyes" ; then + enable_thp="1" +else + enable_thp="0" +fi +]) +if test "x$enable_thp" = "x1" ; then + AC_DEFINE([JEMALLOC_THP], [ ]) +fi +AC_SUBST([enable_thp]) + dnl ============================================================================ dnl Check whether __sync_{add,sub}_and_fetch() are available despite dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined. @@ -2141,6 +2159,7 @@ AC_MSG_RESULT([prof : ${enable_prof}]) AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}]) AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}]) AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}]) +AC_MSG_RESULT([thp : ${enable_thp}]) AC_MSG_RESULT([fill : ${enable_fill}]) AC_MSG_RESULT([utrace : ${enable_utrace}]) AC_MSG_RESULT([xmalloc : ${enable_xmalloc}]) diff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in index c2c0e925..a9c3d403 100644 --- a/doc/jemalloc.xml.in +++ b/doc/jemalloc.xml.in @@ -849,6 +849,17 @@ mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".decay", build configuration. + + + config.thp + (bool) + r- + + was not specified + during build configuration, and the system supports transparent huge + page manipulation. + + config.utrace diff --git a/include/jemalloc/internal/jemalloc_internal_defs.h.in b/include/jemalloc/internal/jemalloc_internal_defs.h.in index 75576a56..20a2358e 100644 --- a/include/jemalloc/internal/jemalloc_internal_defs.h.in +++ b/include/jemalloc/internal/jemalloc_internal_defs.h.in @@ -269,8 +269,8 @@ #undef JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS /* - * Defined if transparent huge pages are supported via the MADV_[NO]HUGEPAGE - * arguments to madvise(2). + * Defined if transparent huge pages (THPs) are supported via the + * MADV_[NO]HUGEPAGE arguments to madvise(2), and THP support is enabled. */ #undef JEMALLOC_THP diff --git a/include/jemalloc/internal/jemalloc_preamble.h.in b/include/jemalloc/internal/jemalloc_preamble.h.in index 0e876103..46750e99 100644 --- a/include/jemalloc/internal/jemalloc_preamble.h.in +++ b/include/jemalloc/internal/jemalloc_preamble.h.in @@ -111,6 +111,13 @@ static const bool config_stats = false #endif ; +static const bool config_thp = +#ifdef JEMALLOC_THP + true +#else + false +#endif + ; static const bool config_tls = #ifdef JEMALLOC_TLS true @@ -139,13 +146,6 @@ static const bool config_cache_oblivious = false #endif ; -static const bool have_thp = -#ifdef JEMALLOC_THP - true -#else - false -#endif - ; #ifdef JEMALLOC_HAVE_SCHED_GETCPU /* Currently percpu_arena depends on sched_getcpu. */ #define JEMALLOC_PERCPU_ARENA diff --git a/src/ctl.c b/src/ctl.c index d10c39bb..e3337e8a 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -73,6 +73,7 @@ CTL_PROTO(config_prof) CTL_PROTO(config_prof_libgcc) CTL_PROTO(config_prof_libunwind) CTL_PROTO(config_stats) +CTL_PROTO(config_thp) CTL_PROTO(config_utrace) CTL_PROTO(config_xmalloc) CTL_PROTO(opt_abort) @@ -263,6 +264,7 @@ static const ctl_named_node_t config_node[] = { {NAME("prof_libgcc"), CTL(config_prof_libgcc)}, {NAME("prof_libunwind"), CTL(config_prof_libunwind)}, {NAME("stats"), CTL(config_stats)}, + {NAME("thp"), CTL(config_thp)}, {NAME("utrace"), CTL(config_utrace)}, {NAME("xmalloc"), CTL(config_xmalloc)} }; @@ -1544,6 +1546,7 @@ CTL_RO_CONFIG_GEN(config_prof, bool) CTL_RO_CONFIG_GEN(config_prof_libgcc, bool) CTL_RO_CONFIG_GEN(config_prof_libunwind, bool) CTL_RO_CONFIG_GEN(config_stats, bool) +CTL_RO_CONFIG_GEN(config_thp, bool) CTL_RO_CONFIG_GEN(config_utrace, bool) CTL_RO_CONFIG_GEN(config_xmalloc, bool) diff --git a/src/stats.c b/src/stats.c index 61550d83..268862b0 100644 --- a/src/stats.c +++ b/src/stats.c @@ -725,6 +725,7 @@ stats_general_print(void (*write_cb)(void *, const char *), void *cbopaque, CONFIG_WRITE_BOOL_JSON(prof_libgcc, ",") CONFIG_WRITE_BOOL_JSON(prof_libunwind, ",") CONFIG_WRITE_BOOL_JSON(stats, ",") + CONFIG_WRITE_BOOL_JSON(thp, ",") CONFIG_WRITE_BOOL_JSON(utrace, ",") CONFIG_WRITE_BOOL_JSON(xmalloc, "") diff --git a/test/unit/pages.c b/test/unit/pages.c index 4457f369..67dbb4cd 100644 --- a/test/unit/pages.c +++ b/test/unit/pages.c @@ -11,7 +11,7 @@ TEST_BEGIN(test_pages_huge) { assert_ptr_not_null(pages, "Unexpected pages_map() error"); hugepage = (void *)(ALIGNMENT_CEILING((uintptr_t)pages, HUGEPAGE)); - assert_b_ne(pages_huge(hugepage, HUGEPAGE), have_thp, + assert_b_ne(pages_huge(hugepage, HUGEPAGE), config_thp, "Unexpected pages_huge() result"); assert_false(pages_nohuge(hugepage, HUGEPAGE), "Unexpected pages_nohuge() result");