diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-11-17 11:43:50 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-11-17 11:43:50 -0500 |
commit | 734ba5cb0a0b6cc5376f8889305835224d814252 (patch) | |
tree | 78fa73f2248c8cea20426c5d70c5811d5765de58 /src/common/torgzip.h | |
parent | a68b90fc7af401220f11f4f9e39f08a8548a6957 (diff) | |
download | tor-734ba5cb0a0b6cc5376f8889305835224d814252.tar.gz tor-734ba5cb0a0b6cc5376f8889305835224d814252.zip |
Use smaller zlib objects when under memory pressure
We add a compression level argument to tor_zlib_new, and use it to
determine how much memory to allocate for the zlib object. We use the
existing level by default, but shift to smaller levels for small
requests when we have been over 3/4 of our memory usage in the past
half-hour.
Closes ticket 11791.
Diffstat (limited to 'src/common/torgzip.h')
-rw-r--r-- | src/common/torgzip.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/common/torgzip.h b/src/common/torgzip.h index 1378d55b76..eaba2712bb 100644 --- a/src/common/torgzip.h +++ b/src/common/torgzip.h @@ -19,6 +19,15 @@ typedef enum { NO_METHOD=0, GZIP_METHOD=1, ZLIB_METHOD=2, UNKNOWN_METHOD=3 } compress_method_t; +/** + * Enumeration to define tradeoffs between memory usage and compression level. + * HIGH_COMPRESSION saves the most bandwidth; LOW_COMPRESSION saves the most + * memory. + **/ +typedef enum { + HIGH_COMPRESSION, MEDIUM_COMPRESSION, LOW_COMPRESSION +} zlib_compression_level_t; + int tor_gzip_compress(char **out, size_t *out_len, const char *in, size_t in_len, @@ -47,7 +56,8 @@ typedef enum { } tor_zlib_output_t; /** Internal state for an incremental zlib compression/decompression. */ typedef struct tor_zlib_state_t tor_zlib_state_t; -tor_zlib_state_t *tor_zlib_new(int compress, compress_method_t method); +tor_zlib_state_t *tor_zlib_new(int compress, compress_method_t method, + zlib_compression_level_t level); tor_zlib_output_t tor_zlib_process(tor_zlib_state_t *state, char **out, size_t *out_len, |