aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gallatin <gallatin@FreeBSD.org>2026-04-17 20:01:36 +0000
committerAndrew Gallatin <gallatin@FreeBSD.org>2026-04-18 19:04:05 +0000
commit29336f1c9d25c32896620a00a6218c332b37c4b7 (patch)
tree83eeda3b2c67d0f7db04427b9f3c822a938c880d
parent90383181aae908d2c696f8d66c19645011b4c388 (diff)
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
-rw-r--r--sys/netinet/tcp_subr.c17
-rw-r--r--sys/netinet/tcp_var.h2
2 files changed, 18 insertions, 1 deletions
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 4adc8d859f3e..9844ba176237 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -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 */
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index 987bb98c19af..a1b0519ceac3 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -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];