V(MaxClientCircuitsPending, POSINT, "32"),
V(MaxConsensusAgeForDiffs, INTERVAL, "0 seconds"),
VAR("MaxMemInQueues", MEMUNIT, MaxMemInQueues_raw, "0"),
+ VAR("MaxHSDirCacheBytes", MEMUNIT, MaxHSDirCacheBytes, "0"),
OBSOLETE("MaxOnionsPending"),
V(MaxOnionQueueDelay, MSEC_INTERVAL, "0"),
V(MaxUnparseableDescSizeToLog, MEMUNIT, "10 MB"),
server_mode(options));
options->MaxMemInQueues_low_threshold = (options->MaxMemInQueues / 4) * 3;
+ /* Process MaxHSDirCacheBytes. If not set (0), use MaxMemInQueues / 5 as default. */
+ if (options->MaxHSDirCacheBytes == 0) {
+ /* Default to MaxMemInQueues / 5 for HS directory cache (20%) */
+ options->MaxHSDirCacheBytes = options->MaxMemInQueues / 5;
+ }
+
if (!options->SafeLogging ||
!strcasecmp(options->SafeLogging, "0")) {
options->SafeLogging_ = SAFELOG_SCRUB_NONE;
/** Above this value, consider ourselves low on RAM. */
uint64_t MaxMemInQueues_low_threshold;
+ uint64_t MaxHSDirCacheBytes;/**< If we have more memory than this allocated
+ * for the hidden service directory cache,
+ * run the HS cache OOM handler */
+
/** @name port booleans
*
* Derived booleans: For server ports and ControlPort, true iff there is a
/* Note this overload down */
rep_hist_note_overload(OVERLOAD_GENERAL);
- /* If we're spending over 20% of the memory limit on hidden service
- * descriptors, free them until we're down to 10%. Do the same for geoip
- * client cache. */
- if (hs_cache_total > get_options()->MaxMemInQueues / 5) {
+ /* If we're spending over the configured limit on hidden service
+ * descriptors, free them until we're down to 50% of the limit. */
+ if (hs_cache_total > get_options()->MaxHSDirCacheBytes) {
const size_t bytes_to_remove =
- hs_cache_total - (size_t)(get_options()->MaxMemInQueues / 10);
+ hs_cache_total - (size_t)(get_options()->MaxHSDirCacheBytes / 2);
removed = hs_cache_handle_oom(bytes_to_remove);
oom_stats_n_bytes_removed_hsdir += removed;
alloc -= removed;