[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r9939: Add support for using memory pools to allocate queued cell; (in tor/trunk: . src/common src/or)



Author: nickm
Date: 2007-04-10 20:30:29 -0400 (Tue, 10 Apr 2007)
New Revision: 9939

Modified:
   tor/trunk/
   tor/trunk/configure.in
   tor/trunk/src/common/mempool.c
   tor/trunk/src/or/main.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/relay.c
Log:
 r12337@catbus:  nickm | 2007-04-10 17:55:26 -0400
 Add support for using memory pools to allocate queued cell; pass --disable-cell-pool to configure to disable this.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/branches/mempool [r12337] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/configure.in
===================================================================
--- tor/trunk/configure.in	2007-04-11 00:30:25 UTC (rev 9938)
+++ tor/trunk/configure.in	2007-04-11 00:30:29 UTC (rev 9939)
@@ -19,6 +19,14 @@
     CFLAGS="$CFLAGS -g"
 fi])
 
+AC_ARG_ENABLE(cell-pool,
+     AS_HELP_STRING(--disable-cell-pool, disable pool allocator for cells))
+
+if test x$enable_cell_pool != xno; then
+  AC_DEFINE(ENABLE_CELL_POOL, 1,
+            [Defined if we try to use the pool allocator for queued cells])
+fi
+
 AC_ARG_ENABLE(transparent,
      AS_HELP_STRING(--disable-transparent, disable transparent proxy support),
      [case "${enableval}" in

Modified: tor/trunk/src/common/mempool.c
===================================================================
--- tor/trunk/src/common/mempool.c	2007-04-11 00:30:25 UTC (rev 9938)
+++ tor/trunk/src/common/mempool.c	2007-04-11 00:30:29 UTC (rev 9939)
@@ -7,6 +7,10 @@
 #define MEMPOOL_PRIVATE
 #include "mempool.h"
 
+/* OVERVIEW:
+ *   DOCDOC
+ */
+
 /* DRAWBACKS:
  *   - Not even slightly threadsafe.
  *   - Likes to have lots of items per chunks.
@@ -17,6 +21,7 @@
  *     if you need doubles.
  *   - Could probably be optimized a bit; the representation contains
  *     a bit more info than it really needs to have.
+ *   - probably, chunks should always be a power of 2.
  */
 
 /* NOTES:

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2007-04-11 00:30:25 UTC (rev 9938)
+++ tor/trunk/src/or/main.c	2007-04-11 00:30:29 UTC (rev 9939)
@@ -1229,6 +1229,9 @@
     }
   }
 
+  /* DOCDOC */
+  init_cell_pool();
+
   /* Set up our buckets */
   connection_bucket_init();
   stats_prev_global_read_bucket = global_read_bucket;
@@ -1665,6 +1668,7 @@
     config_free_all();
     router_free_all();
   }
+  free_cell_pool();
   tor_tls_free_all();
   /* stuff in main.c */
   smartlist_free(closeable_connection_lst);

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-04-11 00:30:25 UTC (rev 9938)
+++ tor/trunk/src/or/or.h	2007-04-11 00:30:29 UTC (rev 9939)
@@ -2667,6 +2667,9 @@
 extern uint64_t stats_n_data_cells_received;
 extern uint64_t stats_n_data_bytes_received;
 
+void init_cell_pool(void);
+void free_cell_pool(void);
+
 void cell_queue_clear(cell_queue_t *queue);
 void cell_queue_append(cell_queue_t *queue, packed_cell_t *cell);
 void cell_queue_append_packed_copy(cell_queue_t *queue, const cell_t *cell);

Modified: tor/trunk/src/or/relay.c
===================================================================
--- tor/trunk/src/or/relay.c	2007-04-11 00:30:25 UTC (rev 9938)
+++ tor/trunk/src/or/relay.c	2007-04-11 00:30:29 UTC (rev 9939)
@@ -13,6 +13,7 @@
  **/
 
 #include "or.h"
+#include "../common/mempool.h"
 
 static int relay_crypt(circuit_t *circ, cell_t *cell, int cell_direction,
                 crypt_path_t **layer_hint, char *recognized);
@@ -1477,18 +1478,67 @@
 #define assert_active_circuits_ok_paranoid(conn)
 #endif
 
+#ifdef ENABLE_CELL_POOL
+static mp_pool_t *cell_pool;
+/* DOCDOC */
+void
+init_cell_pool(void)
+{
+  tor_assert(!cell_pool);
+  cell_pool = mp_pool_new(sizeof(packed_cell_t), 64);
+}
+
+/* DOCDOC */
+void
+free_cell_pool(void)
+{
+  tor_assert(cell_pool);
+  mp_pool_destroy(cell_pool);
+  cell_pool = NULL;
+}
+
 /** Release storage held by <b>cell</b> */
 static INLINE void
 packed_cell_free(packed_cell_t *cell)
 {
+  mp_pool_release(cell);
+}
+
+/* DOCDOC */
+static INLINE packed_cell_t*
+packed_cell_alloc(void)
+{
+  return mp_pool_get(cell_pool);
+}
+#else
+void
+init_cell_pool(void)
+{
+}
+
+void
+free_cell_pool(void)
+{
+}
+
+static INLINE void
+packed_cell_free(packed_cell_t *cell)
+{
   tor_free(cell);
 }
 
+static INLINE packed_cell_t *
+packed_cell_alloc(void)
+{
+  return tor_malloc(sizeof(packed_cell_t));
+}
+#endif
+
 /** Allocate a new copy of packed <b>cell</b>. */
 static INLINE packed_cell_t *
 packed_cell_copy(const cell_t *cell)
 {
-  packed_cell_t *c = tor_malloc(sizeof(packed_cell_t));
+  packed_cell_t *c = packed_cell_alloc();
   cell_pack(c, cell);
   c->next = NULL;
   return c;