]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Include message length in conflux_get_circ_bytes_allocation
authorNick Mathewson <nickm@torproject.org>
Thu, 8 May 2025 01:31:03 +0000 (21:31 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 12 May 2025 01:51:48 +0000 (21:51 -0400)
src/core/or/conflux.c
src/core/or/conflux_st.h

index 140d15e7b702314d621bdbb842a7cfac0caf8a7b..96e218806a403e0f292c30aa29484a38ca996428 100644 (file)
@@ -172,7 +172,8 @@ uint64_t
 conflux_get_circ_bytes_allocation(const circuit_t *circ)
 {
   if (circ->conflux) {
-    return smartlist_len(circ->conflux->ooo_q) * sizeof(conflux_msg_t);
+    return smartlist_len(circ->conflux->ooo_q) * sizeof(void*)
+      + circ->conflux->ooo_q_alloc_cost;
   }
   return 0;
 }
@@ -887,11 +888,13 @@ conflux_process_relay_msg(conflux_t *cfx, circuit_t *in_circ,
      * stack. This is simpler and less error prone but might show up in our
      * profile (maybe?). The Maze is serious. It needs to be respected. */
     c_msg->msg = relay_msg_copy(msg);
+    size_t cost = conflux_msg_alloc_cost(c_msg);
 
     smartlist_pqueue_add(cfx->ooo_q, conflux_queue_cmp,
                          offsetof(conflux_msg_t, heap_idx), c_msg);
 
-    total_ooo_q_bytes += conflux_msg_alloc_cost(c_msg);
+    total_ooo_q_bytes += cost;
+    cfx->ooo_q_alloc_cost += cost;
 
     /* This cell should not be processed yet, and the queue is not ready
      * to process because the next absolute seqnum has not yet arrived */
@@ -919,7 +922,11 @@ conflux_dequeue_relay_msg(conflux_t *cfx)
   if (top->seq == cfx->last_seq_delivered+1) {
     smartlist_pqueue_pop(cfx->ooo_q, conflux_queue_cmp,
                          offsetof(conflux_msg_t, heap_idx));
-    total_ooo_q_bytes -= conflux_msg_alloc_cost(top);
+
+    size_t cost = conflux_msg_alloc_cost(top);
+    total_ooo_q_bytes -= cost;
+    cfx->ooo_q_alloc_cost -= cost;
+
     cfx->last_seq_delivered++;
     return top;
   } else {
index 61e38f8268f422e1b8067851a265a90124e69e00..18961fb38815153403fcdab41b0c218cf2dd2a7b 100644 (file)
@@ -102,6 +102,12 @@ struct conflux_t {
    */
   smartlist_t *ooo_q;
 
+  /**
+   * Approximate allocation cost of the bytes stored in ooo_q
+   * and the messages that it contains.
+   */
+  size_t ooo_q_alloc_cost;
+
   /**
    * Absolute sequence number of cells delivered to streams since start.
    * (ie: this is updated *after* dequeue from the ooo_q priority queue). */