summaryrefslogtreecommitdiff
path: root/src/or/relay.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-11-17 11:43:50 -0500
committerNick Mathewson <nickm@torproject.org>2014-11-17 11:43:50 -0500
commit734ba5cb0a0b6cc5376f8889305835224d814252 (patch)
tree78fa73f2248c8cea20426c5d70c5811d5765de58 /src/or/relay.c
parenta68b90fc7af401220f11f4f9e39f08a8548a6957 (diff)
downloadtor-734ba5cb0a0b6cc5376f8889305835224d814252.tar.gz
tor-734ba5cb0a0b6cc5376f8889305835224d814252.zip
Use smaller zlib objects when under memory pressure
We add a compression level argument to tor_zlib_new, and use it to determine how much memory to allocate for the zlib object. We use the existing level by default, but shift to smaller levels for small requests when we have been over 3/4 of our memory usage in the past half-hour. Closes ticket 11791.
Diffstat (limited to 'src/or/relay.c')
-rw-r--r--src/or/relay.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/or/relay.c b/src/or/relay.c
index 05c7b3c955..a899fc09cb 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -2432,6 +2432,12 @@ cell_queues_get_total_allocation(void)
return total_cells_allocated * packed_cell_mem_cost();
}
+/** How long after we've been low on memory should we try to conserve it? */
+#define MEMORY_PRESSURE_INTERVAL (30*60)
+
+/** The time at which we were last low on memory. */
+static time_t last_time_under_memory_pressure = 0;
+
/** Check whether we've got too much space used for cells. If so,
* call the OOM handler and return 1. Otherwise, return 0. */
STATIC int
@@ -2440,13 +2446,25 @@ cell_queues_check_size(void)
size_t alloc = cell_queues_get_total_allocation();
alloc += buf_get_total_allocation();
alloc += tor_zlib_get_total_allocation();
- if (alloc >= get_options()->MaxMemInQueues) {
- circuits_handle_oom(alloc);
- return 1;
+ if (alloc >= get_options()->MaxMemInQueues_low_threshold) {
+ last_time_under_memory_pressure = approx_time();
+ if (alloc >= get_options()->MaxMemInQueues) {
+ circuits_handle_oom(alloc);
+ return 1;
+ }
}
return 0;
}
+/** Return true if we've been under memory pressure in the last
+ * MEMORY_PRESSURE_INTERVAL seconds. */
+int
+have_been_under_memory_pressure(void)
+{
+ return last_time_under_memory_pressure + MEMORY_PRESSURE_INTERVAL
+ < approx_time();
+}
+
/**
* Update the number of cells available on the circuit's n_chan or p_chan's
* circuit mux.