aboutsummaryrefslogtreecommitdiff
path: root/src/or/relay.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2018-02-02 10:15:28 -0500
committerDavid Goulet <dgoulet@torproject.org>2018-02-02 14:48:41 -0500
commit51839f47650463f59bd2cc84da05d5bc535d699d (patch)
tree0d75973ecb70a578e0c9db02fe1643e0afaabf61 /src/or/relay.c
parenta2aaf9509ba578f4e7705b506ee9a0f764d24ff2 (diff)
downloadtor-51839f47650463f59bd2cc84da05d5bc535d699d.tar.gz
tor-51839f47650463f59bd2cc84da05d5bc535d699d.zip
geoip: Hook the client history cache into the OOM handler
If the cache is using 20% of our maximum allowed memory, clean 10% of it. Same behavior as the HS descriptor cache. Closes #25122 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/relay.c')
-rw-r--r--src/or/relay.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/or/relay.c b/src/or/relay.c
index 29f34ca033..22ce767523 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -2469,24 +2469,34 @@ static time_t last_time_under_memory_pressure = 0;
STATIC int
cell_queues_check_size(void)
{
+ time_t now = time(NULL);
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;
+ const size_t geoip_client_cache_total =
+ geoip_client_cache_total_allocation();
+ alloc += geoip_client_cache_total;
if (alloc >= get_options()->MaxMemInQueues_low_threshold) {
last_time_under_memory_pressure = approx_time();
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%.
- */
+ * descriptors, free them until we're down to 10%. Do the same for geoip
+ * client cache. */
if (rend_cache_total > get_options()->MaxMemInQueues / 5) {
const size_t bytes_to_remove =
rend_cache_total - (size_t)(get_options()->MaxMemInQueues / 10);
- rend_cache_clean_v2_descs_as_dir(time(NULL), bytes_to_remove);
+ rend_cache_clean_v2_descs_as_dir(now, bytes_to_remove);
alloc -= rend_cache_total;
alloc += rend_cache_get_total_allocation();
}
+ if (geoip_client_cache_total > get_options()->MaxMemInQueues / 5) {
+ const size_t bytes_to_remove =
+ geoip_client_cache_total -
+ (size_t)(get_options()->MaxMemInQueues / 10);
+ alloc -= geoip_client_cache_handle_oom(now, bytes_to_remove);
+ }
circuits_handle_oom(alloc);
return 1;
}