diff --git a/ChangeLog b/ChangeLog index 1802706e5..1899b666f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,12 +22,16 @@ Changes in version 0.2.1.1-alpha - 2008-??-?? Fixes bug 625. Bugfix on 0.2.0.x. - Logging functions now check that the passed severity is sane. - Use proper log levels in the testsuite call of get_interface_address6(). + - When using a nonstandard malloc, do not use the platform values for + HAVE_MALLOC_GOOD_SIZE or HAVE_MALLOC_USABLE_SIZE. o Minor features: - Allow separate log levels to be configured for different logging domains. For example, this allows one to log all notices, warnings, or errors, plus all memory management messages of level debug or higher, with: Log [MM] debug-err [*] notice-err file /var/log/tor. + - Add a malloc_good_size implementation to OpenBSD_malloc_linux.c, + to avoid unused RAM in buffer chunks and memory pools. Changes in version 0.2.0.21-rc - 2008-03-02 diff --git a/configure.in b/configure.in index c8543e399..d2a568093 100644 --- a/configure.in +++ b/configure.in @@ -183,7 +183,19 @@ dnl ------------------------------------------------------------------- dnl Check for functions before libevent, since libevent-1.2 apparently dnl exports strlcpy without defining it in a header. -AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r inet_pton inet_ntop mallinfo malloc_good_size malloc_usable_size) +AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r inet_pton inet_ntop) + +using_custom_malloc=no +if test x$enable_openbsd_malloc = xyes ; then + AC_DEFINE(HAVE_MALLOC_GOOD_SIZE, 1, [Defined if we have the malloc_good_size function]) + using_custom_malloc=yes +fi +if test x$tcmalloc = xyes ; then + using_custom_malloc=yes +fi +if test $using_custom_malloc = no ; then + AC_CHECK_FUNCS(mallinfo malloc_good_size malloc_usable_size) +fi if test "$enable_threads" = "yes"; then AC_CHECK_HEADERS(pthread.h) diff --git a/src/common/OpenBSD_malloc_Linux.c b/src/common/OpenBSD_malloc_Linux.c index 59c2c7def..da240c8e7 100644 --- a/src/common/OpenBSD_malloc_Linux.c +++ b/src/common/OpenBSD_malloc_Linux.c @@ -1998,3 +1998,21 @@ void *valloc(size_t size) posix_memalign(&r, malloc_pagesize, size); return r; } + +size_t malloc_good_size(size_t size) +{ + if (size == 0) { + return 1; + } else if (size <= malloc_maxsize) { + int i, j; + /* round up to the nearest power of 2, with same approach + * as malloc_bytes() uses. */ + j = 1; + i = size - 1; + while (i >>= 1) + j++; + return ((size_t)1) << j; + } else { + return pageround(size); + } +}