How Much Memory Does a TCP Connection Really Use? Seven-Day Experiment Reveals Surprising Results
A seven‑day series of experiments measures the memory footprint of TCP sockets in various states—including ESTABLISH, data transfer, and TIME_WAIT—showing how the Linux kernel optimizes socket memory usage and what factors influence the actual consumption.
Experiment 1: ESTABLISH (Idle) Connections
The author created a large number of TCP sockets that remain in the ESTABLISH state without transmitting data, then recorded the kernel memory consumption. The results are shown in the following screenshots.
Experiment 2: Client → Server Data Transfer
In this test the client continuously sends data to the server while the kernel memory usage is monitored. Screenshots capture the memory growth and reclamation patterns.
Experiment 3: Server → Client Data Transfer
This scenario mirrors Experiment 2 but with the server sending data to the client. The captured images illustrate how the kernel allocates and frees buffers on the sending side.
Experiment 4: Non‑ESTABLISH States (e.g., TIME_WAIT)
The final set of tests examines sockets in states other than ESTABLISH, such as TIME_WAIT, to see how the kernel reclaims memory for these objects.
Summary of Findings
The collected data reveal several kernel‑level optimizations for socket memory usage:
The kernel promptly reclaims send and receive buffers; newer kernel versions perform this reclamation more aggressively.
The actual minimum size of send/receive buffers can be smaller than the configured rmem_min parameter.
In states such as TIME_WAIT, the kernel also frees auxiliary objects like socket_alloc that are no longer needed.
These mechanisms together reduce the per‑connection memory overhead, especially under high‑concurrency workloads.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
