summaryrefslogtreecommitdiff
path: root/src/or/relay.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-01-04 20:05:29 -0500
committerNick Mathewson <nickm@torproject.org>2015-01-12 13:47:52 -0500
commit3033ba9f5ec8eb4dea3e6778f6d7546cacf7ae57 (patch)
treed8ba8ccd5dee101c4da4308c2d76dbea954d50a8 /src/or/relay.c
parenteda5cebd6c334c3e6fa82c6623f33592a8f77e60 (diff)
downloadtor-3033ba9f5ec8eb4dea3e6778f6d7546cacf7ae57.tar.gz
tor-3033ba9f5ec8eb4dea3e6778f6d7546cacf7ae57.zip
When OOM, free cached hidden service descriptors too.
Diffstat (limited to 'src/or/relay.c')
-rw-r--r--src/or/relay.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/or/relay.c b/src/or/relay.c
index b95e5841e7..50070b7d90 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -2441,7 +2441,19 @@ cell_queues_check_size(void)
size_t alloc = cell_queues_get_total_allocation();
alloc += buf_get_total_allocation();
alloc += tor_zlib_get_total_allocation();
+ const size_t rend_cache_total = rend_cache_get_total_allocation();
+ alloc += rend_cache_total;
if (alloc >= get_options()->MaxMemInQueues) {
+ /* If we're spending over 20% of the memory limit on hidden service
+ * descriptors, free them until we're down to 10%.
+ */
+ if (rend_cache_total > get_options()->MaxMemInQueues / 5) {
+ const size_t bytes_to_remove =
+ rend_cache_total - (get_options()->MaxMemInQueues / 10);
+ rend_cache_clean_v2_descs_as_dir(time(NULL), bytes_to_remove);
+ alloc -= rend_cache_total;
+ alloc += rend_cache_get_total_allocation();
+ }
circuits_handle_oom(alloc);
return 1;
}