]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a new hsdir max bytes config
authorMike Perry <mikeperry-git@torproject.org>
Tue, 3 Jun 2025 19:32:38 +0000 (19:32 +0000)
committerMike Perry <mikeperry-git@torproject.org>
Thu, 5 Jun 2025 01:09:04 +0000 (01:09 +0000)
src/app/config/config.c
src/app/config/or_options_st.h
src/core/or/relay.c

index a10329c5525cc35f6b0f26626c1d3dcf287319f7..e42bc3301e0145e5df93057969c6f3dd6a4f9880 100644 (file)
@@ -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;
index 36b00662b5af1e281973d4a4c631b8fd9c89e810..789f2f2a4c52dbdb9e5d3b9ccf0709d67ee09ec4 100644 (file)
@@ -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
index 005a597cf83fb307697950c045411a9c1c596ab0..a6c04f6be276e77bf634162c7bcfb8a66754916f 100644 (file)
@@ -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;