$RodHat_/search
Console Tips

FreeBSD netstat -m and vmstat -z: find the kernel limit you hit

Published by

This article may contain Amazon affiliate links. I may earn a commission if you buy through them. Disclosure.

Terminal showing netstat -m output with the requests for mbufs denied lines
AI illustration: RodHat
On this page · 4 sections
  1. netstat -m: the mbuf scoreboard
  2. vmstat -z: every UMA zone, with its failure count
  3. vmstat -m is the other allocator
  4. The workflow I actually use

The box is up. CPU is bored. Memory is mostly free. New connections stall, some sends fail with ENOBUFS, and the usual suspects (the switch, the firewall, the application) all swear they are innocent. Before you blame the network, ask the kernel whether it ran out of something. It keeps score, and nobody reads the scoreboard.

netstat -m: the mbuf scoreboard

netstat -m

Network buffers on FreeBSD are mbufs, with clusters hanging off them for larger payloads. The output has lines in the shape current/cache/total/max. The max is the ceiling. The lines that matter most are further down:

requests for mbufs denied (mbufs/clusters/mbuf+clusters)
requests for mbufs delayed (mbufs/clusters/mbuf+clusters)

Anything nonzero in the denied line means the allocator said no to a networking request. That is not a theory. That is a counter that went up. Delayed means a request had to wait, which is the milder version of the same disease. Counters are since boot, so run it twice a minute apart and compare, or you will chase an incident from March.

If the cluster line shows total sitting at max, you found the wall. The knob is kern.ipc.nmbclusters:

sysctl kern.ipc.nmbclusters

Whether it can be raised at runtime or only from /boot/loader.conf has changed across releases, so read tuning(7) for yours instead of trusting me or a forum post from 2012. How loader tunables and sysctls fit together is in the sysctl and loader.conf post. And do not just set it to a huge number. Every cluster is wired kernel memory. Size it from the observed peak plus headroom, then re-measure.

vmstat -z: every UMA zone, with its failure count

mbufs are one consumer of the kernel’s UMA zone allocator. The rest are visible too:

vmstat -z

Columns are ITEM SIZE LIMIT USED FREE REQ FAIL SLEEP and, on newer releases, one or two more. Check vmstat(8) for your version. Read them like this:

  • LIMIT is the zone cap. Zero generally means no explicit limit.
  • USED against LIMIT tells you how close you are.
  • FAIL is allocations that returned failure. This is the column to sort on.
  • SLEEP is allocations that had to block waiting for memory.

Eyeball the header once, then filter on the FAIL column with awk for your own release’s layout, since I will not promise column positions from memory. The zone names are the useful part: mbuf_cluster, socket, tcpcb, tcp_inpcb and friends tell you which resource ran dry. A FAIL on socket or tcpcb is a different conversation than one on mbuf_cluster, and the corresponding limits are kern.maxfiles, kern.ipc.maxsockets, and the TCP control block tunables.

vmstat -m is the other allocator

vmstat -m covers malloc(9) types, separate from the UMA zones. Different allocator, different list, same kind of question: who is holding the memory and is it growing. If one type climbs forever across a day, you have a leak or a missing cleanup, and netstat -m will never show it to you.

The workflow I actually use

  1. netstat -m, twice, a minute apart. Did a denied or delayed counter move?
  2. If yes, is total pinned at max? Raise the limit with a number derived from the peak, not from optimism.
  3. If no, vmstat -z, sort by FAIL, read the zone names.
  4. Only then go look at the wire. If you need to, procstat on the wedged process shows which kernel path it is parked in.

The ephemeral-port version of this exhaustion story is on Linux, in the ephemeral port post, and the answer there is the same: the failure looked like the network, and the cause was a counter hitting a number somebody picked years ago. More in the FreeBSD and OpenBSD hub.

I used to think reading kernel allocator stats was something you did only after a panic. Turns out it is two commands and a minute. Mildly annoying to admit, given how many hours I spent in packet captures.