[or-cvs] r14010: Add a malloc_good_size() implementation to OpenBSD_malloc_Li (in tor/trunk: . src/common)
nickm at seul.org
nickm at seul.org
Thu Mar 13 18:11:33 UTC 2008
Author: nickm
Date: 2008-03-13 14:11:33 -0400 (Thu, 13 Mar 2008)
New Revision: 14010
Modified:
tor/trunk/
tor/trunk/ChangeLog
tor/trunk/configure.in
tor/trunk/src/common/OpenBSD_malloc_Linux.c
Log:
r18793 at catbus: nickm | 2008-03-13 14:09:19 -0400
Add a malloc_good_size() implementation to OpenBSD_malloc_Linux.c. Also, make configure.in not use support functions for the platform malloc when we are not using the platform mallocs.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r18793] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog 2008-03-13 16:56:36 UTC (rev 14009)
+++ tor/trunk/ChangeLog 2008-03-13 18:11:33 UTC (rev 14010)
@@ -22,12 +22,16 @@
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
Modified: tor/trunk/configure.in
===================================================================
--- tor/trunk/configure.in 2008-03-13 16:56:36 UTC (rev 14009)
+++ tor/trunk/configure.in 2008-03-13 18:11:33 UTC (rev 14010)
@@ -183,8 +183,20 @@
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)
AC_CHECK_FUNCS(pthread_create)
Modified: tor/trunk/src/common/OpenBSD_malloc_Linux.c
===================================================================
--- tor/trunk/src/common/OpenBSD_malloc_Linux.c 2008-03-13 16:56:36 UTC (rev 14009)
+++ tor/trunk/src/common/OpenBSD_malloc_Linux.c 2008-03-13 18:11:33 UTC (rev 14010)
@@ -1998,3 +1998,21 @@
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);
+ }
+}
More information about the tor-commits
mailing list