diff --git a/src/acconfig.h b/src/acconfig.h index cf5bbdda446..cf6e0292cb3 100644 --- a/src/acconfig.h +++ b/src/acconfig.h @@ -550,19 +550,18 @@ #define PIKE_OOB_WORKS -1 /* dlmalloc has mallinfo. */ -#if defined(USE_DL_MALLOC) && !defined(HAVE_MALLINFO) -#define HAVE_MALLINFO +#if !defined(USE_JEMALLOC) +# if defined(USE_DL_MALLOC) && !defined(HAVE_MALLINFO) +# define HAVE_MALLINFO -#if defined (HAVE_MALLOC_H) && defined (HAVE_STRUCT_MALLINFO) -#include -#else /* HAVE_MALLOC_H && HAVE_STRUCT_MALLINFO */ - -#ifndef MALLINFO_FIELD_TYPE -#define MALLINFO_FIELD_TYPE size_t -#endif /* MALLINFO_FIELD_TYPE */ +# if defined (HAVE_MALLOC_H) && defined (HAVE_STRUCT_MALLINFO) +# include +# elif !defined(MALLINFO_FIELD_TYPE) +# define MALLINFO_FIELD_TYPE size_t +# endif /* defined (HAVE_MALLOC_H) && defined (HAVE_STRUCT_MALLINFO) */ /* Needed for size_t. */ -#include +# include /* dlmalloc definition of struct mallinfo. */ struct mallinfo { @@ -578,8 +577,8 @@ struct mallinfo { MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ }; -#endif /* HAVE_USR_INCLUDE_MALLOC_H */ +# endif /* defined(USE_DL_MALLOC) && !defined(HAVE_MALLINFO) */ -#endif +#endif /* !defined(USE_JEMALLOC) */ #endif /* MACHINE_H */ diff --git a/src/builtin.cmod b/src/builtin.cmod index f4e4e2f1a82..59f077b2a94 100644 --- a/src/builtin.cmod +++ b/src/builtin.cmod @@ -5962,15 +5962,15 @@ static void get_val_module(void) /* Always do the lookup in the Val module dynamically to allow the * values to be replaced. */ #define GET_VAL(NAME) \ - PMOD_EXPORT struct object *PIKE_CONCAT (get_val_, NAME) (void) \ + PMOD_EXPORT struct object *get_val_ ## NAME (void) \ { \ struct svalue index, res; \ if (!val_module) get_val_module(); \ SET_SVAL(index, T_STRING, 0, string, NULL); \ - MAKE_CONST_STRING (index.u.string, TOSTR (NAME)); \ + MAKE_CONST_STRING (index.u.string, #NAME); \ object_index_no_free (&res, val_module, 0, &index); \ if (TYPEOF(res) != T_OBJECT) \ - Pike_error ("\"Val." TOSTR (NAME) "\" didn't resolve to an object.\n"); \ + Pike_error ("\"Val." #NAME "\" didn't resolve to an object.\n"); \ return res.u.object; \ } diff --git a/src/builtin_functions.c b/src/builtin_functions.c index 9b923a7fd6e..341635964ee 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -7538,7 +7538,9 @@ PMOD_EXPORT void f__memory_usage(INT32 args) { size_t num,size; struct svalue *ss; -#ifdef USE_DL_MALLOC +#ifdef USE_JEMALLOC + /* No mallinfo. */ +#elif USE_DL_MALLOC struct mallinfo mi = dlmallinfo(); #elif HAVE_MALLINFO struct mallinfo mi = mallinfo(); @@ -7551,7 +7553,20 @@ PMOD_EXPORT void f__memory_usage(INT32 args) * statistics from our bundled Doug Lea malloc, and not the * underlying system malloc. Ideally we should include both. */ -#if defined(HAVE_MALLINFO) || defined(USE_DL_MALLOC) +#if defined(USE_JEMALLOC) + size_t sz, allocated, active, resident, mapped; + + sz = sizeof(size_t); + mallctl("stats.allocated", (void *)&allocated, &sz, NULL, 0); + mallctl("stats.active", (void *)&active, &sz, NULL, 0); + mallctl("stats.resident", (void *)&resident, &sz, NULL, 0); + mallctl("stats.mapped", (void *)&mapped, &sz, NULL, 0); + + push_text("allocated");push_ulongest(allocated); + push_text("active");push_ulongest(active); + push_text("resident");push_ulongest(resident); + push_text("mapped");push_ulongest(mapped); +#elif defined(HAVE_MALLINFO) || defined(USE_DL_MALLOC) push_static_text("num_malloc_blocks"); push_ulongest(1 + mi.hblks); /* 1 for the arena. */ @@ -7617,7 +7632,7 @@ PMOD_EXPORT void f__memory_usage(INT32 args) count_string_types(); -#endif +#endif /* if defined(USE_JEMALLOC) */ #define COUNT(TYPE) do { \ PIKE_CONCAT3(count_memory_in_, TYPE, s)(&num, &size); \ diff --git a/src/configure.in b/src/configure.in index bb198ac1278..b5b0fcbb684 100644 --- a/src/configure.in +++ b/src/configure.in @@ -1026,6 +1026,16 @@ else enable_dlmalloc=no fi +AC_ARG_ENABLE(jemalloc, MY_DESCR([--enable-jemalloc], + [use jemalloc implementation instead of system malloc]), + [enable_jemalloc=yes], [enable_jemalloc=no]) +if test "x$enable_jemalloc" = xyes; then + AC_DEFINE(USE_JEMALLOC, [1], [Set to 1 if jemalloc should be used for memory allocation]) + LIBS="-ljemalloc ${LIBS}" +else + enable_jemalloc=no +fi + MY_AC_ARG_WITH(cleanup-on-exit, MY_DESCR([--with-cleanup-on-exit], [Do full cleanup at exit to detect leaks better.]), @@ -2818,7 +2828,8 @@ AC_CHECK_HEADERS(winsock2.h sys/rusage.h sys/time.h \ sys/id.h mach-o/dyld.h sys/ptrace.h \ thread.h dlfcn.h dld.h dl.h sys/times.h sched.h \ sys/procfs.h sys/socket.h sys/uio.h fcntl.h \ - malloc.h netinet/in.h sys/wait.h windows.h grp.h pwd.h \ + malloc.h jemalloc/jemalloc.h netinet/in.h sys/wait.h \ + windows.h grp.h pwd.h \ passwd.h group.h winsock.h sys/file.h poll.h \ sys/poll.h socket.h ieeefp.h fp_class.h floatingpoint.h \ sys/priocntl.h sys/sched.h winbase.h \ @@ -4396,7 +4407,7 @@ AC_MSG_RESULT($pike_cv_has_struct_sockaddr_in6) ############################################################################# -if test $ac_cv_header_malloc_h = yes; then +if test $ac_cv_header_malloc_h = yes && test "x$enable_jemalloc" = xno; then AC_MSG_CHECKING(struct mallinfo in malloc.h) AC_CACHE_VAL(pike_cv_struct_mallinfo, [ AC_TRY_LINK([ @@ -7826,6 +7837,7 @@ PAD_FEATURE([cdebug])$with_cdebug PAD_FEATURE([rtldebug])$with_rtldebug PAD_FEATURE([dmalloc])$with_dmalloc PAD_FEATURE([dlmalloc])$enable_dlmalloc +PAD_FEATURE([jemalloc])$enable_jemalloc PAD_FEATURE([byte code format])$byte_code_format PAD_FEATURE([module reloc])${with_relocatable_dumped_modules:-no} PAD_FEATURE([use machine code])$with_machine_code diff --git a/src/global.h b/src/global.h index 3558ef5e3ec..86fe8039bb8 100644 --- a/src/global.h +++ b/src/global.h @@ -325,12 +325,14 @@ void *alloca(); #include #include -#ifdef HAVE_MALLOC_H +#if defined(USE_JEMALLOC) && defined(HAVE_JEMALLOC_JEMALLOC_H) +#include +#elif defined(HAVE_MALLOC_H) #if !defined(__FreeBSD__) && !defined(__OpenBSD__) /* FreeBSD and OpenBSD has , but it just contains a warning... */ #include #endif /* !__FreeBSD__ && !__OpenBSD */ -#endif +#endif /* if defined(USE_JEMALLOC) */ #ifdef HAVE_UNISTD_H #include diff --git a/src/modules/HTTPLoop/requestobject.c b/src/modules/HTTPLoop/requestobject.c index fc22c235906..dbbc7b3b241 100644 --- a/src/modules/HTTPLoop/requestobject.c +++ b/src/modules/HTTPLoop/requestobject.c @@ -654,8 +654,8 @@ static void actually_send(struct send_args *a) #if defined(TCP_CORK) && defined(SOL_TCP) DWERROR("cork... \n"); { - int true=1; - fd_setsockopt( a->to->fd, SOL_TCP, TCP_CORK, &true, sizeof(true) ); + int true_val=1; + fd_setsockopt( a->to->fd, SOL_TCP, TCP_CORK, &true_val, sizeof(true_val) ); } #endif fail = WRITE(a->to->fd, (char *)data, data_len); @@ -745,8 +745,8 @@ static void actually_send(struct send_args *a) DWERROR("all written.. \n"); #if defined(TCP_CORK) && defined(SOL_TCP) { - int false = 0; - fd_setsockopt( a->to->fd, SOL_TCP, TCP_CORK, &false, sizeof(false) ); + int false_val = 0; + fd_setsockopt( a->to->fd, SOL_TCP, TCP_CORK, &false_val, sizeof(false_val) ); } #endif {