tcp: Allocate t_tcpreq_info on demand

When TCP_REQUEST_TRK is enabled, the tcb grows by 600 bytes
to accommodate the t_tcpreq_info[MAX_TCP_TRK_REQ] array.
Even when the option is enabled, not every connection is using
this feature.  So let's allocate it on-demand, and save 600
bytes in the common case.

Sponsored by: Netflix
Reviewed by: rrs, tuexen
Differential Revision: https://reviews.freebsd.org/D56484
This commit is contained in:
Andrew Gallatin
2026-04-17 16:01:36 -04:00
parent 90383181aa
commit 29336f1c9d
2 changed files with 18 additions and 1 deletions
+17
View File
@@ -1133,6 +1133,9 @@ tcp_default_fb_fini(struct tcpcb *tp, int tcb_is_purged)
MALLOC_DEFINE(M_TCPLOG, "tcplog", "TCP address and flags print buffers");
MALLOC_DEFINE(M_TCPFUNCTIONS, "tcpfunc", "TCP function set memory");
#ifdef TCP_REQUEST_TRK
MALLOC_DEFINE(M_TCPREQTRK, "tcpreqtrk", "TCP request tracking");
#endif
static struct mtx isn_mtx;
@@ -2445,6 +2448,12 @@ tcp_discardcb(struct tcpcb *tp)
#ifdef STATS
stats_blob_destroy(tp->t_stats);
#endif
#ifdef TCP_REQUEST_TRK
if (tp->t_tcpreq_info != NULL) {
free(tp->t_tcpreq_info, M_TCPREQTRK);
tp->t_tcpreq_info = NULL;
}
#endif
CC_ALGO(tp) = NULL;
if ((m = STAILQ_FIRST(&tp->t_inqueue)) != NULL) {
@@ -4890,6 +4899,14 @@ tcp_req_alloc_req_full(struct tcpcb *tp, struct tcp_snd_req *req, uint64_t ts, i
struct tcp_sendfile_track *fil;
int i, allocated;
/* Allocate the request tracking array on demand */
if (tp->t_tcpreq_info == NULL) {
tp->t_tcpreq_info = malloc(
sizeof(*tp->t_tcpreq_info) * MAX_TCP_TRK_REQ,
M_TCPREQTRK, M_NOWAIT | M_ZERO);
if (tp->t_tcpreq_info == NULL)
return (NULL);
}
/* In case the stack does not check for completions do so now */
tcp_req_check_for_comp(tp, tp->snd_una);
/* Check for stale entries */
+1 -1
View File
@@ -493,7 +493,7 @@ struct tcpcb {
uint32_t tcp_hybrid_start; /* Num of times we started hybrid pacing */
uint32_t tcp_hybrid_stop; /* Num of times we stopped hybrid pacing */
uint32_t tcp_hybrid_error; /* Num of times we failed to start hybrid pacing */
struct tcp_sendfile_track t_tcpreq_info[MAX_TCP_TRK_REQ];
struct tcp_sendfile_track *t_tcpreq_info;
#endif
#ifdef TCP_ACCOUNTING
uint64_t tcp_cnt_counters[TCP_NUM_CNT_COUNTERS];