Fundamentals 4 min read

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.

ITPUB
ITPUB
ITPUB
How Much Memory Does a TCP Connection Really Use? Seven-Day Experiment Reveals Surprising Results

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

TCPlinuxnetwork performancekernel optimizationsocket memory
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

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.