[tor-commits] [tor/master] Add --disable-mempools configure option

nickm at torproject.org nickm at torproject.org
Thu May 22 20:39:57 UTC 2014


commit 39d4e67be8283b2a7141a7aa8342d30e27f47e6f
Author: Andrea Shepard <andrea at torproject.org>
Date:   Mon May 12 18:23:34 2014 -0700

    Add --disable-mempools configure option
---
 configure.ac               |    9 +++++++++
 src/common/include.am      |   16 ++++++++++++----
 src/or/circuitlist.c       |    2 ++
 src/or/main.c              |    6 ++++++
 src/or/relay.c             |   21 ++++++++++++++++++++-
 src/or/relay.h             |    2 ++
 src/test/test.c            |    2 ++
 src/test/test_cell_queue.c |   10 ++++++++++
 src/test/test_circuitmux.c |    4 ++++
 src/test/test_oom.c        |   13 +++++++++++++
 src/test/test_util.c       |    8 ++++++++
 11 files changed, 88 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 936d61b..255dcea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,8 @@ CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
 #XXXX020 We should make these enabled or not, before 0.2.0.x-final
 AC_ARG_ENABLE(buf-freelists,
    AS_HELP_STRING(--enable-buf-freelists, enable freelists for buffer RAM))
+AC_ARG_ENABLE(mempools,
+   AS_HELP_STRING(--disable-mempools, disable mempools for relay cells))
 AC_ARG_ENABLE(openbsd-malloc,
    AS_HELP_STRING(--enable-openbsd-malloc, Use malloc code from openbsd.  Linux only))
 AC_ARG_ENABLE(instrument-downloads,
@@ -58,6 +60,13 @@ if test x$enable_buf_freelists = xyes; then
   AC_DEFINE(ENABLE_BUF_FREELISTS, 1,
             [Defined if we try to use freelists for buffer RAM chunks])
 fi
+
+AM_CONDITIONAL(USE_MEMPOOLS, test x$enable_mempools != xno)
+if test x$enable_mempools != xno; then
+  AC_DEFINE(ENABLE_MEMPOOLS, 1,
+            [Defined if we try to use mempools for cells being relayed])
+fi
+
 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test x$enable_openbsd_malloc = xyes)
 if test x$enable_instrument_downloads = xyes; then
   AC_DEFINE(INSTRUMENT_DOWNLOADS, 1,
diff --git a/src/common/include.am b/src/common/include.am
index 7b2465c..61a90cd 100644
--- a/src/common/include.am
+++ b/src/common/include.am
@@ -24,6 +24,14 @@ else
 libor_extra_source=
 endif
 
+if USE_MEMPOOLS
+libor_mempool_source=src/common/mempool.c
+libor_mempool_header=src/common/mempool.h
+else
+libor_mempool_source=
+libor_mempool_header=
+endif
+
 src_common_libcurve25519_donna_a_CFLAGS=
 
 if BUILD_CURVE25519_DONNA
@@ -56,13 +64,13 @@ LIBOR_A_SOURCES = \
   src/common/di_ops.c					\
   src/common/log.c					\
   src/common/memarea.c					\
-  src/common/mempool.c					\
   src/common/procmon.c					\
   src/common/util.c					\
   src/common/util_codedigest.c				\
   src/common/sandbox.c					\
   src/ext/csiphash.c					\
-  $(libor_extra_source)
+  $(libor_extra_source)					\
+  $(libor_mempool_source)
 
 LIBOR_CRYPTO_A_SOURCES = \
   src/common/aes.c		\
@@ -102,7 +110,6 @@ COMMONHEADERS = \
   src/common/crypto_curve25519.h		\
   src/common/di_ops.h				\
   src/common/memarea.h				\
-  src/common/mempool.h				\
   src/common/linux_syscalls.inc			\
   src/common/procmon.h				\
   src/common/sandbox.h				\
@@ -111,7 +118,8 @@ COMMONHEADERS = \
   src/common/torint.h				\
   src/common/torlog.h				\
   src/common/tortls.h				\
-  src/common/util.h
+  src/common/util.h				\
+  $(libor_mempool_header)
 
 noinst_HEADERS+= $(COMMONHEADERS)
 
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index c54a954..e482fa5 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -1975,7 +1975,9 @@ circuits_handle_oom(size_t current_allocation)
       break;
   } SMARTLIST_FOREACH_END(circ);
 
+#ifdef ENABLE_MEMPOOLS
   clean_cell_pool(); /* In case this helps. */
+#endif /* ENABLE_MEMPOOLS */
   buf_shrink_freelists(1); /* This is necessary to actually release buffer
                               chunks. */
 
diff --git a/src/or/main.c b/src/or/main.c
index 6713d80..e5a48cf 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1522,7 +1522,9 @@ run_scheduled_events(time_t now)
         if (conn->inbuf)
           buf_shrink(conn->inbuf);
       });
+#ifdef ENABLE_MEMPOOL
     clean_cell_pool();
+#endif /* ENABLE_MEMPOOL */
     buf_shrink_freelists(0);
 /** How often do we check buffers and pools for empty space that can be
  * deallocated? */
@@ -1927,8 +1929,10 @@ do_main_loop(void)
     }
   }
 
+#ifdef ENABLE_MEMPOOLS
   /* Set up the packed_cell_t memory pool. */
   init_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
 
   /* Set up our buckets */
   connection_bucket_init();
@@ -2545,7 +2549,9 @@ tor_free_all(int postfork)
     router_free_all();
     policies_free_all();
   }
+#ifdef ENABLE_MEMPOOLS
   free_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
   if (!postfork) {
     tor_tls_free_all();
   }
diff --git a/src/or/relay.c b/src/or/relay.c
index f8b0dee..e593f87 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -26,7 +26,9 @@
 #include "control.h"
 #include "geoip.h"
 #include "main.h"
+#ifdef ENABLE_MEMPOOLS
 #include "mempool.h"
+#endif
 #include "networkstatus.h"
 #include "nodelist.h"
 #include "onion.h"
@@ -2231,9 +2233,10 @@ circuit_consider_sending_sendme(circuit_t *circ, crypt_path_t *layer_hint)
 #define assert_cmux_ok_paranoid(chan)
 #endif
 
-/** The total number of cells we have allocated from the memory pool. */
+/** The total number of cells we have allocated. */
 static size_t total_cells_allocated = 0;
 
+#ifdef ENABLE_MEMPOOLS
 /** A memory pool to allocate packed_cell_t objects. */
 static mp_pool_t *cell_pool = NULL;
 
@@ -2265,12 +2268,18 @@ clean_cell_pool(void)
   mp_pool_clean(cell_pool, 0, 1);
 }
 
+#endif /* ENABLE_MEMPOOLS */
+
 /** Release storage held by <b>cell</b>. */
 static INLINE void
 packed_cell_free_unchecked(packed_cell_t *cell)
 {
   --total_cells_allocated;
+#ifdef ENABLE_MEMPOOLS
   mp_pool_release(cell);
+#else
+  tor_free(cell);
+#endif /* ENABLE_MEMPOOLS */
 }
 
 /** Allocate and return a new packed_cell_t. */
@@ -2278,7 +2287,11 @@ STATIC packed_cell_t *
 packed_cell_new(void)
 {
   ++total_cells_allocated;
+#ifdef ENABLE_MEMPOOLS
   return mp_pool_get(cell_pool);
+#else
+  return tor_malloc(sizeof(packed_cell_t));
+#endif
 }
 
 /** Return a packed cell used outside by channel_t lower layer */
@@ -2307,7 +2320,9 @@ dump_cell_pool_usage(int severity)
   tor_log(severity, LD_MM,
           "%d cells allocated on %d circuits. %d cells leaked.",
           n_cells, n_circs, (int)total_cells_allocated - n_cells);
+#ifdef ENABLE_MEMPOOLS
   mp_pool_log_status(cell_pool, severity);
+#endif
 }
 
 /** Allocate a new copy of packed <b>cell</b>. */
@@ -2387,7 +2402,11 @@ cell_queue_pop(cell_queue_t *queue)
 size_t
 packed_cell_mem_cost(void)
 {
+#ifdef ENABLE_MEMPOOLS
   return sizeof(packed_cell_t) + MP_POOL_ITEM_OVERHEAD;
+#else
+  return sizeof(packed_cell_t);
+#endif /* ENABLE_MEMPOOLS */
 }
 
 /** DOCDOC */
diff --git a/src/or/relay.h b/src/or/relay.h
index 9c0e21c..479d474 100644
--- a/src/or/relay.h
+++ b/src/or/relay.h
@@ -42,9 +42,11 @@ extern uint64_t stats_n_data_bytes_packaged;
 extern uint64_t stats_n_data_cells_received;
 extern uint64_t stats_n_data_bytes_received;
 
+#ifdef ENABLE_MEMPOOLS
 void init_cell_pool(void);
 void free_cell_pool(void);
 void clean_cell_pool(void);
+#endif /* ENABLE_MEMPOOLS */
 void dump_cell_pool_usage(int severity);
 size_t packed_cell_mem_cost(void);
 
diff --git a/src/test/test.c b/src/test/test.c
index 771725e..b49f946 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -51,7 +51,9 @@ double fabs(double x);
 #include "rendcommon.h"
 #include "test.h"
 #include "torgzip.h"
+#ifdef ENABLE_MEMPOOLS
 #include "mempool.h"
+#endif
 #include "memarea.h"
 #include "onion.h"
 #include "onion_ntor.h"
diff --git a/src/test/test_cell_queue.c b/src/test/test_cell_queue.c
index 1eac073..9262982 100644
--- a/src/test/test_cell_queue.c
+++ b/src/test/test_cell_queue.c
@@ -16,7 +16,10 @@ test_cq_manip(void *arg)
   cell_t cell;
   (void) arg;
 
+#ifdef ENABLE_MEMPOOLS
   init_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
+
   cell_queue_init(&cq);
   tt_int_op(cq.n, ==, 0);
 
@@ -96,7 +99,10 @@ test_cq_manip(void *arg)
   packed_cell_free(pc_tmp);
 
   cell_queue_clear(&cq);
+
+#ifdef ENABLE_MEMPOOLS
   free_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
 }
 
 static void
@@ -108,7 +114,9 @@ test_circuit_n_cells(void *arg)
 
   (void)arg;
 
+#ifdef ENABLE_MEMPOOLS
   init_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
 
   pc1 = packed_cell_new();
   pc2 = packed_cell_new();
@@ -137,7 +145,9 @@ test_circuit_n_cells(void *arg)
   circuit_free(TO_CIRCUIT(or_c));
   circuit_free(TO_CIRCUIT(origin_c));
 
+#ifdef ENABLE_MEMPOOLS
   free_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
 }
 
 struct testcase_t cell_queue_tests[] = {
diff --git a/src/test/test_circuitmux.c b/src/test/test_circuitmux.c
index 0f59200..b9c0436 100644
--- a/src/test/test_circuitmux.c
+++ b/src/test/test_circuitmux.c
@@ -36,7 +36,9 @@ test_cmux_destroy_cell_queue(void *arg)
   cell_queue_t *cq = NULL;
   packed_cell_t *pc = NULL;
 
+#ifdef ENABLE_MEMPOOLS
   init_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
   (void) arg;
 
   cmux = circuitmux_alloc();
@@ -74,7 +76,9 @@ test_cmux_destroy_cell_queue(void *arg)
   channel_free(ch);
   packed_cell_free(pc);
 
+#ifdef ENABLE_MEMPOOLS
   free_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
 }
 
 struct testcase_t circuitmux_tests[] = {
diff --git a/src/test/test_oom.c b/src/test/test_oom.c
index 989ca12..1afe3fd 100644
--- a/src/test/test_oom.c
+++ b/src/test/test_oom.c
@@ -12,7 +12,9 @@
 #include "compat_libevent.h"
 #include "connection.h"
 #include "config.h"
+#ifdef ENABLE_MEMPOOLS
 #include "mempool.h"
+#endif
 #include "relay.h"
 #include "test.h"
 
@@ -130,7 +132,10 @@ test_oom_circbuf(void *arg)
   (void) arg;
 
   MOCK(circuit_mark_for_close_, circuit_mark_for_close_dummy_);
+
+#ifdef ENABLE_MEMPOOLS
   init_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
 
   /* Far too low for real life. */
   options->MaxMemInQueues = 256*packed_cell_mem_cost();
@@ -149,8 +154,13 @@ test_oom_circbuf(void *arg)
   tor_gettimeofday_cache_set(&tv);
   c2 = dummy_or_circuit_new(20, 20);
 
+#ifdef ENABLE_MEMPOOLS
   tt_int_op(packed_cell_mem_cost(), ==,
             sizeof(packed_cell_t) + MP_POOL_ITEM_OVERHEAD);
+#else
+  tt_int_op(packed_cell_mem_cost(), ==,
+            sizeof(packed_cell_t));
+#endif /* ENABLE_MEMPOOLS */
   tt_int_op(cell_queues_get_total_allocation(), ==,
             packed_cell_mem_cost() * 70);
   tt_int_op(cell_queues_check_size(), ==, 0); /* We are still not OOM */
@@ -220,7 +230,10 @@ test_oom_streambuf(void *arg)
   (void) arg;
 
   MOCK(circuit_mark_for_close_, circuit_mark_for_close_dummy_);
+
+#ifdef ENABLE_MEMPOOLS
   init_cell_pool();
+#endif /* ENABLE_MEMPOOLS */
 
   /* Far too low for real life. */
   options->MaxMemInQueues = 81*packed_cell_mem_cost() + 4096 * 34;
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 6d6b6db..eadbf73 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -12,7 +12,9 @@
 #include "config.h"
 #include "control.h"
 #include "test.h"
+#ifdef ENABLE_MEMPOOLS
 #include "mempool.h"
+#endif /* ENABLE_MEMPOOLS */
 #include "memarea.h"
 
 #ifdef _WIN32
@@ -1899,6 +1901,8 @@ test_util_path_is_relative(void)
   ;
 }
 
+#ifdef ENABLE_MEMPOOLS
+
 /** Run unittests for memory pool allocator */
 static void
 test_util_mempool(void)
@@ -1957,6 +1961,8 @@ test_util_mempool(void)
     mp_pool_destroy(pool);
 }
 
+#endif /* ENABLE_MEMPOOLS */
+
 /** Run unittests for memory area allocator */
 static void
 test_util_memarea(void)
@@ -3656,7 +3662,9 @@ struct testcase_t util_tests[] = {
   UTIL_LEGACY(pow2),
   UTIL_LEGACY(gzip),
   UTIL_LEGACY(datadir),
+#ifdef ENABLE_MEMPOOLS
   UTIL_LEGACY(mempool),
+#endif
   UTIL_LEGACY(memarea),
   UTIL_LEGACY(control_formats),
   UTIL_LEGACY(mmap),





More information about the tor-commits mailing list