diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-01-06 13:52:54 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-01-06 13:52:54 -0500 |
commit | cf2ac8e2556849fdcace74adf36da876f86af30a (patch) | |
tree | 84a0f7f21309374f148760d0c416c5ae49803575 /src/or/relay.c | |
parent | 6f7a8f84d906a0a9d5fd88e49d352bb748a36b09 (diff) | |
parent | 734ba5cb0a0b6cc5376f8889305835224d814252 (diff) | |
download | tor-cf2ac8e2556849fdcace74adf36da876f86af30a.tar.gz tor-cf2ac8e2556849fdcace74adf36da876f86af30a.zip |
Merge remote-tracking branch 'public/feature11791'
Diffstat (limited to 'src/or/relay.c')
-rw-r--r-- | src/or/relay.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/or/relay.c b/src/or/relay.c index 4915fbcd98..2d11096309 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -2433,6 +2433,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 @@ -2441,13 +2447,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. |