From: Mike Perry Date: Tue, 3 Jun 2025 19:32:38 +0000 (+0000) Subject: Add a new hsdir max bytes config X-Git-Tag: tor-0.4.8.18~6^2^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=92d6aa44d0929b4ba97793d66bede30f8adab7e6;p=thirdparty%2Ftor.git Add a new hsdir max bytes config --- diff --git a/src/app/config/config.c b/src/app/config/config.c index a10329c552..e42bc3301e 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -558,6 +558,7 @@ static const config_var_t option_vars_[] = { 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"), @@ -3535,6 +3536,12 @@ options_validate_cb(const void *old_options_, void *options_, char **msg) 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; diff --git a/src/app/config/or_options_st.h b/src/app/config/or_options_st.h index 36b00662b5..789f2f2a4c 100644 --- a/src/app/config/or_options_st.h +++ b/src/app/config/or_options_st.h @@ -203,6 +203,10 @@ struct or_options_t { /** 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 diff --git a/src/core/or/relay.c b/src/core/or/relay.c index 005a597cf8..a6c04f6be2 100644 --- a/src/core/or/relay.c +++ b/src/core/or/relay.c @@ -2935,12 +2935,11 @@ cell_queues_check_size(void) /* 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;