uint64_t in_usec, uint64_t our_usec);
/* Track the total number of bytes used by all ooo_q so it can be used by the
- * OOM handler to assess. */
+ * OOM handler to assess.
+ *
+ * When adding or subtracting to this value, use conflux_msg_alloc_cost(). */
static uint64_t total_ooo_q_bytes = 0;
/**
return 0;
}
+/**
+ * Return the total number of required allocated to store `msg`.
+ */
+static inline size_t
+conflux_msg_alloc_cost(conflux_msg_t *msg)
+{
+ return msg->msg->length + sizeof(conflux_msg_t) + sizeof(relay_msg_t);
+}
+
/**
* Process an incoming relay cell for conflux. Called from
* connection_edge_process_relay_cell().
smartlist_pqueue_add(cfx->ooo_q, conflux_queue_cmp,
offsetof(conflux_msg_t, heap_idx), c_msg);
- total_ooo_q_bytes += sizeof(msg->length);
+
+ total_ooo_q_bytes += conflux_msg_alloc_cost(c_msg);
/* This cell should not be processed yet, and the queue is not ready
* to process because the next absolute seqnum has not yet arrived */
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 -= sizeof(top->msg->length);
+ total_ooo_q_bytes -= conflux_msg_alloc_cost(top);
cfx->last_seq_delivered++;
return top;
} else {