Fundamentals 3 min read

Experimental Analysis of TCP Connection Memory Consumption in the Linux Kernel

The article presents a seven‑day series of experiments measuring how much memory a TCP connection occupies in various states—including ESTABLISH, data transfer, and TIME_WAIT—revealing kernel optimizations for socket buffer reclamation and overall memory overhead.

Refining Core Development Skills
Refining Core Development Skills
Refining Core Development Skills
Experimental Analysis of TCP Connection Memory Consumption in the Linux Kernel

The author conducts a seven‑day experimental study to quantify the memory footprint of TCP connections in the Linux kernel, addressing real‑world complexities such as data transmission and states like TIME_WAIT.

Experiment 1 – ESTABLISH idle connection: Measurements of a newly established socket without data exchange are shown, illustrating baseline memory usage.

Experiment 2 – Client‑to‑Server data transfer: The client sends data to the server, and the resulting memory consumption is recorded, highlighting the impact of active transmission on socket buffers.

Experiment 3 – Server‑to‑Client data transfer: Data flow in the opposite direction is tested, providing a comparative view of memory usage when the server transmits.

Experiment 4 – Non‑ESTABLISH states (e.g., TIME_WAIT): The study examines memory behavior in closed or waiting states, showing how the kernel reclaims resources such as socket_alloc objects.

The summary of findings indicates that the kernel aggressively recycles send and receive buffers, that the minimal buffer size is often smaller than the configured rmem minimum, and that additional states like TIME_WAIT trigger further cleanup.

For further reading, the author links to related articles on Linux network packet reception, monitoring and tuning, TCP connection latency, and visual explanations of TCP connection capacity.

Kernel promptly recycles send/receive buffers, especially in newer versions.

Actual minimal buffer size can be smaller than the rmem kernel parameter.

In states such as TIME_WAIT, unnecessary objects like socket_alloc are also reclaimed.

TCPlinuxNetwork PerformanceKernel Optimizationsocket memory
Refining Core Development Skills
Written by

Refining Core Development Skills

Fei has over 10 years of development experience at Tencent and Sogou. Through this account, he shares his deep insights on performance.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.