aboutsummaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-05-22 16:27:29 -0400
committerNick Mathewson <nickm@torproject.org>2014-05-22 16:27:29 -0400
commit1a73e178011d24ad2ef252dab7256d7c4fa94a64 (patch)
tree35990ad7f447fcebe8422aed4b66047f9fec2d29 /src/or
parentfef65fa64341fb70df0e7b34d91d3b08a74e7aad (diff)
parent170e0df7417e78f7b689f3189e7a0b5b8dfd2722 (diff)
downloadtor-1a73e178011d24ad2ef252dab7256d7c4fa94a64.tar
tor-1a73e178011d24ad2ef252dab7256d7c4fa94a64.tar.gz
Merge remote-tracking branch 'andrea/bug11476'
Diffstat (limited to 'src/or')
-rw-r--r--src/or/circuitlist.c2
-rw-r--r--src/or/main.c6
-rw-r--r--src/or/relay.c31
-rw-r--r--src/or/relay.h2
4 files changed, 37 insertions, 4 deletions
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index e5ed9c04f..6238e08e1 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -1983,7 +1983,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 025b5192b..1168f43c9 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();
#ifndef _WIN32
diff --git a/src/or/relay.c b/src/or/relay.c
index f8b0deedb..5c430a6d7 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,30 @@ clean_cell_pool(void)
mp_pool_clean(cell_pool, 0, 1);
}
+#define relay_alloc_cell() \
+ mp_pool_get(cell_pool)
+#define relay_free_cell(cell) \
+ mp_pool_release(cell)
+
+#define RELAY_CELL_MEM_COST (sizeof(packed_cell_t) + MP_POOL_ITEM_OVERHEAD)
+
+#else /* !ENABLE_MEMPOOLS case */
+
+#define relay_alloc_cell() \
+ tor_malloc_zero(sizeof(packed_cell_t))
+#define relay_free_cell(cell) \
+ tor_free(cell)
+
+#define RELAY_CELL_MEM_COST (sizeof(packed_cell_t))
+
+#endif /* ENABLE_MEMPOOLS */
+
/** Release storage held by <b>cell</b>. */
static INLINE void
packed_cell_free_unchecked(packed_cell_t *cell)
{
--total_cells_allocated;
- mp_pool_release(cell);
+ relay_free_cell(cell);
}
/** Allocate and return a new packed_cell_t. */
@@ -2278,7 +2299,7 @@ STATIC packed_cell_t *
packed_cell_new(void)
{
++total_cells_allocated;
- return mp_pool_get(cell_pool);
+ return relay_alloc_cell();
}
/** Return a packed cell used outside by channel_t lower layer */
@@ -2307,7 +2328,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 +2410,7 @@ cell_queue_pop(cell_queue_t *queue)
size_t
packed_cell_mem_cost(void)
{
- return sizeof(packed_cell_t) + MP_POOL_ITEM_OVERHEAD;
+ return RELAY_CELL_MEM_COST;
}
/** DOCDOC */
diff --git a/src/or/relay.h b/src/or/relay.h
index 9c0e21c14..479d474b3 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);