From: Nick Mathewson Date: Wed, 12 Feb 2014 17:44:58 +0000 (-0500) Subject: Merge remote-tracking branch 'public/bug10169_024' into bug10169_025_v2 X-Git-Tag: tor-0.2.5.3-alpha~38^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=87fb1e324c1b3214765c46bec3d9ec6adc3fa83d;p=thirdparty%2Ftor.git Merge remote-tracking branch 'public/bug10169_024' into bug10169_025_v2 Conflicts: src/or/circuitlist.c --- 87fb1e324c1b3214765c46bec3d9ec6adc3fa83d diff --cc src/or/circuitlist.c index 9474896367,3081035abb..eb652301ed --- a/src/or/circuitlist.c +++ b/src/or/circuitlist.c @@@ -1612,8 -1513,40 +1612,40 @@@ marked_circuit_free_cells(circuit_t *ci cell_queue_clear(& TO_OR_CIRCUIT(circ)->p_chan_cells); } + /** Aggressively free buffer contents on all the buffers of all streams in the + * list starting at stream. Return the number of bytes recovered. */ + static size_t + marked_circuit_streams_free_bytes(edge_connection_t *stream) + { + size_t result = 0; + for ( ; stream; stream = stream->next_stream) { + connection_t *conn = TO_CONN(stream); + if (conn->inbuf) { + result += buf_allocation(conn->inbuf); + buf_clear(conn->inbuf); + } + if (conn->outbuf) { + result += buf_allocation(conn->outbuf); + buf_clear(conn->outbuf); + } + } + return result; + } + + /** Aggressively free buffer contents on all the buffers of all streams on + * circuit c. Return the number of bytes recovered. */ + static size_t + marked_circuit_free_stream_bytes(circuit_t *c) + { + if (CIRCUIT_IS_ORIGIN(c)) { + return marked_circuit_streams_free_bytes(TO_ORIGIN_CIRCUIT(c)->p_streams); + } else { + return marked_circuit_streams_free_bytes(TO_OR_CIRCUIT(c)->n_streams); + } + } + /** Return the number of cells used by the circuit c's cell queues. */ -static size_t +STATIC size_t n_cells_in_circ_queues(const circuit_t *c) { size_t n = c->n_chan_cells.n; @@@ -1700,17 -1691,17 +1792,17 @@@ circuits_handle_oom(size_t current_allo if (current_allocation <= mem_target) return; mem_to_recover = current_allocation - mem_target; - n_cells_to_remove = CEIL_DIV(mem_to_recover, packed_cell_mem_cost()); } + tor_gettimeofday_cached(&now); + now_ms = (uint32_t)tv_to_msec(&now); + /* This algorithm itself assumes that you've got enough memory slack * to actually run it. */ - TOR_LIST_FOREACH(circ, &global_circuitlist, head) - for (circ = global_circuitlist; circ; circ = circ->next) { ++ TOR_LIST_FOREACH(circ, &global_circuitlist, head) { + circ->age_tmp = circuit_max_queued_item_age(circ, now_ms); smartlist_add(circlist, circ); - - /* Set circcomp_now_tmp so that the sort can work. */ - tor_gettimeofday_cached(&now); - circcomp_now_tmp = (uint32_t)tv_to_msec(&now); + } /* This is O(n log n); there are faster algorithms we could use instead. * Let's hope this doesn't happen enough to be in the critical path. */