[tor-commits] [tor/master] Add `tor_compress_get_total_allocation()` function.

nickm at torproject.org nickm at torproject.org
Tue Apr 25 12:18:24 UTC 2017


commit 04682d302aeeb0c2a0d9859bc0c1feee38daf16a
Author: Alexander Færøy <ahf at torproject.org>
Date:   Thu Apr 20 15:33:13 2017 +0200

    Add `tor_compress_get_total_allocation()` function.
    
    This patch adds the `tor_compress_get_total_allocation()` which returns
    an approximate number of bytes currently in use by all the different
    compression backends.
    
    See: https://bugs.torproject.org/21662
---
 src/common/compress.c | 10 ++++++++++
 src/common/compress.h |  3 +++
 src/or/relay.c        |  4 ++--
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/common/compress.c b/src/common/compress.c
index dc86be7..52ff132 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -154,6 +154,16 @@ detect_compression_method(const char *in, size_t in_len)
   }
 }
 
+/** Return the approximate number of bytes allocated for all
+ * supported compression schemas. */
+size_t
+tor_compress_get_total_allocation(void)
+{
+  return tor_zlib_get_total_allocation() +
+         tor_lzma_get_total_allocation() +
+         tor_zstd_get_total_allocation();
+}
+
 /** Internal state for an incremental compression/decompression.  The body of
  * this struct is not exposed. */
 struct tor_compress_state_t {
diff --git a/src/common/compress.h b/src/common/compress.h
index 59e7a79..1fd4325 100644
--- a/src/common/compress.h
+++ b/src/common/compress.h
@@ -51,6 +51,9 @@ tor_compress_memory_level(compression_level_t level);
 int
 tor_compress_is_compression_bomb(size_t size_in, size_t size_out);
 
+size_t
+tor_compress_get_total_allocation(void);
+
 /** Return values from tor_compress_process; see that function's documentation
  * for details. */
 typedef enum {
diff --git a/src/or/relay.c b/src/or/relay.c
index 8a98c50..8524080 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -54,7 +54,7 @@
 #include "circuitbuild.h"
 #include "circuitlist.h"
 #include "circuituse.h"
-#include "compress_zlib.h"
+#include "compress.h"
 #include "config.h"
 #include "connection.h"
 #include "connection_edge.h"
@@ -2454,7 +2454,7 @@ cell_queues_check_size(void)
 {
   size_t alloc = cell_queues_get_total_allocation();
   alloc += buf_get_total_allocation();
-  alloc += tor_zlib_get_total_allocation();
+  alloc += tor_compress_get_total_allocation();
   const size_t rend_cache_total = rend_cache_get_total_allocation();
   alloc += rend_cache_total;
   if (alloc >= get_options()->MaxMemInQueues_low_threshold) {





More information about the tor-commits mailing list