diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-02-06 10:36:59 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-02-06 11:05:07 -0500 |
commit | f98cb5d3552666ede73137d998162094d5a31a1a (patch) | |
tree | e261f61e9f0939366933f7a0ab0852acc8bd3772 /src/common | |
parent | 7cb954209d2c3b12d0d60a46a74f2c31ad6d48c5 (diff) | |
download | tor-f98cb5d3552666ede73137d998162094d5a31a1a.tar.gz tor-f98cb5d3552666ede73137d998162094d5a31a1a.zip |
Use "static-only" zstd functions to estimate memory usage.
These should provide better and more accurate results when we can
use them; we fall back to the old approach when we can't.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compress_zstd.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c index 7994487446..02469ced9e 100644 --- a/src/common/compress_zstd.c +++ b/src/common/compress_zstd.c @@ -139,9 +139,11 @@ struct tor_zstd_compress_state_t { #ifdef HAVE_ZSTD /** Return an approximate number of bytes stored in memory to hold the - * Zstandard compression/decompression state. */ + * Zstandard compression/decompression state. This is a fake estimate + * based on inspecting the zstd source: tor_zstd_state_size_precalc() is + * more accurate when it's allowed to use "static-only" functions */ static size_t -tor_zstd_state_size_precalc(int compress, int preset) +tor_zstd_state_size_precalc_fake(int compress, int preset) { tor_assert(preset > 0); @@ -198,6 +200,24 @@ tor_zstd_state_size_precalc(int compress, int preset) return memory_usage; } + +/** Return an approximate number of bytes stored in memory to hold the + * Zstandard compression/decompression state. */ +static size_t +tor_zstd_state_size_precalc(int compress, int preset) +{ +#ifdef ZSTD_STATIC_LINKING_ONLY + if (tor_zstd_can_use_static_apis()) { + if (compress) { + return ZSTD_estimateCStreamSize(preset); + } else { + /* Could use DStream, but that takes a windowSize. */ + return ZSTD_estimateDCtxSize(); + } + } +#endif + return tor_zstd_state_size_precalc_fake(compress, preset); +} #endif /* defined(HAVE_ZSTD) */ /** Construct and return a tor_zstd_compress_state_t object using |