commit 92d6aa44d0929b4ba97793d66bede30f8adab7e6
parent 6a35cdeedd4afe42f8860d372c855a0af0e9f235
Author: Mike Perry <mikeperry-git@torproject.org>
Date: Tue, 3 Jun 2025 19:32:38 +0000
Add a new hsdir max bytes config
Diffstat:
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git 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
@@ -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
@@ -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;