Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Kernel "TCP: out of memory -- consider tuning tcp_mem": measure TCP memory in pages before raising it

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

The kernel log line TCP: out of memory -- consider tuning tcp_mem means the memory used by all TCP sockets together went above the third value of net.ipv4.tcp_mem, and the kernel reset a connection that was being closed. It is not the process OOM killer, and it does not mean the server is out of RAM. Compare the TCP memory in use with tcp_mem, which is counted in pages, then find what holds the memory before you raise the limit.

What the error means

tcp_mem is a vector of three integers. The kernel documentation names them min, pressure and max, and the tcp(7) manual names them low, pressure and high. Both say the values are numbers of pages. In the kernel's words, pressure is "when amount of memory allocated by TCP exceeds this number of pages, TCP moderates its memory consumption", and max is the "number of pages allowed for queueing by all TCP sockets". The documentation adds that "Defaults are calculated at boot time from amount of available memory."

The page size is not 1 KB. On most x86-64 servers it is 4096 bytes, and getconf PAGESIZE prints it (the getconf manual says it queries variables defined by sysconf(3), which lists PAGESIZE). So a tcp_mem high value of 196608 pages is 196608 x 4096 = 805,306,368 bytes, which is 768 MiB.

Reading the kernel source (tcp_check_oom in net/ipv4/tcp.c, tag v6.12), the message is raised when the memory allocated to TCP is above the third tcp_mem limit and the socket's queued send memory is above a minimum. The same function prints TCP: too many orphaned sockets when the number of orphaned sockets is above tcp_max_orphans. Both are rate limited. The check runs when an application closes a socket that is not yet closed, and from the timer code (tcp_out_of_resources in net/ipv4/tcp_timer.c) for orphaned sockets. When the check is true in the close path, the kernel sets the socket to closed, sends a reset and counts it. In the timer path a reset is sent when the calling code asked for one, or when the last segment was sent recently, or when the window is closed with no packets outstanding; otherwise the socket is dropped without one (tcp_out_of_resources, tcp_timer.c, tag v6.12).

The counter is TcpExtTCPAbortOnMemory. The kernel's SNMP counter documentation explains that when an application closes a connection, the kernel still tracks it, and when "kernel has no enough memory to keep the orphan socket, kernel would send an RST to the other side, and delete the socket". It lists two conditions: TCP memory above the third value of tcp_mem, or the orphan count above net.ipv4.tcp_max_orphans.

Other kernel memory problems look different. A process killed for lack of memory is covered by Linux OOM Killer on a VM: Find the Cause, Set Memory Limits.

Likely causes

Cause What you see How to confirm
Many connections, each holding large buffers The message at busy times; TcpExtTCPAbortOnMemory rises /proc/net/sockstat TCP mem close to the third tcp_mem value; ss -tmn shows large skmem values
tcp_mem is small for the workload The message with modest connection counts The third value is small when multiplied by the page size (see arithmetic)
Slow or stuck peers leave data queued Send-Q growing on many connections ss -tn shows large Send-Q for many peers
An application does not read its sockets Large Recv-Q values ss -tn Recv-Q large on the same process
Orphaned sockets pile up The orphan count is high; the other message too many orphaned sockets may appear ss -s shows a high orphaned count; compare with tcp_max_orphans
Buffer maximums were raised Each connection can grow to a large buffer sysctl net.ipv4.tcp_rmem net.ipv4.tcp_wmem show large maximums

Prove the cause before changing anything

All of these only read.

1. Find the messages and the times.

journalctl -k -g 'TCP: out of memory'

The journalctl manual says -k shows only kernel messages and -g filters with a regular expression.

2. Read the limits and buffer settings.

sysctl net.ipv4.tcp_mem net.ipv4.tcp_rmem net.ipv4.tcp_wmem net.ipv4.tcp_max_orphans
getconf PAGESIZE

The three tcp_mem numbers are in pages. tcp_rmem and tcp_wmem are min, default and max per socket; the kernel documentation says tcp_rmem max is the maximal size of automatically selected receive buffers and gives tcp_wmem max a default "between 64K and 4MB, depending on RAM size".

3. Read the current TCP memory in pages.

grep '^TCP:' /proc/net/sockstat

The kernel's proc documentation names /proc/net/sockstat as the place for TCP memory allocations, and the kernel source (net/ipv4/proc.c) prints the line as TCP: inuse ... orphan ... tw ... alloc ... mem .... The mem value is the TCP memory allocation the kernel compares with tcp_mem. A good result is mem well below the second tcp_mem value. A bad result is mem at or above the third value during the incident.

4. Count the resets caused by memory.

nstat -az TcpExtTCPAbortOnMemory

The nstat manual says -a dumps absolute counter values and -z includes zero counters. A value that rises during busy periods ties the message to real resets.

5. See where socket memory sits.

ss -s
ss -tmn state established

The ss manual says -s prints summary statistics and -m shows socket memory in the form skmem:(r<rmem_alloc>,rb<rcv_buf>,t<wmem_alloc>,tb<snd_buf>,...). A few sockets with very large buffers point at an application or a peer; many ordinary ones point at the limit being too low for the connection count.

6. Do the arithmetic. Convert pages to bytes: pages x page size. Compare the incident mem figure with the third value. If mem was 196,000 pages against a limit of 196,608 pages, usage was 99.7% of the limit.

Fix

Reduce demand first

The usual changes are made in the application's own settings: making it read its sockets, closing idle connections it no longer needs, or lowering buffer sizes for a service that does not need large buffers. The kernel documentation says that setting a socket buffer size with SO_RCVBUF or SO_SNDBUF disables automatic tuning for that socket, so application settings affect memory use too.

Raise tcp_mem at run time

First print and keep the current value:

sysctl net.ipv4.tcp_mem > tcp_mem-before.2026-12-01.txt

Risk: the next command raises the ceiling on kernel memory that TCP sockets may use, effective at once. Set it too high and TCP buffers compete with applications for RAM, which can, in our reading, lead to the process OOM killer instead of this message.

Choose the new values from your measured peak: the third value should clear the peak mem with headroom, and keep the order low, pressure, high. Quote the value, as the sysctl manual says for values with spaces:

sysctl -w net.ipv4.tcp_mem="147456 196608 294912"

To undo it, read the three numbers in the saved file and set exactly those, using the values from tcp_mem-before.2026-12-01.txt in place of the three placeholders:

cat tcp_mem-before.2026-12-01.txt
sysctl -w net.ipv4.tcp_mem="<low> <pressure> <high>"
sysctl net.ipv4.tcp_mem

Keep the value after a reboot

First, only if you did not run the run-time step above, print and keep the current value. If you did run it, tcp_mem-before.2026-12-01.txt already holds the old value, and running this command again would overwrite it with the new one:

sysctl net.ipv4.tcp_mem > tcp_mem-before.2026-12-01.txt

Then list the folder so you do not overwrite a file:

ls -l /etc/sysctl.d/

Risk: the next file applies the new tcp_mem values at every boot and whenever sysctl --system runs. The sysctl --system command after it re-reads every system sysctl file, so any other value that was changed at run time and never saved in a file goes back to what the files say.

Create /etc/sysctl.d/90-tcp-mem.conf with an editor. The sysctl.conf manual gives the format token = value, and notes that systemd-sysctl does not use /etc/sysctl.conf, so a file in /etc/sysctl.d/ works with both:

net.ipv4.tcp_mem = 147456 196608 294912

Load it with sysctl --system, which the manual says loads settings from all system configuration files:

sysctl --system

To back out, remove only the file you created, then set the numbers from tcp_mem-before.2026-12-01.txt at run time as above, because removing the file does not change the running value:

ls -l /etc/sysctl.d/90-tcp-mem.conf
rm /etc/sysctl.d/90-tcp-mem.conf
sysctl -w net.ipv4.tcp_mem="<low> <pressure> <high>"

Example (illustrative): web01 has 8 GiB of RAM. sysctl net.ipv4.tcp_mem prints 98304 131072 196608, and getconf PAGESIZE prints 4096. The third value is 196,608 x 4,096 = 805,306,368 bytes = 768 MiB. At the evening peak grep '^TCP:' /proc/net/sockstat shows mem 196000 (about 765.6 MiB) and TcpExtTCPAbortOnMemory rises by a few hundred. ss -s shows no unusual orphan count, and ss -tmn shows many ordinary connections. The team raises the three values by 50 percent to 147456 196608 294912. The new third value is 294,912 x 4,096 = 1,207,959,552 bytes = 1,152 MiB, 384 MiB more than before, which they have confirmed the server can spare.

Confirm the fix

  1. sysctl net.ipv4.tcp_mem prints the values you set.
  2. nstat -az TcpExtTCPAbortOnMemory stops increasing over a full busy period.
  3. journalctl -k -g 'TCP: out of memory' shows no new lines after the change time.
  4. grep '^TCP:' /proc/net/sockstat shows mem below the new second value at peak.
  5. Free memory for applications is still adequate; use your normal memory check at peak.

What to watch afterwards

  • TCP mem at peak, as a share of the third value; a steady climb means the load is still growing.
  • The orphan count and tcp_max_orphans if the other message appears.
  • Application memory after raising the limit, because TCP can now use more.
  • Memory changes on virtual machines: the documentation says defaults are calculated at boot; our reading is that memory added later does not change them by itself.

Risks and limits

  • These commands have not been run or lab-tested.
  • The kernel documentation says defaults come from available memory at boot; the formula in the kernel source (tcp_init_mem in net/ipv4/tcp.c) can change between releases and is not a rule for sizing.
  • The message text and its conditions are read from kernel source files; check your kernel version.
  • /proc/net/sockstat is described in the kernel documentation only as a source for TCP memory allocations; the unit of mem is read from the source, where it is the same allocation the kernel compares with tcp_mem.
  • Raising tcp_mem does not fix an application that never reads its sockets or a peer that never answers.

Sources

  • IP Sysctl — The Linux Kernel documentation, no page date shown, accessed 1 December 2026
  • SNMP counter — The Linux Kernel documentation, no page date shown, accessed 1 December 2026
  • The /proc Filesystem — The Linux Kernel documentation, no page date shown, accessed 1 December 2026
  • tcp(7) — man7.org copy (Linux man-pages 6.19, 2026-04-19), HTML rendering created 2026-09-09, accessed 1 December 2026
  • sysctl(8) — man7.org copy, HTML rendering created 2026-09-09, accessed 1 December 2026
  • sysctl.conf(5) — man7.org copy, HTML rendering created 2026-09-09, accessed 1 December 2026
  • sysctl.d(5) — man7.org copy, HTML rendering created 2026-09-09, accessed 1 December 2026
  • ss(8) — man7.org copy, HTML rendering created 2026-09-09, accessed 1 December 2026
  • nstat(8) — man7.org copy, HTML rendering created 2026-09-09, accessed 1 December 2026
  • sysconf(3) — man7.org copy (Linux man-pages 6.19, 2026-02-08), HTML rendering created 2026-09-09, accessed 1 December 2026
  • getconf(1) — Debian Manpages, bookworm (libc-bin 2.36), source updated 2025-03-06, accessed 1 December 2026
  • journalctl(1) — man7.org copy (systemd 262 development snapshot), HTML rendering created 2026-09-09, accessed 1 December 2026
  • net/ipv4/tcp.c (tag v6.12) — Linux kernel source at tag v6.12, no date shown, accessed 1 December 2026
  • net/ipv4/tcp_timer.c (tag v6.12) — Linux kernel source at tag v6.12, no date shown, accessed 1 December 2026
  • net/ipv4/proc.c (tag v6.12) — Linux kernel source at tag v6.12, no date shown, accessed 1 December 2026